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)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
|
||||
@@ -97,6 +97,38 @@ describe('buildRefertoHtml (referto.js)', () => {
|
||||
expect(html).toContain('Nessun punto registrato')
|
||||
})
|
||||
|
||||
it('elenca time out e cambi del set con squadra e punteggio', () => {
|
||||
const striscia = [{
|
||||
serv: 'h', ris: 'hhhg', vinc: null,
|
||||
timeouts: [{ team: 'guest', punteggio: { home: 3, guest: 1 } }],
|
||||
cambi: [{ team: 'home', in: '10', out: '3', punteggio: { home: 2, guest: 0 } }],
|
||||
}]
|
||||
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||
expect(html).toContain('Cambi e time out')
|
||||
expect(html).toContain('Time out <strong>Rivali</strong> sul 3-1')
|
||||
expect(html).toContain('Cambio <strong>Antoniana</strong>: entra 10 per 3 sul 2-0')
|
||||
})
|
||||
|
||||
it('ordina gli eventi per punteggio crescente', () => {
|
||||
const striscia = [{
|
||||
serv: 'h', ris: 'hhhgg', vinc: null,
|
||||
timeouts: [{ team: 'home', punteggio: { home: 3, guest: 2 } }],
|
||||
cambi: [{ team: 'guest', in: '9', out: '4', punteggio: { home: 1, guest: 0 } }],
|
||||
}]
|
||||
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||
const idxCambio = html.indexOf('entra 9 per 4')
|
||||
const idxTimeout = html.indexOf('Time out')
|
||||
expect(idxCambio).toBeGreaterThan(-1)
|
||||
expect(idxTimeout).toBeGreaterThan(-1)
|
||||
expect(idxCambio).toBeLessThan(idxTimeout)
|
||||
})
|
||||
|
||||
it('omette la sezione eventi se il set non ne ha', () => {
|
||||
const striscia = [{ serv: 'h', ris: 'h', vinc: null }]
|
||||
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||
expect(html).not.toContain('Cambi e time out')
|
||||
})
|
||||
|
||||
it('header contiene nomi squadre, modalità e data iniettata', () => {
|
||||
const striscia = [{ serv: 'h', ris: '', vinc: null }]
|
||||
const state = statoConSet(striscia)
|
||||
|
||||
Reference in New Issue
Block a user