refactor(striscia): nuova struttura array-di-set, elimina storicoServizio
La striscia diventa un array di set: ogni elemento è { serv, r[] }
dove r è la sequenza di scorer ('home'|'guest') del set.
- Un rally = un elemento in r: minimo non-derivabile
- Tutti i set (passati e corrente) sono conservati nell'array
- Dal set corrente si derivano: punteggio, servizio, cambio palla, rotazione
- Dal set completo si derivano: vincitore (r.at(-1)), score finale (count)
- storicoServizio eliminato: l'undo legge l'entry precedente di r
DisplayPage calcola le strip visive (home/guest) tramite computed
da striscia.at(-1).r senza dati ridondanti nel modello.
This commit is contained in:
@@ -31,13 +31,10 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(state.sp.form.guest).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('dovrebbe avere la striscia iniziale a [0]', () => {
|
||||
expect(state.sp.striscia.home).toEqual([0])
|
||||
expect(state.sp.striscia.guest).toEqual([0])
|
||||
})
|
||||
|
||||
it('dovrebbe avere storico servizio vuoto', () => {
|
||||
expect(state.sp.storicoServizio).toEqual([])
|
||||
it('dovrebbe avere la striscia iniziale con un set vuoto', () => {
|
||||
expect(state.sp.striscia).toHaveLength(1)
|
||||
expect(state.sp.striscia[0].serv).toBe('home')
|
||||
expect(state.sp.striscia[0].r).toEqual([])
|
||||
})
|
||||
|
||||
it('dovrebbe avere modalità 3/5 di default', () => {
|
||||
@@ -116,21 +113,19 @@ describe('Game Logic (gameState.js)', () => {
|
||||
|
||||
it('dovrebbe aggiornare la striscia per punto Home', () => {
|
||||
const s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(s.sp.striscia.home).toEqual([0, 1])
|
||||
expect(s.sp.striscia.guest).toEqual([0, " "])
|
||||
expect(s.sp.striscia.at(-1).r).toEqual(['home'])
|
||||
})
|
||||
|
||||
it('dovrebbe aggiornare la striscia per punto Guest', () => {
|
||||
const s = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
expect(s.sp.striscia.guest).toEqual([0, 1])
|
||||
expect(s.sp.striscia.home).toEqual([0, " "])
|
||||
expect(s.sp.striscia.at(-1).r).toEqual(['guest'])
|
||||
})
|
||||
|
||||
it('dovrebbe registrare lo storico servizio', () => {
|
||||
const s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(s.sp.storicoServizio).toHaveLength(1)
|
||||
expect(s.sp.storicoServizio[0]).toHaveProperty('servHome')
|
||||
expect(s.sp.storicoServizio[0]).toHaveProperty('cambioPalla')
|
||||
it('dovrebbe registrare scorer nella striscia', () => {
|
||||
let s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
s = applyAction(s, { type: 'incPunt', team: 'guest' })
|
||||
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||
expect(s.sp.striscia.at(-1).r).toEqual(['home', 'guest', 'home'])
|
||||
})
|
||||
|
||||
it('non dovrebbe incrementare i punti dopo vittoria', () => {
|
||||
@@ -185,7 +180,7 @@ describe('Game Logic (gameState.js)', () => {
|
||||
it('dovrebbe ripristinare la striscia', () => {
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||
expect(s2.sp.striscia.home).toEqual([0])
|
||||
expect(s2.sp.striscia.at(-1).r).toEqual([])
|
||||
})
|
||||
|
||||
it('dovrebbe gestire undo multipli in sequenza', () => {
|
||||
@@ -250,16 +245,17 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(s.sp.punt.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe resettare la striscia', () => {
|
||||
state.sp.punt.home = 25
|
||||
it('dovrebbe aggiungere un nuovo set vuoto alla striscia', () => {
|
||||
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
||||
expect(s.sp.striscia).toEqual({ home: [0], guest: [0] })
|
||||
expect(s.sp.striscia).toHaveLength(2)
|
||||
expect(s.sp.striscia.at(-1).r).toEqual([])
|
||||
expect(s.sp.striscia.at(-1).serv).toBe('home')
|
||||
})
|
||||
|
||||
it('dovrebbe resettare lo storico servizio', () => {
|
||||
state.sp.storicoServizio = [{ servHome: true, cambioPalla: false }]
|
||||
it('dovrebbe conservare il set precedente nella striscia', () => {
|
||||
state.sp.striscia[0].r = ['home', 'guest', 'home']
|
||||
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
||||
expect(s.sp.storicoServizio).toEqual([])
|
||||
expect(s.sp.striscia[0].r).toEqual(['home', 'guest', 'home'])
|
||||
})
|
||||
|
||||
it('dovrebbe resettare le formazioni', () => {
|
||||
@@ -664,17 +660,11 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(s.sp.form.guest).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('dovrebbe resettare la striscia', () => {
|
||||
state.sp.striscia = { home: [0, 1, 2, 3], guest: [0, " ", " ", 1] }
|
||||
it('dovrebbe resettare la striscia a un set vuoto', () => {
|
||||
state.sp.striscia = [{ serv: 'home', r: ['home', 'guest', 'home'] }, { serv: 'home', r: ['guest'] }]
|
||||
const s = applyAction(state, { type: 'resetta' })
|
||||
expect(s.sp.striscia.home).toEqual([0])
|
||||
expect(s.sp.striscia.guest).toEqual([0])
|
||||
})
|
||||
|
||||
it('dovrebbe resettare lo storico servizio', () => {
|
||||
state.sp.storicoServizio = [{ servHome: true, cambioPalla: false }]
|
||||
const s = applyAction(state, { type: 'resetta' })
|
||||
expect(s.sp.storicoServizio).toEqual([])
|
||||
expect(s.sp.striscia).toHaveLength(1)
|
||||
expect(s.sp.striscia[0].r).toEqual([])
|
||||
})
|
||||
|
||||
it('dovrebbe impostare visuForm a false', () => {
|
||||
|
||||
Reference in New Issue
Block a user