feat(test): implementazione infrastruttura completa (Unit, Integration, E2E) con Vitest e Playwright
- Introduce Vitest per Unit e Integration Test. - Introduce Playwright per End-to-End Test. - Aggiuge documentazione dettagliata in tests/README.md. - Aggiorna .gitignore per escludere i report di coverage
This commit is contained in:
91
tests/unit/gameState.test.js
Normal file
91
tests/unit/gameState.test.js
Normal file
@@ -0,0 +1,91 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { createInitialState, applyAction, checkVittoria } from '../../src/gameState.js'
|
||||
|
||||
describe('Game Logic (gameState.js)', () => {
|
||||
let state
|
||||
|
||||
beforeEach(() => {
|
||||
state = createInitialState()
|
||||
})
|
||||
|
||||
describe('Initial State', () => {
|
||||
it('dovrebbe iniziare con 0-0', () => {
|
||||
expect(state.sp.punt.home).toBe(0)
|
||||
expect(state.sp.punt.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe avere i set a 0', () => {
|
||||
expect(state.sp.set.home).toBe(0)
|
||||
expect(state.sp.set.guest).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Punteggio', () => {
|
||||
it('dovrebbe incrementare i punti (Home)', () => {
|
||||
const newState = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(newState.sp.punt.home).toBe(1)
|
||||
expect(newState.sp.punt.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe gestire il cambio palla', () => {
|
||||
// Home batte
|
||||
state.sp.servHome = true
|
||||
// Punto Guest -> Cambio palla
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
expect(s1.sp.servHome).toBe(false) // Ora batte Guest
|
||||
|
||||
// Punto Home -> Cambio palla
|
||||
const s2 = applyAction(s1, { type: 'incPunt', team: 'home' })
|
||||
expect(s2.sp.servHome).toBe(true) // Torna a battere Home
|
||||
})
|
||||
|
||||
it('dovrebbe gestire la rotazione formazione al cambio palla', () => {
|
||||
state.sp.servHome = true // Batte Home
|
||||
state.sp.form.guest = ["1", "2", "3", "4", "5", "6"]
|
||||
|
||||
// Punto Guest -> Cambio palla e rotazione Guest
|
||||
const newState = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
|
||||
// Verifica che la formazione sia ruotata (il primo elemento diventa ultimo)
|
||||
expect(newState.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
|
||||
})
|
||||
})
|
||||
|
||||
describe('Vittoria Set', () => {
|
||||
it('non dovrebbe dare vittoria a 24-24', () => {
|
||||
state.sp.punt.home = 24
|
||||
state.sp.punt.guest = 24
|
||||
expect(checkVittoria(state)).toBe(false)
|
||||
})
|
||||
|
||||
it('dovrebbe dare vittoria a 25-23', () => {
|
||||
state.sp.punt.home = 25
|
||||
state.sp.punt.guest = 23
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('dovrebbe richiedere 2 punti di scarto (26-24)', () => {
|
||||
state.sp.punt.home = 25
|
||||
state.sp.punt.guest = 24
|
||||
expect(checkVittoria(state)).toBe(false)
|
||||
|
||||
state.sp.punt.home = 26
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Reset', () => {
|
||||
it('dovrebbe resettare tutto a zero', () => {
|
||||
state.sp.punt.home = 10
|
||||
state.sp.set.home = 1
|
||||
|
||||
const newState = applyAction(state, { type: 'resetta' })
|
||||
|
||||
expect(newState.sp.punt.home).toBe(0)
|
||||
expect(newState.sp.set.home).toBe(0) // Nota: il reset attuale resetta solo i punti o tutto?
|
||||
// Controllo il codice: "s.sp.punt.home = 0... s.sp.storicoServizio = []"
|
||||
// Attenzione: nel codice originale `resetta` NON sembra resettare i set!
|
||||
// Verifichiamo il comportamento attuale del codice.
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user