test: ripara la suite Vitest e migra gli e2e all'architettura attuale

La suite era allineata a una vecchia forma dello stato (sp.punt/sp.set/
sp.servHome) e a una vecchia architettura e2e (controller su :3001).
Baseline iniziale: 77/170 test Vitest falliti.

Vitest (ora 212/212 verdi):
- gameState.test.js: riscritto con helper che derivano punteggio/set/
  servizio dalla striscia; aggiunto blocco formInizio
- server-utils.js: getNetworkIPs accetta interfacce iniettabili e
  printServerInfo accetta gli IP iniettabili (deterministico anche su WSL);
  filtro LAN unificato (esclude 127./169.254./172.)
- websocket + stress: punteggio letto via punteggio(striscia)
- ControllerPage/DisplayPage: forzato layout mobile (viewport portrait),
  punteggi impostati via striscia; aggiunto test bottone REFERTO
- nuovi: referto.test.js, persist.test.js (mock fs), wsMixin.test.js,
  integration/server.test.js (routing)

Refactor di supporto:
- referto.js: estratta buildRefertoHtml(state, now) pura; generaReferto
  resta wrapper con window.open/print
- server.js: estratti createApp()/startServer(); avvio solo se entrypoint

e2e (migrazione parziale, NON ancora verificata verde):
- tutti i riferimenti controller :3001 -> :3000/controller
- forzato viewport portrait sul controller prima del goto
- reset helper: chiude il dialog di configurazione che doReset apre
- game-simulation: gestione del dialog SET VINTO automatico a 25
This commit is contained in:
2026-06-21 00:36:02 +02:00
parent ddf68010a4
commit eb37f8319f
19 changed files with 931 additions and 302 deletions
+208 -145
View File
@@ -1,5 +1,39 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { createInitialState, applyAction, checkVittoria, checkVittoriaPartita } from '../../src/gameState.js'
import {
createInitialState, applyAction, checkVittoria, checkVittoriaPartita,
punteggio, setVinti, servizio,
} from '../../src/gameState.js'
// =============================================
// HELPER
// Lo stato non memorizza più punteggio/set/servizio direttamente:
// si ricavano dalla striscia tramite le funzioni pure esportate.
// =============================================
// Punteggio del set in corso
const puntDi = (s) => punteggio(s.sp.striscia)
// Set vinti nel match
const setDi = (s) => setVinti(s.sp.striscia)
// true se serve Home
const servDi = (s) => servizio(s.sp.striscia)
// Imposta chi serve a inizio set (set in corso a 0-0)
function setServizioIniziale(state, team) {
state.sp.striscia.at(-1).serv = team === 'home' ? 'h' : 'g'
}
// Imposta il punteggio del set in corso costruendo una ris coerente
function setPunteggio(state, home, guest) {
state.sp.striscia.at(-1).ris = 'h'.repeat(home) + 'g'.repeat(guest)
}
// Aggiunge set già conclusi (vinti) PRIMA del set in corso
function setSetVinti(state, home, guest) {
const conclusi = []
for (let i = 0; i < home; i++) conclusi.push({ serv: 'h', ris: '', vinc: 'h' })
for (let i = 0; i < guest; i++) conclusi.push({ serv: 'g', ris: '', vinc: 'g' })
state.sp.striscia = [...conclusi, state.sp.striscia.at(-1)]
}
describe('Game Logic (gameState.js)', () => {
let state
@@ -13,17 +47,17 @@ describe('Game Logic (gameState.js)', () => {
// =============================================
describe('Stato iniziale', () => {
it('dovrebbe iniziare con 0-0', () => {
expect(state.sp.punt.home).toBe(0)
expect(state.sp.punt.guest).toBe(0)
expect(puntDi(state).home).toBe(0)
expect(puntDi(state).guest).toBe(0)
})
it('dovrebbe avere i set a 0', () => {
expect(state.sp.set.home).toBe(0)
expect(state.sp.set.guest).toBe(0)
expect(setDi(state).home).toBe(0)
expect(setDi(state).guest).toBe(0)
})
it('dovrebbe avere servizio Home', () => {
expect(state.sp.servHome).toBe(true)
expect(servDi(state)).toBe(true)
})
it('dovrebbe avere formazione di default [1-6]', () => {
@@ -69,43 +103,43 @@ describe('Game Logic (gameState.js)', () => {
describe('incPunt', () => {
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)
expect(puntDi(newState).home).toBe(1)
expect(puntDi(newState).guest).toBe(0)
})
it('dovrebbe incrementare i punti Guest', () => {
const newState = applyAction(state, { type: 'incPunt', team: 'guest' })
expect(newState.sp.punt.guest).toBe(1)
expect(newState.sp.punt.home).toBe(0)
expect(puntDi(newState).guest).toBe(1)
expect(puntDi(newState).home).toBe(0)
})
it('dovrebbe gestire il cambio palla (Guest segna, batteva Home)', () => {
state.sp.servHome = true
setServizioIniziale(state, 'home')
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
expect(s1.sp.servHome).toBe(false)
expect(servDi(s1)).toBe(false)
})
it('dovrebbe gestire il cambio palla (Home segna, batteva Guest)', () => {
state.sp.servHome = false
setServizioIniziale(state, 'guest')
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
expect(s1.sp.servHome).toBe(true)
expect(servDi(s1)).toBe(true)
})
it('non dovrebbe cambiare palla se segna chi batte', () => {
state.sp.servHome = true
setServizioIniziale(state, 'home')
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
expect(s1.sp.servHome).toBe(true)
expect(servDi(s1)).toBe(true)
})
it('dovrebbe ruotare la formazione al cambio palla', () => {
state.sp.servHome = true
setServizioIniziale(state, 'home')
state.sp.form.guest = ["1", "2", "3", "4", "5", "6"]
const newState = applyAction(state, { type: 'incPunt', team: 'guest' })
expect(newState.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
})
it('non dovrebbe ruotare la formazione se non c\'è cambio palla', () => {
state.sp.servHome = true
setServizioIniziale(state, 'home')
state.sp.form.home = ["1", "2", "3", "4", "5", "6"]
const newState = applyAction(state, { type: 'incPunt', team: 'home' })
expect(newState.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
@@ -129,10 +163,9 @@ describe('Game Logic (gameState.js)', () => {
})
it('non dovrebbe incrementare i punti dopo vittoria', () => {
state.sp.punt.home = 25
state.sp.punt.guest = 23
setPunteggio(state, 25, 23)
const s = applyAction(state, { type: 'incPunt', team: 'home' })
expect(s.sp.punt.home).toBe(25)
expect(puntDi(s).home).toBe(25)
})
})
@@ -143,33 +176,33 @@ describe('Game Logic (gameState.js)', () => {
it('dovrebbe annullare l\'ultimo punto Home', () => {
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
const s2 = applyAction(s1, { type: 'decPunt' })
expect(s2.sp.punt.home).toBe(0)
expect(s2.sp.punt.guest).toBe(0)
expect(puntDi(s2).home).toBe(0)
expect(puntDi(s2).guest).toBe(0)
})
it('dovrebbe annullare l\'ultimo punto Guest', () => {
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
const s2 = applyAction(s1, { type: 'decPunt' })
expect(s2.sp.punt.home).toBe(0)
expect(s2.sp.punt.guest).toBe(0)
expect(puntDi(s2).home).toBe(0)
expect(puntDi(s2).guest).toBe(0)
})
it('non dovrebbe fare nulla sullo stato iniziale', () => {
const s = applyAction(state, { type: 'decPunt' })
expect(s.sp.punt.home).toBe(0)
expect(s.sp.punt.guest).toBe(0)
expect(puntDi(s).home).toBe(0)
expect(puntDi(s).guest).toBe(0)
})
it('dovrebbe ripristinare il servizio dopo undo con cambio palla', () => {
state.sp.servHome = true
setServizioIniziale(state, 'home')
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
expect(s1.sp.servHome).toBe(false)
expect(servDi(s1)).toBe(false)
const s2 = applyAction(s1, { type: 'decPunt' })
expect(s2.sp.servHome).toBe(true)
expect(servDi(s2)).toBe(true)
})
it('dovrebbe invertire la rotazione dopo undo con cambio palla', () => {
state.sp.servHome = true
setServizioIniziale(state, 'home')
state.sp.form.guest = ["1", "2", "3", "4", "5", "6"]
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
expect(s1.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
@@ -188,14 +221,66 @@ describe('Game Logic (gameState.js)', () => {
s = applyAction(s, { type: 'incPunt', team: 'home' })
s = applyAction(s, { type: 'incPunt', team: 'guest' })
s = applyAction(s, { type: 'incPunt', team: 'home' })
expect(s.sp.punt.home).toBe(2)
expect(s.sp.punt.guest).toBe(1)
expect(puntDi(s).home).toBe(2)
expect(puntDi(s).guest).toBe(1)
s = applyAction(s, { type: 'decPunt' })
expect(s.sp.punt.home).toBe(1)
expect(puntDi(s).home).toBe(1)
s = applyAction(s, { type: 'decPunt' })
expect(s.sp.punt.guest).toBe(0)
expect(puntDi(s).guest).toBe(0)
s = applyAction(s, { type: 'decPunt' })
expect(s.sp.punt.home).toBe(0)
expect(puntDi(s).home).toBe(0)
})
})
// =============================================
// FORMAZIONE DI PARTENZA (formInizio)
// =============================================
describe('formInizio', () => {
it('dovrebbe salvare la formazione corrente al primo punto del set', () => {
const s = applyAction(state, { type: 'incPunt', team: 'home' })
expect(s.sp.striscia.at(-1).formInizio).toEqual({
home: ["1", "2", "3", "4", "5", "6"],
guest: ["1", "2", "3", "4", "5", "6"],
})
})
it('formInizio è uno snapshot: la rotazione successiva non lo modifica', () => {
setServizioIniziale(state, 'home')
// 1° punto Home: nessun cambio palla, salva formInizio
let s = applyAction(state, { type: 'incPunt', team: 'home' })
// 2° punto Guest: cambio palla → ruota la formazione guest
s = applyAction(s, { type: 'incPunt', team: 'guest' })
expect(s.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
// lo snapshot resta quello iniziale
expect(s.sp.striscia.at(-1).formInizio.guest).toEqual(["1", "2", "3", "4", "5", "6"])
})
it('decPunt che riporta il set a 0-0 cancella formInizio', () => {
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
expect(s1.sp.striscia.at(-1).formInizio).toBeDefined()
const s2 = applyAction(s1, { type: 'decPunt' })
expect(s2.sp.striscia.at(-1).formInizio).toBeUndefined()
})
it('decPunt con punti ancora presenti NON cancella formInizio', () => {
let s = applyAction(state, { type: 'incPunt', team: 'home' })
s = applyAction(s, { type: 'incPunt', team: 'home' })
s = applyAction(s, { type: 'decPunt' })
expect(s.sp.striscia.at(-1).ris).toBe('h')
expect(s.sp.striscia.at(-1).formInizio).toBeDefined()
})
it('ogni set mantiene la propria formInizio', () => {
const custom = ['7', '8', '9', '10', '11', '12']
let s = applyAction(state, { type: 'setFormazione', team: 'home', form: custom })
// primo punto del set 1: salva formInizio custom
s = applyAction(s, { type: 'incPunt', team: 'home' })
// chiude il set 1 e ne apre uno nuovo (formazioni resettate a default)
s = applyAction(s, { type: 'nuovoSet', team: 'home' })
// primo punto del set 2: salva formInizio default
s = applyAction(s, { type: 'incPunt', team: 'home' })
expect(s.sp.striscia[0].formInizio.home).toEqual(custom)
expect(s.sp.striscia.at(-1).formInizio.home).toEqual(['1', '2', '3', '4', '5', '6'])
})
})
@@ -205,24 +290,27 @@ describe('Game Logic (gameState.js)', () => {
describe('incSet', () => {
it('dovrebbe incrementare il set Home', () => {
const s = applyAction(state, { type: 'incSet', team: 'home' })
expect(s.sp.set.home).toBe(1)
expect(setDi(s).home).toBe(1)
})
it('dovrebbe incrementare il set Guest', () => {
const s = applyAction(state, { type: 'incSet', team: 'guest' })
expect(s.sp.set.guest).toBe(1)
expect(setDi(s).guest).toBe(1)
})
it('dovrebbe fare wrap da 2 a 0', () => {
state.sp.set.home = 2
const s = applyAction(state, { type: 'incSet', team: 'home' })
expect(s.sp.set.home).toBe(0)
let s = applyAction(state, { type: 'incSet', team: 'home' })
s = applyAction(s, { type: 'incSet', team: 'home' })
expect(setDi(s).home).toBe(2)
s = applyAction(s, { type: 'incSet', team: 'home' })
expect(setDi(s).home).toBe(0)
})
it('dovrebbe incrementare da 1 a 2', () => {
state.sp.set.home = 1
const s = applyAction(state, { type: 'incSet', team: 'home' })
expect(s.sp.set.home).toBe(2)
let s = applyAction(state, { type: 'incSet', team: 'home' })
expect(setDi(s).home).toBe(1)
s = applyAction(s, { type: 'incSet', team: 'home' })
expect(setDi(s).home).toBe(2)
})
})
@@ -231,18 +319,16 @@ describe('Game Logic (gameState.js)', () => {
// =============================================
describe('nuovoSet', () => {
it('dovrebbe incrementare il set della squadra vincente', () => {
state.sp.punt.home = 25
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
expect(s.sp.set.home).toBe(1)
expect(s.sp.set.guest).toBe(0)
expect(setDi(s).home).toBe(1)
expect(setDi(s).guest).toBe(0)
})
it('dovrebbe azzerare i punti', () => {
state.sp.punt.home = 25
state.sp.punt.guest = 10
it('dovrebbe azzerare i punti nel nuovo set', () => {
setPunteggio(state, 25, 10)
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
expect(s.sp.punt.home).toBe(0)
expect(s.sp.punt.guest).toBe(0)
expect(puntDi(s).home).toBe(0)
expect(puntDi(s).guest).toBe(0)
})
it('dovrebbe aggiungere un nuovo set vuoto alla striscia', () => {
@@ -268,37 +354,35 @@ describe('Game Logic (gameState.js)', () => {
it('dovrebbe ignorare team non valido', () => {
const s = applyAction(state, { type: 'nuovoSet', team: 'invalid' })
expect(s.sp.set.home).toBe(0)
expect(s.sp.set.guest).toBe(0)
expect(setDi(s).home).toBe(0)
expect(setDi(s).guest).toBe(0)
})
it('in 2/3 dovrebbe registrare il set vincente senza resettare il punteggio', () => {
it('in 2/3 alla palla match registra il set vincente senza aprirne uno nuovo', () => {
state.modalitaPartita = '2/3'
state.sp.set.home = 1
state.sp.punt.home = 25
state.sp.punt.guest = 18
setSetVinti(state, 1, 0)
setPunteggio(state, 25, 18)
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
expect(s.sp.set.home).toBe(2)
expect(s.sp.punt.home).toBe(25)
expect(s.sp.punt.guest).toBe(18)
expect(setDi(s).home).toBe(2)
expect(puntDi(s).home).toBe(25)
expect(puntDi(s).guest).toBe(18)
})
it('in 3/5 dovrebbe registrare il set vincente senza resettare il punteggio', () => {
it('in 3/5 alla palla match registra il set vincente senza aprirne uno nuovo', () => {
state.modalitaPartita = '3/5'
state.sp.set.home = 2
state.sp.punt.home = 25
state.sp.punt.guest = 20
setSetVinti(state, 2, 0)
setPunteggio(state, 25, 20)
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
expect(s.sp.set.home).toBe(3)
expect(s.sp.punt.home).toBe(25)
expect(s.sp.punt.guest).toBe(20)
expect(setDi(s).home).toBe(3)
expect(puntDi(s).home).toBe(25)
expect(puntDi(s).guest).toBe(20)
})
it('dovrebbe ignorare nuovoSet se la partita è già finita', () => {
state.modalitaPartita = '2/3'
state.sp.set.home = 2
setSetVinti(state, 2, 0)
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
expect(s.sp.set.home).toBe(2)
expect(setDi(s).home).toBe(2)
})
})
@@ -308,29 +392,33 @@ describe('Game Logic (gameState.js)', () => {
describe('checkVittoriaPartita', () => {
it('in 2/3 restituisce false se nessuno ha 2 set', () => {
state.modalitaPartita = '2/3'
state.sp.set.home = 1
state.sp.set.guest = 0
setSetVinti(state, 1, 0)
expect(checkVittoriaPartita(state)).toBe(false)
})
it('in 2/3 restituisce true se home ha 2 set', () => {
state.modalitaPartita = '2/3'
state.sp.set.home = 2
setSetVinti(state, 2, 0)
expect(checkVittoriaPartita(state)).toBe(true)
})
it('in 3/5 restituisce false se nessuno ha 3 set', () => {
state.modalitaPartita = '3/5'
state.sp.set.home = 2
state.sp.set.guest = 2
setSetVinti(state, 2, 2)
expect(checkVittoriaPartita(state)).toBe(false)
})
it('in 3/5 restituisce true se guest ha 3 set', () => {
state.modalitaPartita = '3/5'
state.sp.set.guest = 3
setSetVinti(state, 0, 3)
expect(checkVittoriaPartita(state)).toBe(true)
})
it('in amichevole restituisce sempre false', () => {
state.modalitaPartita = 'amichevole'
setSetVinti(state, 5, 0)
expect(checkVittoriaPartita(state)).toBe(false)
})
})
// =============================================
@@ -338,27 +426,29 @@ describe('Game Logic (gameState.js)', () => {
// =============================================
describe('cambiaPalla', () => {
it('dovrebbe invertire il servizio a 0-0', () => {
expect(state.sp.servHome).toBe(true)
expect(servDi(state)).toBe(true)
const s = applyAction(state, { type: 'cambiaPalla' })
expect(s.sp.servHome).toBe(false)
expect(servDi(s)).toBe(false)
})
it('dovrebbe tornare a Home con doppio toggle', () => {
let s = applyAction(state, { type: 'cambiaPalla' })
s = applyAction(s, { type: 'cambiaPalla' })
expect(s.sp.servHome).toBe(true)
expect(servDi(s)).toBe(true)
})
it('non dovrebbe cambiare palla se il punteggio non è 0-0', () => {
state.sp.punt.home = 1
setPunteggio(state, 1, 0)
const prima = servDi(state)
const s = applyAction(state, { type: 'cambiaPalla' })
expect(s.sp.servHome).toBe(true)
expect(servDi(s)).toBe(prima)
})
it('non dovrebbe cambiare palla se Guest ha punti', () => {
state.sp.punt.guest = 3
setPunteggio(state, 0, 3)
const prima = servDi(state)
const s = applyAction(state, { type: 'cambiaPalla' })
expect(s.sp.servHome).toBe(true)
expect(servDi(s)).toBe(prima)
})
})
@@ -569,44 +659,37 @@ describe('Game Logic (gameState.js)', () => {
// =============================================
describe('checkVittoria', () => {
it('non dovrebbe dare vittoria a 24-24', () => {
state.sp.punt.home = 24
state.sp.punt.guest = 24
setPunteggio(state, 24, 24)
expect(checkVittoria(state)).toBe(false)
})
it('dovrebbe dare vittoria a 25-23', () => {
state.sp.punt.home = 25
state.sp.punt.guest = 23
setPunteggio(state, 25, 23)
expect(checkVittoria(state)).toBe(true)
})
it('non dovrebbe dare vittoria a 25-24 (serve 2 punti di scarto)', () => {
state.sp.punt.home = 25
state.sp.punt.guest = 24
setPunteggio(state, 25, 24)
expect(checkVittoria(state)).toBe(false)
})
it('dovrebbe dare vittoria a 26-24', () => {
state.sp.punt.home = 26
state.sp.punt.guest = 24
setPunteggio(state, 26, 24)
expect(checkVittoria(state)).toBe(true)
})
it('dovrebbe dare vittoria Guest a 25-20', () => {
state.sp.punt.home = 20
state.sp.punt.guest = 25
setPunteggio(state, 20, 25)
expect(checkVittoria(state)).toBe(true)
})
it('dovrebbe dare vittoria ai vantaggi (30-28)', () => {
state.sp.punt.home = 30
state.sp.punt.guest = 28
setPunteggio(state, 30, 28)
expect(checkVittoria(state)).toBe(true)
})
it('non dovrebbe dare vittoria ai vantaggi senza scarto (28-27)', () => {
state.sp.punt.home = 28
state.sp.punt.guest = 27
setPunteggio(state, 28, 27)
expect(checkVittoria(state)).toBe(false)
})
})
@@ -617,82 +700,64 @@ describe('Game Logic (gameState.js)', () => {
describe('Set decisivo', () => {
it('modalità 3/5: set decisivo dopo 4 set totali → vittoria a 15', () => {
state.modalitaPartita = "3/5"
state.sp.set.home = 2
state.sp.set.guest = 2
state.sp.punt.home = 15
state.sp.punt.guest = 10
setSetVinti(state, 2, 2)
setPunteggio(state, 15, 10)
expect(checkVittoria(state)).toBe(true)
})
it('modalità 3/5: non vittoria a 14-10 nel set decisivo', () => {
state.modalitaPartita = "3/5"
state.sp.set.home = 2
state.sp.set.guest = 2
state.sp.punt.home = 14
state.sp.punt.guest = 10
setSetVinti(state, 2, 2)
setPunteggio(state, 14, 10)
expect(checkVittoria(state)).toBe(false)
})
it('modalità 3/5: vittoria a 15-13 nel set decisivo', () => {
state.modalitaPartita = "3/5"
state.sp.set.home = 2
state.sp.set.guest = 2
state.sp.punt.home = 15
state.sp.punt.guest = 13
setSetVinti(state, 2, 2)
setPunteggio(state, 15, 13)
expect(checkVittoria(state)).toBe(true)
})
it('modalità 3/5: non vittoria a 15-14 nel set decisivo (serve scarto)', () => {
state.modalitaPartita = "3/5"
state.sp.set.home = 2
state.sp.set.guest = 2
state.sp.punt.home = 15
state.sp.punt.guest = 14
setSetVinti(state, 2, 2)
setPunteggio(state, 15, 14)
expect(checkVittoria(state)).toBe(false)
})
it('modalità 3/5: vittoria a 16-14 nel set decisivo', () => {
state.modalitaPartita = "3/5"
state.sp.set.home = 2
state.sp.set.guest = 2
state.sp.punt.home = 16
state.sp.punt.guest = 14
setSetVinti(state, 2, 2)
setPunteggio(state, 16, 14)
expect(checkVittoria(state)).toBe(true)
})
it('modalità 2/3: set decisivo dopo 2 set totali → vittoria a 15', () => {
state.modalitaPartita = "2/3"
state.sp.set.home = 1
state.sp.set.guest = 1
state.sp.punt.home = 15
state.sp.punt.guest = 10
setSetVinti(state, 1, 1)
setPunteggio(state, 15, 10)
expect(checkVittoria(state)).toBe(true)
})
it('modalità 2/3: non vittoria a 24-20 nel set decisivo (soglia 15)', () => {
it('modalità 2/3: non vittoria a 14-10 nel set decisivo (soglia 15)', () => {
state.modalitaPartita = "2/3"
state.sp.set.home = 1
state.sp.set.guest = 1
state.sp.punt.home = 14
state.sp.punt.guest = 10
setSetVinti(state, 1, 1)
setPunteggio(state, 14, 10)
expect(checkVittoria(state)).toBe(false)
})
it('modalità 2/3: set non decisivo (1-0) → soglia 25', () => {
state.modalitaPartita = "2/3"
state.sp.set.home = 1
state.sp.set.guest = 0
state.sp.punt.home = 15
state.sp.punt.guest = 10
setSetVinti(state, 1, 0)
setPunteggio(state, 15, 10)
expect(checkVittoria(state)).toBe(false)
})
it('modalità 3/5: set non decisivo (2-1) → soglia 25', () => {
state.modalitaPartita = "3/5"
state.sp.set.home = 2
state.sp.set.guest = 1
state.sp.punt.home = 15
state.sp.punt.guest = 10
setSetVinti(state, 2, 1)
setPunteggio(state, 15, 10)
expect(checkVittoria(state)).toBe(false)
})
})
@@ -702,15 +767,13 @@ describe('Game Logic (gameState.js)', () => {
// =============================================
describe('Reset', () => {
it('dovrebbe resettare punti e set a zero', () => {
state.sp.punt.home = 10
state.sp.punt.guest = 8
state.sp.set.home = 1
state.sp.set.guest = 1
setSetVinti(state, 1, 1)
setPunteggio(state, 10, 8)
const s = applyAction(state, { type: 'resetta' })
expect(s.sp.punt.home).toBe(0)
expect(s.sp.punt.guest).toBe(0)
expect(s.sp.set.home).toBe(0)
expect(s.sp.set.guest).toBe(0)
expect(puntDi(s).home).toBe(0)
expect(puntDi(s).guest).toBe(0)
expect(setDi(s).home).toBe(0)
expect(setDi(s).guest).toBe(0)
})
it('dovrebbe resettare formazioni a default', () => {
@@ -721,7 +784,7 @@ describe('Game Logic (gameState.js)', () => {
})
it('dovrebbe resettare la striscia a un set vuoto', () => {
state.sp.striscia = [{ serv: 'h', ris: 'hgh' }, { serv: 'h', ris: 'g' }]
state.sp.striscia = [{ serv: 'h', ris: 'hgh', vinc: 'h' }, { serv: 'h', ris: 'g', vinc: null }]
const s = applyAction(state, { type: 'resetta' })
expect(s.sp.striscia).toHaveLength(1)
expect(s.sp.striscia[0].ris).toBe('')
@@ -748,8 +811,8 @@ describe('Game Logic (gameState.js)', () => {
describe('Azione sconosciuta', () => {
it('dovrebbe restituire lo stato invariato con azione non riconosciuta', () => {
const s = applyAction(state, { type: 'azioneInesistente' })
expect(s.sp.punt.home).toBe(0)
expect(s.sp.punt.guest).toBe(0)
expect(puntDi(s).home).toBe(0)
expect(puntDi(s).guest).toBe(0)
})
})
})