test(component): porta ControllerPage e DisplayPage al 100% di statement coverage
Aggiunge 65 test per ControllerPage.vue (layout esteso/landscape, popup automatico di set vinto con soglia decisiva, modal di configurazione, validazione completa dei cambi giocatore, modal time out con selezione video/ticker/countdown, cleanup dei listener) e 35 per DisplayPage.vue (countdown overlay, riallineamento video su riconnessione, fallback muto per autoplay bloccato, selezione voce per la sintesi vocale). Nessun bug riscontrato nei componenti.
This commit is contained in:
@@ -133,6 +133,14 @@ describe('ControllerPage.vue', () => {
|
|||||||
const btn = wrapper.findAll('.btn-ctrl').find(b => b.text().includes('Cambio Palla'))
|
const btn = wrapper.findAll('.btn-ctrl').find(b => b.text().includes('Cambio Palla'))
|
||||||
expect(btn.attributes('disabled')).toBeDefined()
|
expect(btn.attributes('disabled')).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('il click quando abilitato invia cambiaPalla', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
const btn = wrapper.findAll('.btn-ctrl').find(b => b.text().includes('Cambio Palla'))
|
||||||
|
await btn.trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'cambiaPalla' })
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
@@ -349,6 +357,25 @@ describe('ControllerPage.vue', () => {
|
|||||||
expect(spy).toHaveBeenCalledWith({ type: 'stopTimeout' })
|
expect(spy).toHaveBeenCalledWith({ type: 'stopTimeout' })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('avviaTimeout non invia nulla se nessuna squadra è selezionata', () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.timeoutTeamSel = null
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
wrapper.vm.avviaTimeout()
|
||||||
|
expect(spy).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('il ticker del time out aggiorna nowTick periodicamente', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.state.timeoutTeam = 'home'
|
||||||
|
wrapper.vm.state.timeoutStartedAt = Date.now()
|
||||||
|
wrapper.vm.state.timeout = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const before = wrapper.vm.nowTick
|
||||||
|
vi.advanceTimersByTime(500)
|
||||||
|
expect(wrapper.vm.nowTick).toBeGreaterThan(before)
|
||||||
|
})
|
||||||
|
|
||||||
it('durante il time out mostra banner con squadra e countdown', async () => {
|
it('durante il time out mostra banner con squadra e countdown', async () => {
|
||||||
const wrapper = mountController()
|
const wrapper = mountController()
|
||||||
wrapper.vm.state.timeoutTeam = 'home'
|
wrapper.vm.state.timeoutTeam = 'home'
|
||||||
@@ -365,6 +392,587 @@ describe('ControllerPage.vue', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// MODALITÀ ESTESA (landscape)
|
||||||
|
// =============================================
|
||||||
|
describe('Modalità estesa', () => {
|
||||||
|
it('con isLandscape=true mostra il layout esteso con i pannelli squadra', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.isLandscape = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.find('.e-dash').exists()).toBe(true)
|
||||||
|
expect(wrapper.findAll('.e-panel')).toHaveLength(2)
|
||||||
|
// in modalità estesa non compare il layout mobile
|
||||||
|
expect(wrapper.find('.score-preview').exists()).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('il resize della finestra aggiorna isLandscape', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
expect(wrapper.vm.isLandscape).toBe(false)
|
||||||
|
Object.defineProperty(window, 'innerWidth', { value: 800, writable: true, configurable: true })
|
||||||
|
Object.defineProperty(window, 'innerHeight', { value: 400, writable: true, configurable: true })
|
||||||
|
window.dispatchEvent(new Event('resize'))
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.isLandscape).toBe(true)
|
||||||
|
// ripristina le dimensioni portrait usate dagli altri test
|
||||||
|
Object.defineProperty(window, 'innerWidth', { value: 400, writable: true, configurable: true })
|
||||||
|
Object.defineProperty(window, 'innerHeight', { value: 800, writable: true, configurable: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('il click sul punteggio in modalità estesa invia incPunt', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.isLandscape = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
await wrapper.findAll('.e-panel__score')[0].trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'incPunt', team: 'home' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('smontare il componente rimuove i listener di resize e ferma il ticker del time out', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.state.timeout = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(vi.getTimerCount()).toBeGreaterThan(0)
|
||||||
|
const removeSpy = vi.spyOn(window, 'removeEventListener')
|
||||||
|
wrapper.unmount()
|
||||||
|
expect(removeSpy).toHaveBeenCalledWith('resize', expect.any(Function))
|
||||||
|
expect(removeSpy).toHaveBeenCalledWith('orientationchange', expect.any(Function))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// SET VINTO AUTOMATICO (watch squadraVincente)
|
||||||
|
// =============================================
|
||||||
|
describe('Set vinto automatico', () => {
|
||||||
|
it('apre la modal SET VINTO quando il punteggio raggiunge la soglia', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
setScore(wrapper, 25, 10)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.showSetVinto).toBe(true)
|
||||||
|
expect(wrapper.vm.setVintoTeam).toBe('home')
|
||||||
|
expect(wrapper.find('.dialog-title').text()).toBe('SET VINTO')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('non riapre la modal se è già aperta', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
setScore(wrapper, 25, 10)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
wrapper.vm.setVintoTeam = 'guest'
|
||||||
|
setScore(wrapper, 25, 24)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
// il watch non deve sovrascrivere setVintoTeam perché showSetVinto è già true
|
||||||
|
expect(wrapper.vm.setVintoTeam).toBe('guest')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('INDIETRO annulla l\'ultimo punto e chiude la modal', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
setScore(wrapper, 25, 10)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
await wrapper.find('.btn-cancel').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'decPunt' })
|
||||||
|
expect(wrapper.vm.showSetVinto).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('VAI AL SET SUCCESSIVO invia nuovoSet e apre la configurazione', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
setScore(wrapper, 25, 10)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
const btn = wrapper.findAll('.btn-confirm').find(b => b.text().includes('SET SUCCESSIVO'))
|
||||||
|
await btn.trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'nuovoSet', team: 'home' })
|
||||||
|
expect(wrapper.vm.showSetVinto).toBe(false)
|
||||||
|
expect(wrapper.vm.showConfig).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// CONFIGURAZIONE
|
||||||
|
// =============================================
|
||||||
|
describe('Configurazione', () => {
|
||||||
|
it('apre la modal di configurazione precompilata con lo stato corrente', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
await wrapper.find('.btn-ctrl:not(.btn-timeout)').exists()
|
||||||
|
const btn = wrapper.findAll('.btn-ctrl').find(b => b.text() === 'Config')
|
||||||
|
await btn.trigger('click')
|
||||||
|
expect(wrapper.vm.showConfig).toBe(true)
|
||||||
|
expect(wrapper.vm.configData.nomeHome).toBe('Antoniana')
|
||||||
|
expect(wrapper.vm.configData.nomeGuest).toBe('Guest')
|
||||||
|
expect(wrapper.vm.configData.modalita).toBe('3/5')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('OK invia le action di configurazione e chiude la modal', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.showConfig = true
|
||||||
|
wrapper.vm.configData = {
|
||||||
|
nomeHome: 'Casa', nomeGuest: 'Ospiti', modalita: '2/3',
|
||||||
|
formHome: ['1', '2', '3', '4', '5', '6'],
|
||||||
|
formGuest: ['1', '2', '3', '4', '5', '6'],
|
||||||
|
}
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
await wrapper.find('.dialog-config .btn-confirm').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'setNomi', home: 'Casa', guest: 'Ospiti' })
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'setModalita', modalita: '2/3' })
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'setFormazione', team: 'home', form: ['1', '2', '3', '4', '5', '6'] })
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'setFormazione', team: 'guest', form: ['1', '2', '3', '4', '5', '6'] })
|
||||||
|
expect(wrapper.vm.showConfig).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Annulla chiude la modal di configurazione senza inviare nulla', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.showConfig = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
await wrapper.find('.dialog-config .btn-cancel').trigger('click')
|
||||||
|
expect(spy).not.toHaveBeenCalled()
|
||||||
|
expect(wrapper.vm.showConfig).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('scegliendo la modalità 2/3 il bottone diventa attivo', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.showConfig = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const btn23 = wrapper.findAll('.btn-mode').find(b => b.text() === '2/3')
|
||||||
|
await btn23.trigger('click')
|
||||||
|
expect(wrapper.vm.configData.modalita).toBe('2/3')
|
||||||
|
expect(btn23.classes()).toContain('active')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// GESTIONE CAMBI GIOCATORE
|
||||||
|
// =============================================
|
||||||
|
describe('Gestione cambi', () => {
|
||||||
|
it('il click su Cambi apre la selezione squadra, poi la modal cambio per la squadra scelta', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
const btnCambi = wrapper.findAll('.btn-ctrl').find(b => b.text() === 'Cambi')
|
||||||
|
await btnCambi.trigger('click')
|
||||||
|
expect(wrapper.vm.showCambiTeam).toBe(true)
|
||||||
|
await wrapper.find('.dialog-title').exists()
|
||||||
|
const btnHome = wrapper.find('.overlay .btn-set.home-bg')
|
||||||
|
await btnHome.trigger('click')
|
||||||
|
expect(wrapper.vm.showCambiTeam).toBe(false)
|
||||||
|
expect(wrapper.vm.showCambi).toBe(true)
|
||||||
|
expect(wrapper.vm.cambiTeam).toBe('home')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Annulla chiude la modal cambi e azzera i campi', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.openCambi('home')
|
||||||
|
wrapper.vm.cambiData = [{ in: '10', out: '1' }, { in: '', out: '' }]
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
await wrapper.find('.dialog .btn-cancel').trigger('click')
|
||||||
|
expect(wrapper.vm.showCambi).toBe(false)
|
||||||
|
expect(wrapper.vm.cambiData).toEqual([{ in: '', out: '' }, { in: '', out: '' }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('CONFERMA con un cambio valido invia confermaCambi e chiude la modal', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.openCambi('home')
|
||||||
|
wrapper.vm.cambiData = [{ in: '10', out: '1' }, { in: '', out: '' }]
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
await wrapper.find('.dialog .btn-confirm').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'confermaCambi', team: 'home', cambi: [{ in: '10', out: '1' }] })
|
||||||
|
expect(wrapper.vm.showCambi).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('segnala errore se il numero del giocatore non è formato da sole cifre', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.openCambi('home')
|
||||||
|
wrapper.vm.cambiData = [{ in: 'ab', out: '1' }, { in: '', out: '' }]
|
||||||
|
wrapper.vm.confermaCambi()
|
||||||
|
expect(wrapper.vm.cambiError).toBe('I numeri dei giocatori devono essere cifre')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('segnala errore se il giocatore entrante coincide con l\'uscente', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.openCambi('home')
|
||||||
|
wrapper.vm.cambiData = [{ in: '1', out: '1' }, { in: '', out: '' }]
|
||||||
|
wrapper.vm.confermaCambi()
|
||||||
|
expect(wrapper.vm.cambiError).toBe('Il giocatore 1 non può sostituire sé stesso')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('segnala errore se il giocatore entrante è già in formazione', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.openCambi('home')
|
||||||
|
// "2" è già presente nella formazione di default ["1".."6"]
|
||||||
|
wrapper.vm.cambiData = [{ in: '2', out: '1' }, { in: '', out: '' }]
|
||||||
|
wrapper.vm.confermaCambi()
|
||||||
|
expect(wrapper.vm.cambiError).toBe('Il giocatore 2 è già in formazione')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('segnala errore se il giocatore uscente non è in formazione', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.openCambi('home')
|
||||||
|
wrapper.vm.cambiData = [{ in: '10', out: '9' }, { in: '', out: '' }]
|
||||||
|
wrapper.vm.confermaCambi()
|
||||||
|
expect(wrapper.vm.cambiError).toBe('Il giocatore 9 non è in formazione')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('confermaCambi non fa nulla se cambiValid è false', () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.openCambi('home')
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
wrapper.vm.cambiData = [{ in: '', out: '' }, { in: '', out: '' }]
|
||||||
|
wrapper.vm.confermaCambi()
|
||||||
|
expect(spy).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// GESTIONE ERRORI WEBSOCKET
|
||||||
|
// =============================================
|
||||||
|
describe('Gestione errori WebSocket', () => {
|
||||||
|
it('onWsMessage con type error logga il messaggio', () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||||
|
wrapper.vm.onWsMessage({ type: 'error', message: 'boom' })
|
||||||
|
expect(spy).toHaveBeenCalledWith('[Controller] Error:', 'boom')
|
||||||
|
spy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sendAction senza type non invia nulla', () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendWs')
|
||||||
|
wrapper.vm.sendAction({})
|
||||||
|
expect(spy).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sendAction mostra un feedback di errore se non connesso', () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||||
|
wrapper.vm.wsConnected = false
|
||||||
|
wrapper.vm.sendAction({ type: 'incPunt', team: 'home' })
|
||||||
|
expect(errSpy).toHaveBeenCalledWith('[Controller] Error:', 'Non connesso al server')
|
||||||
|
errSpy.mockRestore()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// DURATA VIDEO SPOT
|
||||||
|
// =============================================
|
||||||
|
describe('Durata video spot', () => {
|
||||||
|
it('formatDurata mostra i secondi arrotondati o un placeholder', () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
expect(wrapper.vm.formatDurata(12.4)).toBe('12s')
|
||||||
|
expect(wrapper.vm.formatDurata(undefined)).toBe('…')
|
||||||
|
expect(wrapper.vm.formatDurata(NaN)).toBe('…')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('probeDurata popola spotDurations quando i metadata del video sono pronti', () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
const videoEls = []
|
||||||
|
const originalCreateElement = document.createElement.bind(document)
|
||||||
|
vi.spyOn(document, 'createElement').mockImplementation((tag) => {
|
||||||
|
const el = originalCreateElement(tag)
|
||||||
|
if (tag === 'video') videoEls.push(el)
|
||||||
|
return el
|
||||||
|
})
|
||||||
|
wrapper.vm.probeDurata('a.mp4')
|
||||||
|
const videoEl = videoEls[0]
|
||||||
|
Object.defineProperty(videoEl, 'duration', { value: 42, configurable: true })
|
||||||
|
videoEl.onloadedmetadata()
|
||||||
|
expect(wrapper.vm.spotDurations['a.mp4']).toBe(42)
|
||||||
|
document.createElement.mockRestore()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// PULSANTI MOBILE (click reali sui bottoni)
|
||||||
|
// =============================================
|
||||||
|
describe('Pulsanti layout mobile', () => {
|
||||||
|
it('ANNULLA PUNTO invia decPunt', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
await wrapper.find('.btn-undo').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'decPunt' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('i due bottoni SET inviano incSet per la rispettiva squadra', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
const setBtns = wrapper.findAll('.action-row .btn-set')
|
||||||
|
await setBtns[0].trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'incSet', team: 'home' })
|
||||||
|
await setBtns[1].trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'incSet', team: 'guest' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Formazioni/Striscia/Inverti/Voce inviano le rispettive action', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
const byLabel = (label) => wrapper.findAll('.btn-ctrl').find(b => b.text().includes(label))
|
||||||
|
await byLabel('Formazioni').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'toggleFormazione' })
|
||||||
|
await byLabel('Striscia').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'toggleStriscia' })
|
||||||
|
await byLabel('Inverti').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'toggleOrder' })
|
||||||
|
const wsSendSpy = vi.spyOn(wrapper.vm, 'sendWs')
|
||||||
|
wrapper.vm.wsConnected = true
|
||||||
|
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
||||||
|
await byLabel('Voce').trigger('click')
|
||||||
|
expect(wsSendSpy).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('con order=false lo score-preview mostra prima guest e poi home', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.state.order = false
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
const scores = wrapper.findAll('.team-score')
|
||||||
|
expect(scores[0].classes()).toContain('guest-bg')
|
||||||
|
expect(scores[1].classes()).toContain('home-bg')
|
||||||
|
await scores[0].trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'incPunt', team: 'guest' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// MODALITÀ ESTESA: interazioni aggiuntive
|
||||||
|
// =============================================
|
||||||
|
describe('Modalità estesa: interazioni', () => {
|
||||||
|
it('il click sul punteggio e sul bottone SET della seconda squadra funzionano', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.isLandscape = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
await wrapper.findAll('.e-panel__score')[1].trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'incPunt', team: 'guest' })
|
||||||
|
await wrapper.findAll('.e-panel__setbtn')[0].trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'incSet', team: 'home' })
|
||||||
|
await wrapper.findAll('.e-panel__setbtn')[1].trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'incSet', team: 'guest' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('la barra e-actions invia le action corrispondenti ai bottoni', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.isLandscape = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
const byLabel = (label) => wrapper.findAll('.e-act').find(b => b.text().includes(label))
|
||||||
|
await byLabel('Annulla').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'decPunt' })
|
||||||
|
await byLabel('Cambio Palla').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'cambiaPalla' })
|
||||||
|
await byLabel('Inverti').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'toggleOrder' })
|
||||||
|
await byLabel('Striscia').trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'toggleStriscia' })
|
||||||
|
expect(wrapper.vm.showCambiTeam).toBe(false)
|
||||||
|
const btnCambi = wrapper.findAll('.e-act').find(b => b.text() === 'Cambi')
|
||||||
|
await btnCambi.trigger('click')
|
||||||
|
expect(wrapper.vm.showCambiTeam).toBe(true)
|
||||||
|
wrapper.vm.showCambiTeam = false
|
||||||
|
await byLabel('Config').trigger('click')
|
||||||
|
expect(wrapper.vm.showConfig).toBe(true)
|
||||||
|
wrapper.vm.showConfig = false
|
||||||
|
await wrapper.find('.e-act--danger').trigger('click')
|
||||||
|
expect(wrapper.vm.confirmReset).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('il bottone Voce e il bottone Time Out della barra estesa funzionano', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.isLandscape = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
wrapper.vm.wsConnected = true
|
||||||
|
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
||||||
|
const wsSendSpy = vi.spyOn(wrapper.vm, 'sendWs')
|
||||||
|
const btnVoce = wrapper.findAll('.e-act').find(b => b.text() === 'Voce')
|
||||||
|
await btnVoce.trigger('click')
|
||||||
|
expect(wsSendSpy).toHaveBeenCalled()
|
||||||
|
|
||||||
|
const btnTimeout = wrapper.find('.e-act.btn-timeout')
|
||||||
|
await btnTimeout.trigger('click')
|
||||||
|
expect(wrapper.vm.showTimeoutModal).toBe(true)
|
||||||
|
wrapper.vm.showTimeoutModal = false
|
||||||
|
wrapper.vm.state.timeout = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
await btnTimeout.trigger('click')
|
||||||
|
expect(spy).toHaveBeenCalledWith({ type: 'stopTimeout' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// CHIUSURA DIALOG CLICCANDO FUORI (overlay self)
|
||||||
|
// =============================================
|
||||||
|
describe('Chiusura dialog cliccando fuori', () => {
|
||||||
|
it('conferma reset si chiude cliccando fuori dal dialog', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.confirmReset = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
await wrapper.find('.overlay').trigger('click')
|
||||||
|
expect(wrapper.vm.confirmReset).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('configurazione si chiude cliccando fuori dal dialog', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.showConfig = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
await wrapper.find('.overlay').trigger('click')
|
||||||
|
expect(wrapper.vm.showConfig).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('scelta squadra cambi si chiude cliccando fuori dal dialog', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.showCambiTeam = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
await wrapper.find('.overlay').trigger('click')
|
||||||
|
expect(wrapper.vm.showCambiTeam).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('la modal cambi si chiude cliccando fuori dal dialog', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.openCambi('home')
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
await wrapper.find('.overlay').trigger('click')
|
||||||
|
expect(wrapper.vm.showCambi).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('la modal time out si chiude cliccando fuori dal dialog', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
await wrapper.find('.btn-timeout').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await wrapper.find('.overlay').trigger('click')
|
||||||
|
expect(wrapper.vm.showTimeoutModal).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// DIALOG PARTITA FINITA / CONFIGURAZIONE: dettagli
|
||||||
|
// =============================================
|
||||||
|
describe('Dettagli dialog', () => {
|
||||||
|
it('CHIUDI chiude il dialog partita finita senza inviare action', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.state.modalitaPartita = '2/3'
|
||||||
|
wrapper.vm.state.sp.striscia = [
|
||||||
|
{ serv: 'h', ris: '', vinc: 'h' },
|
||||||
|
{ serv: 'h', ris: '', vinc: null },
|
||||||
|
]
|
||||||
|
wrapper.vm.setVintoTeam = 'home'
|
||||||
|
wrapper.vm.showSetVinto = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
const chiudi = wrapper.findAll('.btn-confirm').find(b => b.text() === 'CHIUDI')
|
||||||
|
await chiudi.trigger('click')
|
||||||
|
expect(spy).not.toHaveBeenCalled()
|
||||||
|
expect(wrapper.vm.showSetVinto).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('isPartitaFinita è false in modalità amichevole anche a set vinto', () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.state.modalitaPartita = 'amichevole'
|
||||||
|
wrapper.vm.setVintoTeam = 'home'
|
||||||
|
expect(wrapper.vm.isPartitaFinita).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('la vittoria della squadra guest apre comunque la modal SET VINTO', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
setScore(wrapper, 10, 25, 'g')
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.setVintoTeam).toBe('guest')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('nel set decisivo la soglia di vittoria scende a 15 punti', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
// 4 set già assegnati (2 a testa): il quinto è il set decisivo (3/5)
|
||||||
|
wrapper.vm.state.sp.striscia = [
|
||||||
|
{ serv: 'h', ris: '', vinc: 'h' },
|
||||||
|
{ serv: 'h', ris: '', vinc: 'g' },
|
||||||
|
{ serv: 'h', ris: '', vinc: 'h' },
|
||||||
|
{ serv: 'h', ris: '', vinc: 'g' },
|
||||||
|
{ serv: 'h', ris: '', vinc: null },
|
||||||
|
]
|
||||||
|
setScore(wrapper, 15, 10)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.setVintoTeam).toBe('home')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('i bottoni modalità 3/5 e amichevole aggiornano configData', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.showConfig = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const btn35 = wrapper.findAll('.btn-mode').find(b => b.text() === '3/5')
|
||||||
|
await btn35.trigger('click')
|
||||||
|
expect(wrapper.vm.configData.modalita).toBe('3/5')
|
||||||
|
const btnAmichevole = wrapper.findAll('.btn-mode').find(b => b.text() === 'Amichevole')
|
||||||
|
await btnAmichevole.trigger('click')
|
||||||
|
expect(wrapper.vm.configData.modalita).toBe('amichevole')
|
||||||
|
expect(btnAmichevole.classes()).toContain('active')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('i campi di testo di configurazione aggiornano configData tramite v-model', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.showConfig = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const inputs = wrapper.findAll('.dialog-config .input-field')
|
||||||
|
await inputs[0].setValue('Casa Nuova')
|
||||||
|
await inputs[1].setValue('Ospiti Nuovi')
|
||||||
|
expect(wrapper.vm.configData.nomeHome).toBe('Casa Nuova')
|
||||||
|
expect(wrapper.vm.configData.nomeGuest).toBe('Ospiti Nuovi')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('i campi numerici della formazione aggiornano configData tramite v-model', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.showConfig = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const numInputs = wrapper.findAll('.dialog-config .input-num')
|
||||||
|
// 6 campi per home + 6 per guest: li valorizziamo tutti per coprire ogni binding v-model
|
||||||
|
for (let i = 0; i < numInputs.length; i++) {
|
||||||
|
await numInputs[i].setValue(String(i))
|
||||||
|
}
|
||||||
|
// il DOM ordina le celle come 3,2,1 / 4,5,0: verifichiamo l'insieme dei valori digitati
|
||||||
|
expect(new Set(wrapper.vm.configData.formHome)).toEqual(new Set(['0', '1', '2', '3', '4', '5']))
|
||||||
|
expect(new Set(wrapper.vm.configData.formGuest)).toEqual(new Set(['6', '7', '8', '9', '10', '11']))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('la selezione squadra guest per i cambi apre la modal con cambiTeam=guest', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.showCambiTeam = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
await wrapper.find('.overlay .btn-set.guest-bg').trigger('click')
|
||||||
|
expect(wrapper.vm.cambiTeam).toBe('guest')
|
||||||
|
expect(wrapper.vm.showCambi).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('i campi IN/OUT della modal cambi aggiornano cambiData tramite v-model', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.openCambi('home')
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const inField = wrapper.find('.cambi-in-field')
|
||||||
|
const outField = wrapper.find('.cambi-out-field')
|
||||||
|
await inField.setValue('10')
|
||||||
|
await outField.setValue('1')
|
||||||
|
expect(wrapper.vm.cambiData[0]).toEqual({ in: '10', out: '1' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('nella modal time out si può selezionare un video dall\'elenco tramite radio', async () => {
|
||||||
|
fetchMock.mockResolvedValueOnce({ json: async () => ['a.mp4'] })
|
||||||
|
const wrapper = mountController()
|
||||||
|
await wrapper.find('.btn-timeout').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
const radios = wrapper.findAll('input[type=radio]')
|
||||||
|
await radios[0].setValue(true)
|
||||||
|
expect(wrapper.vm.timeoutVideoSel).toBe('a.mp4')
|
||||||
|
await radios[1].setValue(true)
|
||||||
|
expect(wrapper.vm.timeoutVideoSel).toBe(null)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Annulla nella modal time out la chiude senza avviarlo', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
await wrapper.find('.btn-timeout').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||||
|
await wrapper.find('.dialog-timeout .btn-cancel').trigger('click')
|
||||||
|
expect(spy).not.toHaveBeenCalled()
|
||||||
|
expect(wrapper.vm.showTimeoutModal).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
// BARRA CONNESSIONE
|
// BARRA CONNESSIONE
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|||||||
@@ -31,6 +31,15 @@ vi.stubGlobal('speechSynthesis', {
|
|||||||
getVoices: () => []
|
getVoices: () => []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// happy-dom non implementa la Web Speech API: stub minimo dell'utterance.
|
||||||
|
vi.stubGlobal('SpeechSynthesisUtterance', class {
|
||||||
|
constructor(text) {
|
||||||
|
this.text = text
|
||||||
|
this.voice = null
|
||||||
|
this.lang = ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// happy-dom non implementa la riproduzione media: stub di play/pause/load
|
// happy-dom non implementa la riproduzione media: stub di play/pause/load
|
||||||
// così l'overlay time out può montare il <video> senza errori.
|
// così l'overlay time out può montare il <video> senza errori.
|
||||||
Object.defineProperty(HTMLMediaElement.prototype, 'play', { value: vi.fn().mockResolvedValue(undefined), writable: true })
|
Object.defineProperty(HTMLMediaElement.prototype, 'play', { value: vi.fn().mockResolvedValue(undefined), writable: true })
|
||||||
@@ -257,6 +266,256 @@ describe('DisplayPage.vue', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// ORDINE GUEST/HOME CON FORMAZIONE
|
||||||
|
// =============================================
|
||||||
|
describe('Ordine guest/home con formazione visibile', () => {
|
||||||
|
it('order=false e visuForm=true mostra punteggio inline e formazioni nell\'ordine guest poi home', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
wrapper.vm.state.order = false
|
||||||
|
wrapper.vm.state.visuForm = true
|
||||||
|
wrapper.vm.state.sp.striscia.at(-1).ris = 'h'.repeat(3) + 'g'.repeat(2)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const scores = wrapper.findAll('.score-inline')
|
||||||
|
expect(scores[0].text()).toBe('2') // guest per primo
|
||||||
|
expect(scores[1].text()).toBe('3') // home per secondo
|
||||||
|
const formDivs = wrapper.findAll('.formdiv')
|
||||||
|
expect(formDivs).toHaveLength(12)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// MONTAGGIO: FULLSCREEN E TIME OUT GIÀ ATTIVO
|
||||||
|
// =============================================
|
||||||
|
describe('Comportamento al mount', () => {
|
||||||
|
it('su dispositivo mobile richiede la fullscreen', () => {
|
||||||
|
const uaSpy = vi.spyOn(navigator, 'userAgent', 'get').mockReturnValue('Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)')
|
||||||
|
const fsSpy = vi.fn()
|
||||||
|
document.documentElement.requestFullscreen = fsSpy
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
expect(fsSpy).toHaveBeenCalled()
|
||||||
|
wrapper.unmount()
|
||||||
|
uaSpy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('non richiede la fullscreen su desktop', () => {
|
||||||
|
const fsSpy = vi.fn()
|
||||||
|
document.documentElement.requestFullscreen = fsSpy
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
expect(fsSpy).not.toHaveBeenCalled()
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ignora l\'errore se requestFullscreen lancia un\'eccezione', () => {
|
||||||
|
const uaSpy = vi.spyOn(navigator, 'userAgent', 'get').mockReturnValue('Mozilla/5.0 (Linux; Android 10)')
|
||||||
|
document.documentElement.requestFullscreen = () => { throw new Error('non consentito') }
|
||||||
|
expect(() => mountDisplay()).not.toThrow()
|
||||||
|
uaSpy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('se il time out è già attivo al mount avvia subito la modalità time out', async () => {
|
||||||
|
const wrapper = mount(DisplayPage, {
|
||||||
|
global: { stubs: { 'w-app': true } },
|
||||||
|
data() {
|
||||||
|
const state = {
|
||||||
|
order: true, visuForm: false, visuStriscia: true,
|
||||||
|
timeout: true, timeoutTeam: 'home', timeoutVideo: null,
|
||||||
|
timeoutStartedAt: Date.now(), modalitaPartita: '3/5',
|
||||||
|
sp: {
|
||||||
|
striscia: [{ serv: 'h', ris: '', vinc: null }],
|
||||||
|
nomi: { home: 'Antoniana', guest: 'Guest' },
|
||||||
|
form: { home: ['1', '2', '3', '4', '5', '6'], guest: ['1', '2', '3', '4', '5', '6'] },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return { state }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.mostraPlaceholder).toBe(true)
|
||||||
|
expect(wrapper.find('.timeout-overlay').exists()).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// TICKER COUNTDOWN E CASI LIMITE
|
||||||
|
// =============================================
|
||||||
|
describe('Ticker del countdown', () => {
|
||||||
|
it('il ticker aggiorna nowTick periodicamente durante il time out', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
wrapper.vm.state.timeoutTeam = 'home'
|
||||||
|
wrapper.vm.state.timeoutStartedAt = Date.now()
|
||||||
|
wrapper.vm.state.timeout = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.timeoutRemaining).toBe(30)
|
||||||
|
vi.advanceTimersByTime(1000)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.timeoutRemaining).toBeLessThan(30)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('timeoutRemaining resta 30 se manca timeoutStartedAt', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
wrapper.vm.state.timeoutTeam = 'home'
|
||||||
|
wrapper.vm.state.timeoutStartedAt = null
|
||||||
|
wrapper.vm.state.timeout = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.timeoutRemaining).toBe(30)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('smontare il componente durante il time out ferma il ticker senza errori', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
wrapper.vm.state.timeoutTeam = 'home'
|
||||||
|
wrapper.vm.state.timeoutStartedAt = Date.now()
|
||||||
|
wrapper.vm.state.timeout = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(() => wrapper.unmount()).not.toThrow()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('stricciaStrip non fallisce se la striscia del set corrente è assente', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
wrapper.vm.state.sp.striscia = []
|
||||||
|
expect(wrapper.vm.stricciaStrip).toEqual({ home: [], guest: [] })
|
||||||
|
// ripristina uno stato valido prima che Vue ricalcoli gli altri computed (punt/servHome)
|
||||||
|
wrapper.vm.state.sp.striscia = [{ serv: 'h', ris: '', vinc: null }]
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// FINE TIME OUT: STOP VIDEO E FALLBACK MUTO
|
||||||
|
// =============================================
|
||||||
|
describe('Stop del time out e riproduzione video', () => {
|
||||||
|
async function attivaTimeout(wrapper, { team = 'home', video = null, startedAt = Date.now() } = {}) {
|
||||||
|
wrapper.vm.state.timeoutTeam = team
|
||||||
|
wrapper.vm.state.timeoutVideo = video
|
||||||
|
wrapper.vm.state.timeoutStartedAt = startedAt
|
||||||
|
wrapper.vm.state.timeout = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
}
|
||||||
|
|
||||||
|
it('allo stop del time out con video in corso mette in pausa e resetta il video', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
await attivaTimeout(wrapper, { video: 'a.mp4' })
|
||||||
|
const video = wrapper.find('.timeout-video').element
|
||||||
|
const pauseSpy = vi.spyOn(video, 'pause')
|
||||||
|
wrapper.vm.state.timeout = false
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(pauseSpy).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a metà riproduzione si riallinea al punto corretto (riconnessione)', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
await attivaTimeout(wrapper, { video: 'a.mp4', startedAt: Date.now() - 10000 })
|
||||||
|
const video = wrapper.find('.timeout-video').element
|
||||||
|
Object.defineProperty(video, 'duration', { value: 60, configurable: true })
|
||||||
|
video.onloadedmetadata()
|
||||||
|
expect(video.currentTime).toBeCloseTo(10, 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('senza timeoutStartedAt non tenta alcun riallineamento (trascorsi=0)', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
await attivaTimeout(wrapper, { video: 'a.mp4', startedAt: null })
|
||||||
|
const video = wrapper.find('.timeout-video').element
|
||||||
|
Object.defineProperty(video, 'duration', { value: 60, configurable: true })
|
||||||
|
video.currentTime = 0
|
||||||
|
video.onloadedmetadata()
|
||||||
|
expect(video.currentTime).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('non si riallinea se il tempo trascorso supera la durata del video', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
await attivaTimeout(wrapper, { video: 'a.mp4', startedAt: Date.now() - 10000 })
|
||||||
|
const video = wrapper.find('.timeout-video').element
|
||||||
|
Object.defineProperty(video, 'duration', { value: 5, configurable: true })
|
||||||
|
video.currentTime = 0
|
||||||
|
video.onloadedmetadata()
|
||||||
|
expect(video.currentTime).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('caricaSpotCorrente non fa nulla se manca il ref del video o il video del time out', () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
// nessun overlay attivo: $refs.spotVideo non esiste
|
||||||
|
expect(() => wrapper.vm.caricaSpotCorrente()).not.toThrow()
|
||||||
|
expect(wrapper.vm.spotVideoDuration).toBe(null)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('playSpot non fa nulla se manca il ref del video', () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
expect(() => wrapper.vm.playSpot()).not.toThrow()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('se l\'autoplay con audio viene bloccato ripiega sul muto', async () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
HTMLMediaElement.prototype.play = vi.fn()
|
||||||
|
.mockRejectedValueOnce(new Error('autoplay bloccato'))
|
||||||
|
.mockResolvedValueOnce(undefined)
|
||||||
|
await attivaTimeout(wrapper, { video: 'a.mp4' })
|
||||||
|
const video = wrapper.find('.timeout-video').element
|
||||||
|
await Promise.resolve()
|
||||||
|
await Promise.resolve()
|
||||||
|
expect(video.muted).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// MESSAGGI WEBSOCKET E SINTESI VOCALE
|
||||||
|
// =============================================
|
||||||
|
describe('onWsMessage e sintesi vocale', () => {
|
||||||
|
it('un messaggio "speak" avvia la sintesi vocale con il testo ricevuto', () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
wrapper.vm.onWsMessage({ type: 'speak', text: '15 a 10' })
|
||||||
|
expect(window.speechSynthesis.cancel).toHaveBeenCalled()
|
||||||
|
expect(window.speechSynthesis.speak).toHaveBeenCalled()
|
||||||
|
const utterance = window.speechSynthesis.speak.mock.calls.at(-1)[0]
|
||||||
|
expect(utterance.text).toBe('15 a 10')
|
||||||
|
expect(utterance.lang).toBe('it-IT')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('un messaggio "error" viene loggato in console', () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||||
|
wrapper.vm.onWsMessage({ type: 'error', message: 'boom' })
|
||||||
|
expect(spy).toHaveBeenCalledWith('[Display] Server error:', 'boom')
|
||||||
|
spy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ignora testo vuoto o non stringa nella sintesi vocale', () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
window.speechSynthesis.speak.mockClear()
|
||||||
|
wrapper.vm.speakOnDisplay(' ')
|
||||||
|
wrapper.vm.speakOnDisplay(42)
|
||||||
|
expect(window.speechSynthesis.speak).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sceglie la voce "Google italiano" quando disponibile', () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
const vIt = { name: 'voce it generica', lang: 'it-IT' }
|
||||||
|
const vGoogle = { name: 'Google italiano', lang: 'it-IT' }
|
||||||
|
window.speechSynthesis.getVoices = () => [vIt, vGoogle]
|
||||||
|
wrapper.vm.speakOnDisplay('prova')
|
||||||
|
const utterance = window.speechSynthesis.speak.mock.calls.at(-1)[0]
|
||||||
|
expect(utterance.voice).toBe(vGoogle)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ripiega su una voce con lingua "it" se manca "Google italiano"', () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
const vIt = { name: 'voce italiana', lang: 'it-IT' }
|
||||||
|
const vEn = { name: 'english voice', lang: 'en-US' }
|
||||||
|
window.speechSynthesis.getVoices = () => [vEn, vIt]
|
||||||
|
wrapper.vm.speakOnDisplay('prova')
|
||||||
|
const utterance = window.speechSynthesis.speak.mock.calls.at(-1)[0]
|
||||||
|
expect(utterance.voice).toBe(vIt)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('usa voice=null se nessuna voce italiana è disponibile', () => {
|
||||||
|
const wrapper = mountDisplay()
|
||||||
|
window.speechSynthesis.getVoices = () => [{ name: 'english voice', lang: 'en-US' }]
|
||||||
|
wrapper.vm.speakOnDisplay('prova')
|
||||||
|
const utterance = window.speechSynthesis.speak.mock.calls.at(-1)[0]
|
||||||
|
expect(utterance.voice).toBe(null)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
// ICONA SERVIZIO
|
// ICONA SERVIZIO
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|||||||
Reference in New Issue
Block a user