test(timeout): copri startTimeout/stopTimeout e il timer server-side dei 30s
Unit: attivazione con squadra/video/inizio, rifiuto di squadre non valide, azzeramento completo con stopTimeout. Integration (fake timers): startedAt iniettato dal server, auto-chiusura a 30s con broadcast e persistenza, annullamento del timer su stop manuale e riarmo su nuovo avvio.
This commit is contained in:
@@ -80,8 +80,11 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(state.visuStriscia).toBe(true)
|
||||
})
|
||||
|
||||
it('dovrebbe avere timeout false', () => {
|
||||
it('dovrebbe avere timeout false e campi timeout nulli', () => {
|
||||
expect(state.timeout).toBe(false)
|
||||
expect(state.timeoutTeam).toBe(null)
|
||||
expect(state.timeoutVideo).toBe(null)
|
||||
expect(state.timeoutStartedAt).toBe(null)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -484,12 +487,50 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(s.order).toBe(false)
|
||||
})
|
||||
|
||||
it('toggleTimeout: false → true → false', () => {
|
||||
expect(state.timeout).toBe(false)
|
||||
const s1 = applyAction(state, { type: 'toggleTimeout' })
|
||||
expect(s1.timeout).toBe(true)
|
||||
const s2 = applyAction(s1, { type: 'toggleTimeout' })
|
||||
expect(s2.timeout).toBe(false)
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// TIME OUT (startTimeout, stopTimeout)
|
||||
// =============================================
|
||||
describe('Time out', () => {
|
||||
it('startTimeout dovrebbe attivare il time out con squadra, video e inizio', () => {
|
||||
const s = applyAction(state, { type: 'startTimeout', team: 'home', video: 'spot.mp4', startedAt: 1000 })
|
||||
expect(s.timeout).toBe(true)
|
||||
expect(s.timeoutTeam).toBe('home')
|
||||
expect(s.timeoutVideo).toBe('spot.mp4')
|
||||
expect(s.timeoutStartedAt).toBe(1000)
|
||||
})
|
||||
|
||||
it('startTimeout senza video dovrebbe lasciare timeoutVideo null', () => {
|
||||
const s = applyAction(state, { type: 'startTimeout', team: 'guest', startedAt: 1000 })
|
||||
expect(s.timeout).toBe(true)
|
||||
expect(s.timeoutTeam).toBe('guest')
|
||||
expect(s.timeoutVideo).toBe(null)
|
||||
})
|
||||
|
||||
it('startTimeout senza squadra valida dovrebbe essere ignorato', () => {
|
||||
for (const team of [undefined, null, 'arbitro', '']) {
|
||||
const s = applyAction(state, { type: 'startTimeout', team, video: 'spot.mp4', startedAt: 1000 })
|
||||
expect(s.timeout).toBe(false)
|
||||
expect(s.timeoutTeam).toBe(null)
|
||||
expect(s.timeoutVideo).toBe(null)
|
||||
expect(s.timeoutStartedAt).toBe(null)
|
||||
}
|
||||
})
|
||||
|
||||
it('stopTimeout dovrebbe azzerare tutti i campi del time out', () => {
|
||||
const attivo = applyAction(state, { type: 'startTimeout', team: 'home', video: 'spot.mp4', startedAt: 1000 })
|
||||
const s = applyAction(attivo, { type: 'stopTimeout' })
|
||||
expect(s.timeout).toBe(false)
|
||||
expect(s.timeoutTeam).toBe(null)
|
||||
expect(s.timeoutVideo).toBe(null)
|
||||
expect(s.timeoutStartedAt).toBe(null)
|
||||
})
|
||||
|
||||
it('stopTimeout su time out già inattivo non dovrebbe avere effetti', () => {
|
||||
const s = applyAction(state, { type: 'stopTimeout' })
|
||||
expect(s.timeout).toBe(false)
|
||||
expect(s.timeoutTeam).toBe(null)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user