feat: blocca partita a fine match e mostra dialog dedicato
Aggiunge checkVittoriaPartita per rilevare la vittoria della partita (2 set in 2/3, 3 set in 3/5). nuovoSet ora registra il set vincente senza resettare il punteggio quando la partita è finita. Il controller mostra "PARTITA FINITA" al posto di "SET VINTO" con solo il tasto CHIUDI.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { createInitialState, applyAction, checkVittoria } from '../../src/gameState.js'
|
||||
import { createInitialState, applyAction, checkVittoria, checkVittoriaPartita } from '../../src/gameState.js'
|
||||
|
||||
describe('Game Logic (gameState.js)', () => {
|
||||
let state
|
||||
@@ -271,6 +271,66 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(s.sp.set.home).toBe(0)
|
||||
expect(s.sp.set.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('in 2/3 dovrebbe registrare il set vincente senza resettare il punteggio', () => {
|
||||
state.modalitaPartita = '2/3'
|
||||
state.sp.set.home = 1
|
||||
state.sp.punt.home = 25
|
||||
state.sp.punt.guest = 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)
|
||||
})
|
||||
|
||||
it('in 3/5 dovrebbe registrare il set vincente senza resettare il punteggio', () => {
|
||||
state.modalitaPartita = '3/5'
|
||||
state.sp.set.home = 2
|
||||
state.sp.punt.home = 25
|
||||
state.sp.punt.guest = 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)
|
||||
})
|
||||
|
||||
it('dovrebbe ignorare nuovoSet se la partita è già finita', () => {
|
||||
state.modalitaPartita = '2/3'
|
||||
state.sp.set.home = 2
|
||||
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
||||
expect(s.sp.set.home).toBe(2)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// VITTORIA PARTITA (checkVittoriaPartita)
|
||||
// =============================================
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
expect(checkVittoriaPartita(state)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
|
||||
Reference in New Issue
Block a user