2625284e99
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.
32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
// @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)
|
|
})
|
|
})
|