feat(striscia): registra cambi e time out per set (#18)
La striscia salva ora storico cambi formazione e time out per ogni set, con riferimento al punteggio al momento dell'evento anziché a un timestamp: startTimeout accumula in set.timeouts, confermaCambi in set.cambi. Il referto elenca entrambi ordinati per punteggio.
This commit is contained in:
@@ -532,6 +532,46 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(s.timeout).toBe(false)
|
||||
expect(s.timeoutTeam).toBe(null)
|
||||
})
|
||||
|
||||
it('startTimeout dovrebbe registrare l\'evento nel set corrente con il punteggio', () => {
|
||||
let s = state
|
||||
for (let i = 0; i < 3; i++) s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||
s = applyAction(s, { type: 'incPunt', team: 'guest' })
|
||||
s = applyAction(s, { type: 'startTimeout', team: 'guest', startedAt: 1000 })
|
||||
expect(s.sp.striscia.at(-1).timeouts).toEqual([
|
||||
{ team: 'guest', punteggio: { home: 3, guest: 1 } },
|
||||
])
|
||||
})
|
||||
|
||||
it('startTimeout su time out già attivo non dovrebbe registrare un secondo evento', () => {
|
||||
let s = applyAction(state, { type: 'startTimeout', team: 'home', startedAt: 1000 })
|
||||
s = applyAction(s, { type: 'startTimeout', team: 'home', startedAt: 2000 })
|
||||
expect(s.sp.striscia.at(-1).timeouts).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('time out successivi dovrebbero accumularsi nel set corrente', () => {
|
||||
let s = applyAction(state, { type: 'startTimeout', team: 'home', startedAt: 1000 })
|
||||
s = applyAction(s, { type: 'stopTimeout' })
|
||||
s = applyAction(s, { type: 'incPunt', team: 'guest' })
|
||||
s = applyAction(s, { type: 'startTimeout', team: 'guest', startedAt: 2000 })
|
||||
expect(s.sp.striscia.at(-1).timeouts).toEqual([
|
||||
{ team: 'home', punteggio: { home: 0, guest: 0 } },
|
||||
{ team: 'guest', punteggio: { home: 0, guest: 1 } },
|
||||
])
|
||||
})
|
||||
|
||||
it('un nuovo set non dovrebbe ereditare i time out del precedente', () => {
|
||||
let s = applyAction(state, { type: 'startTimeout', team: 'home', startedAt: 1000 })
|
||||
s = applyAction(s, { type: 'stopTimeout' })
|
||||
s = applyAction(s, { type: 'nuovoSet', team: 'home' })
|
||||
expect(s.sp.striscia.at(-1).timeouts).toBeUndefined()
|
||||
expect(s.sp.striscia.at(-2).timeouts).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('startTimeout ignorato non dovrebbe registrare eventi', () => {
|
||||
const s = applyAction(state, { type: 'startTimeout', team: 'arbitro', startedAt: 1000 })
|
||||
expect(s.sp.striscia.at(-1).timeouts).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
@@ -705,6 +745,64 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(s.sp.form.home).not.toContain("1")
|
||||
expect(s.sp.form.home).not.toContain("10")
|
||||
})
|
||||
|
||||
it('dovrebbe registrare il cambio nel set corrente con il punteggio', () => {
|
||||
let s = state
|
||||
for (let i = 0; i < 2; i++) s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||
s = applyAction(s, { type: 'incPunt', team: 'guest' })
|
||||
s = applyAction(s, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "10", out: "3" }]
|
||||
})
|
||||
expect(s.sp.striscia.at(-1).cambi).toEqual([
|
||||
{ team: 'home', in: "10", out: "3", punteggio: { home: 2, guest: 1 } },
|
||||
])
|
||||
})
|
||||
|
||||
it('dovrebbe registrare ogni cambio di una doppia sostituzione', () => {
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'guest',
|
||||
cambi: [
|
||||
{ in: "10", out: "1" },
|
||||
{ in: "11", out: "2" }
|
||||
]
|
||||
})
|
||||
expect(s.sp.striscia.at(-1).cambi).toEqual([
|
||||
{ team: 'guest', in: "10", out: "1", punteggio: { home: 0, guest: 0 } },
|
||||
{ team: 'guest', in: "11", out: "2", punteggio: { home: 0, guest: 0 } },
|
||||
])
|
||||
})
|
||||
|
||||
it('non dovrebbe registrare nulla se la validazione fallisce', () => {
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "abc", out: "1" }]
|
||||
})
|
||||
expect(s.sp.striscia.at(-1).cambi).toBeUndefined()
|
||||
})
|
||||
|
||||
it('non dovrebbe registrare nulla se tutti i cambi sono vuoti', () => {
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "", out: "" }]
|
||||
})
|
||||
expect(s.sp.striscia.at(-1).cambi).toBeUndefined()
|
||||
})
|
||||
|
||||
it('un nuovo set non dovrebbe ereditare i cambi del precedente', () => {
|
||||
let s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "10", out: "3" }]
|
||||
})
|
||||
s = applyAction(s, { type: 'nuovoSet', team: 'home' })
|
||||
expect(s.sp.striscia.at(-1).cambi).toBeUndefined()
|
||||
expect(s.sp.striscia.at(-2).cambi).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
|
||||
Reference in New Issue
Block a user