test(referto): copri generaReferto e il branch guest di vincitoreSet
buildRefertoHtml mancava il caso vinc nullo con guest in vantaggio; generaReferto (window.open/print) non era testato affatto perché richiede un DOM — aggiunto un test component in happy-dom che mocka window.open.
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
// @vitest-environment happy-dom
|
||||||
|
import { describe, it, expect, vi, afterEach } from 'vitest'
|
||||||
|
import { generaReferto } from '../../src/referto.js'
|
||||||
|
import { createInitialState } from '../../src/gameState.js'
|
||||||
|
|
||||||
|
// generaReferto è l'unico punto con effetti collaterali di referto.js (window.open
|
||||||
|
// + stampa): qui verifichiamo che orchestri correttamente le API del browser,
|
||||||
|
// mockando window.open per non aprire davvero una finestra durante i test.
|
||||||
|
describe('generaReferto (referto.js)', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('apre una nuova scheda, scrive il referto e avvia la stampa', () => {
|
||||||
|
const popup = {
|
||||||
|
document: { write: vi.fn(), close: vi.fn() },
|
||||||
|
print: vi.fn(),
|
||||||
|
}
|
||||||
|
const openSpy = vi.spyOn(window, 'open').mockReturnValue(popup)
|
||||||
|
|
||||||
|
const state = createInitialState()
|
||||||
|
state.sp.nomi = { home: 'Antoniana', guest: 'Rivali' }
|
||||||
|
generaReferto(state)
|
||||||
|
|
||||||
|
expect(openSpy).toHaveBeenCalledWith('', '_blank')
|
||||||
|
expect(popup.document.write).toHaveBeenCalledTimes(1)
|
||||||
|
expect(popup.document.write.mock.calls[0][0]).toContain('Antoniana')
|
||||||
|
expect(popup.document.close).toHaveBeenCalledTimes(1)
|
||||||
|
expect(popup.print).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -60,6 +60,15 @@ describe('buildRefertoHtml (referto.js)', () => {
|
|||||||
expect(html).toContain('1 – 0')
|
expect(html).toContain('1 – 0')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('ricava il vincitore guest dal conteggio punti se vinc è nullo', () => {
|
||||||
|
const striscia = [
|
||||||
|
{ serv: 'h', ris: 'g'.repeat(25) + 'h'.repeat(20), vinc: null },
|
||||||
|
]
|
||||||
|
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||||
|
// conteggio punti guest > home, pur con vinc null → 0 – 1
|
||||||
|
expect(html).toContain('0 – 1')
|
||||||
|
})
|
||||||
|
|
||||||
it('include la progressione punto-punto con classi per squadra', () => {
|
it('include la progressione punto-punto con classi per squadra', () => {
|
||||||
const striscia = [
|
const striscia = [
|
||||||
{ serv: 'h', ris: 'hhg', vinc: null },
|
{ serv: 'h', ris: 'hhg', vinc: null },
|
||||||
|
|||||||
Reference in New Issue
Block a user