Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ffba5b368d | |||
| 1ab57654ad | |||
| c73267d347 | |||
| 5b5dddf2e8 | |||
| e6099be0cb | |||
| d67f3669d6 | |||
| eb37f8319f | |||
| ddf68010a4 | |||
| e212fb4654 | |||
| c7d0ec6215 | |||
| 7e6d51ce58 | |||
| 854669d603 |
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"enabledPlugins": {
|
"enabledPlugins": {
|
||||||
"claude-md-management@claude-plugins-official": true,
|
"claude-md-management@claude-plugins-official": true,
|
||||||
"code-simplifier@claude-plugins-official": true
|
"code-simplifier@claude-plugins-official": true,
|
||||||
|
"frontend-design@claude-plugins-official": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,14 +32,23 @@ Display (Vue) ──WebSocket──┤── websocket-handler.js ── gam
|
|||||||
│ └── persist.js ── .segnapunti/state.json
|
│ └── persist.js ── .segnapunti/state.json
|
||||||
```
|
```
|
||||||
|
|
||||||
**Tutta la logica di gioco** è in `src/gameState.js` come tre funzioni pure esportate:
|
**Tutta la logica di gioco** è in `src/gameState.js` come funzioni pure esportate:
|
||||||
- `createInitialState()` — restituisce lo stato iniziale
|
- `createInitialState()` — restituisce lo stato iniziale
|
||||||
- `applyAction(state, action)` — reducer immutabile (deep-clone via `structuredClone`)
|
- `applyAction(state, action)` — reducer immutabile (deep-clone via `structuredClone`)
|
||||||
- `checkVittoria(state)` — condizioni di vittoria set (25 punti, vantaggio di 2; 15 punti nel set decisivo)
|
- `checkVittoria(state)` — condizioni di vittoria set (25 punti, vantaggio di 2; 15 punti nel set decisivo)
|
||||||
|
- `punteggio` / `setVinti` / `servizio` — derivano punteggio corrente, set vinti e chi serve dalla `striscia` (lo stato NON memorizza questi valori direttamente)
|
||||||
|
|
||||||
|
Punteggio, set e servizio si ricavano sempre dalla `striscia`: al primo punto di ogni set `applyAction('incPunt')` salva in `formInizio` uno snapshot della formazione di partenza (usato dal referto); `decPunt` lo rimuove se il set torna a 0-0.
|
||||||
|
|
||||||
`src/websocket-handler.js` riceve i messaggi WebSocket, valida che il mittente sia un `controller` (non un `display`), chiama `applyAction`, fa il broadcast del nuovo stato a tutti i client, poi invoca `onStateChange` per persistere su disco.
|
`src/websocket-handler.js` riceve i messaggi WebSocket, valida che il mittente sia un `controller` (non un `display`), chiama `applyAction`, fa il broadcast del nuovo stato a tutti i client, poi invoca `onStateChange` per persistere su disco.
|
||||||
|
|
||||||
`server.js` (Express) serve entrambe le interfacce sulla porta 3000: `/display` → `dist/index.html`, `/controller` → `dist/controller.html`. Singolo endpoint WebSocket su `/ws`.
|
`src/wsMixin.js` è il mixin Vue lato client: gestisce connessione/riconnessione WebSocket (backoff esponenziale) ed espone i computed `punt`/`servHome`/`set`.
|
||||||
|
|
||||||
|
`src/referto.js` genera il referto di gara: `buildRefertoHtml(state, now)` è una funzione pura che restituisce l'HTML (testabile), mentre `generaReferto(state)` è il wrapper che apre la finestra con `window.open` e avvia la stampa.
|
||||||
|
|
||||||
|
`src/persist.js` carica/salva lo stato su `.segnapunti/state.json`. `src/server-utils.js` ricava gli IP di rete (`getNetworkIPs`, con sorgente iniettabile) e stampa gli URL all'avvio.
|
||||||
|
|
||||||
|
`server.js` (Express) espone `createApp(distDir)` (solo routing, testabile) e `startServer(port)` (HTTP + WebSocket); serve entrambe le interfacce sulla porta 3000: `/display` → `dist/index.html`, `/controller` → `dist/controller.html`. Singolo endpoint WebSocket su `/ws`. L'avvio automatico parte solo se il file è eseguito come entrypoint.
|
||||||
|
|
||||||
In sviluppo, `vite-plugin-websocket.js` incorpora il server WebSocket dentro il dev server Vite con middleware di URL rewrite per `/display` e `/controller`.
|
In sviluppo, `vite-plugin-websocket.js` incorpora il server WebSocket dentro il dev server Vite con middleware di URL rewrite per `/display` e `/controller`.
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ http://<IP-del-server>:3000/controller
|
|||||||
- **Visualizzazione** — alterna tra punteggio grande e formazioni in campo
|
- **Visualizzazione** — alterna tra punteggio grande e formazioni in campo
|
||||||
- **Striscia** — mostra/nasconde lo storico punti sul display
|
- **Striscia** — mostra/nasconde lo storico punti sul display
|
||||||
- **Reset** — azzera la partita (richiede conferma)
|
- **Reset** — azzera la partita (richiede conferma)
|
||||||
|
- **Referto** — a fine partita, dal dialog *PARTITA FINITA*, genera un referto di gara stampabile/PDF (punteggi per set, formazioni di partenza, andamento punto-punto). *Funzione prototipale.*
|
||||||
|
|
||||||
### Regole pallavolo integrate
|
### Regole pallavolo integrate
|
||||||
|
|
||||||
@@ -181,8 +182,13 @@ Lo stato viene salvato in `.segnapunti/state.json` anche in modalità dev.
|
|||||||
| `npm run test:component` | Componenti Vue (Happy-DOM) |
|
| `npm run test:component` | Componenti Vue (Happy-DOM) |
|
||||||
| `npm run test:stress` | Load test WebSocket (50+ client) |
|
| `npm run test:stress` | Load test WebSocket (50+ client) |
|
||||||
| `npm run test:all` | Tutti i test tranne E2E |
|
| `npm run test:all` | Tutti i test tranne E2E |
|
||||||
|
| `npm run test:ui` | Vitest con interfaccia grafica |
|
||||||
| `npm run test:e2e` | Playwright — Chromium, Firefox, Mobile Chrome |
|
| `npm run test:e2e` | Playwright — Chromium, Firefox, Mobile Chrome |
|
||||||
|
|
||||||
|
Le suite Vitest coprono la logica di gioco (`gameState`, inclusa `formInizio`),
|
||||||
|
il protocollo e il routing del server, la persistenza, il client WebSocket
|
||||||
|
(`wsMixin`), i componenti Vue e la generazione del referto.
|
||||||
|
|
||||||
> I test E2E richiedono il server in esecuzione (`npm run serve`) e i browser Playwright installati:
|
> I test E2E richiedono il server in esecuzione (`npm run serve`) e i browser Playwright installati:
|
||||||
> ```bash
|
> ```bash
|
||||||
> npx playwright install chromium firefox
|
> npx playwright install chromium firefox
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createServer } from 'http'
|
import { createServer } from 'http'
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { WebSocketServer } from 'ws'
|
import { WebSocketServer } from 'ws'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath, pathToFileURL } from 'url'
|
||||||
import { dirname, join } from 'path'
|
import { dirname, join } from 'path'
|
||||||
import { setupWebSocketHandler } from './src/websocket-handler.js'
|
import { setupWebSocketHandler } from './src/websocket-handler.js'
|
||||||
import { printServerInfo } from './src/server-utils.js'
|
import { printServerInfo } from './src/server-utils.js'
|
||||||
@@ -10,36 +10,52 @@ import { loadState, saveState } from './src/persist.js'
|
|||||||
const __filename = fileURLToPath(import.meta.url)
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
const __dirname = dirname(__filename)
|
const __dirname = dirname(__filename)
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000
|
const DIST_DIR = join(__dirname, 'dist')
|
||||||
const distDir = join(__dirname, 'dist')
|
|
||||||
|
|
||||||
const app = express()
|
// Crea l'app Express (asset statici + route display/controller) senza avviare il
|
||||||
|
// listen né il WebSocket: così il routing è testabile in isolamento.
|
||||||
|
export function createApp(distDir = DIST_DIR) {
|
||||||
|
const app = express()
|
||||||
|
|
||||||
app.use(express.static(distDir, { index: false }))
|
app.use(express.static(distDir, { index: false }))
|
||||||
|
|
||||||
app.get(['/', '/display', '/display/*splat'], (_req, res) => {
|
app.get(['/', '/display', '/display/*splat'], (_req, res) => {
|
||||||
res.sendFile(join(distDir, 'index.html'))
|
res.sendFile(join(distDir, 'index.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get(['/controller', '/controller/*splat'], (_req, res) => {
|
app.get(['/controller', '/controller/*splat'], (_req, res) => {
|
||||||
res.sendFile(join(distDir, 'controller.html'))
|
res.sendFile(join(distDir, 'controller.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
const server = createServer(app)
|
return app
|
||||||
const wss = new WebSocketServer({ noServer: true })
|
}
|
||||||
setupWebSocketHandler(wss, { initialState: loadState(), onStateChange: saveState })
|
|
||||||
|
|
||||||
server.on('upgrade', (request, socket, head) => {
|
// Avvia HTTP + WebSocket. Lo stato viene caricato da disco e ripersistito ad ogni azione.
|
||||||
const pathname = new URL(request.url, `http://${request.headers.host}`).pathname
|
export function startServer(port = process.env.PORT || 3000) {
|
||||||
if (pathname === '/ws') {
|
const app = createApp()
|
||||||
wss.handleUpgrade(request, socket, head, (ws) => {
|
const server = createServer(app)
|
||||||
wss.emit('connection', ws, request)
|
const wss = new WebSocketServer({ noServer: true })
|
||||||
})
|
setupWebSocketHandler(wss, { initialState: loadState(), onStateChange: saveState })
|
||||||
} else {
|
|
||||||
socket.destroy()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
server.listen(PORT, '0.0.0.0', () => {
|
server.on('upgrade', (request, socket, head) => {
|
||||||
printServerInfo(PORT)
|
const pathname = new URL(request.url, `http://${request.headers.host}`).pathname
|
||||||
})
|
if (pathname === '/ws') {
|
||||||
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
||||||
|
wss.emit('connection', ws, request)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
socket.destroy()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
server.listen(port, '0.0.0.0', () => {
|
||||||
|
printServerInfo(port)
|
||||||
|
})
|
||||||
|
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
|
// Avvia solo se eseguito direttamente (`node server.js`), non quando importato nei test.
|
||||||
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||||
|
startServer()
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,66 +6,147 @@
|
|||||||
{{ wsConnected ? 'Connesso' : 'Connessione...' }}
|
{{ wsConnected ? 'Connesso' : 'Connessione...' }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Anteprima punteggio -->
|
<!-- ══════════════════ MODALITÀ MOBILE ══════════════════ -->
|
||||||
<div class="score-preview">
|
<template v-if="!isEstesa">
|
||||||
<div class="team-score home-bg" @click="sendAction({ type: 'incPunt', team: 'home' })">
|
<!-- Anteprima punteggio -->
|
||||||
<div class="team-name">{{ state.sp.nomi.home }}</div>
|
<div class="score-preview">
|
||||||
<div class="team-pts">{{ punt.home }}</div>
|
<div class="team-score" :class="primaSquadra + '-bg'" @click="sendAction({ type: 'incPunt', team: primaSquadra })">
|
||||||
<div class="team-set">SET {{ set.home }}</div>
|
<div class="team-name">{{ state.sp.nomi[primaSquadra] }}</div>
|
||||||
<img v-show="servHome" src="/serv.png" class="serv-icon" alt="Servizio" />
|
<div class="team-pts">{{ punt[primaSquadra] }}</div>
|
||||||
|
<div class="team-set">SET {{ set[primaSquadra] }}</div>
|
||||||
|
<img v-show="primaSquadra === 'home' ? servHome : !servHome" src="/serv.png" class="serv-icon" alt="Servizio" />
|
||||||
|
</div>
|
||||||
|
<div class="team-score" :class="secondaSquadra + '-bg'" @click="sendAction({ type: 'incPunt', team: secondaSquadra })">
|
||||||
|
<div class="team-name">{{ state.sp.nomi[secondaSquadra] }}</div>
|
||||||
|
<div class="team-pts">{{ punt[secondaSquadra] }}</div>
|
||||||
|
<div class="team-set">SET {{ set[secondaSquadra] }}</div>
|
||||||
|
<img v-show="secondaSquadra === 'home' ? servHome : !servHome" src="/serv.png" class="serv-icon" alt="Servizio" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="team-score guest-bg" @click="sendAction({ type: 'incPunt', team: 'guest' })">
|
|
||||||
<div class="team-name">{{ state.sp.nomi.guest }}</div>
|
<!-- Riga annulla punto -->
|
||||||
<div class="team-pts">{{ punt.guest }}</div>
|
<div class="undo-row">
|
||||||
<div class="team-set">SET {{ set.guest }}</div>
|
<button class="btn btn-undo" @click="sendAction({ type: 'decPunt' })">
|
||||||
<img v-show="!servHome" src="/serv.png" class="serv-icon" alt="Servizio" />
|
ANNULLA PUNTO
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pulsanti set -->
|
||||||
|
<div class="action-row">
|
||||||
|
<button class="btn btn-set home-bg" @click="sendAction({ type: 'incSet', team: 'home' })">
|
||||||
|
SET {{ state.sp.nomi.home }}
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-set guest-bg" @click="sendAction({ type: 'incSet', team: 'guest' })">
|
||||||
|
SET {{ state.sp.nomi.guest }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Controlli principali -->
|
||||||
|
<div class="controls">
|
||||||
|
<button class="btn btn-ctrl" @click="sendAction({ type: 'cambiaPalla' })" :disabled="!isPunteggioZeroZero">
|
||||||
|
Cambio Palla
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-ctrl" @click="sendAction({ type: 'toggleFormazione' })">
|
||||||
|
{{ state.visuForm ? 'Punteggio' : 'Formazioni' }}
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-ctrl" @click="sendAction({ type: 'toggleStriscia' })">
|
||||||
|
Striscia {{ state.visuStriscia ? 'ON' : 'OFF' }}
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-ctrl" @click="sendAction({ type: 'toggleOrder' })">
|
||||||
|
Inverti
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-ctrl" @click="speak()">
|
||||||
|
Voce
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-ctrl" @click="openConfig()">
|
||||||
|
Config
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-ctrl" @click="openCambiTeam()">
|
||||||
|
Cambi
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-danger" @click="confirmReset = true">
|
||||||
|
Reset
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- ══════════════════ MODALITÀ ESTESA ══════════════════ -->
|
||||||
|
<div v-else class="e-dash" @wheel.prevent @touchmove.prevent>
|
||||||
|
<div class="e-panels">
|
||||||
|
|
||||||
|
<!-- Prima squadra -->
|
||||||
|
<div class="e-panel" :class="primaSquadra === 'home' ? 'e-panel--home' : 'e-panel--guest'">
|
||||||
|
<div class="e-panel__stripe"></div>
|
||||||
|
<div class="e-panel__body">
|
||||||
|
<header class="e-panel__head">
|
||||||
|
<span class="e-panel__name">{{ state.sp.nomi[primaSquadra] }}</span>
|
||||||
|
<span class="e-panel__meta">
|
||||||
|
<img v-show="primaSquadra === 'home' ? servHome : !servHome" src="/serv.png" class="e-panel__serv" />
|
||||||
|
{{ set[primaSquadra] }} <span class="e-label">SET</span>
|
||||||
|
</span>
|
||||||
|
</header>
|
||||||
|
<div class="e-panel__score" @click="sendAction({ type: 'incPunt', team: primaSquadra })">
|
||||||
|
{{ punt[primaSquadra] }}
|
||||||
|
</div>
|
||||||
|
<div class="e-panel__court">
|
||||||
|
<div class="e-court__row">
|
||||||
|
<div v-for="x in [3,2,1]" :key="'pf1'+x" class="e-court__cell">{{ state.sp.form[primaSquadra][x] }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="e-court__net"></div>
|
||||||
|
<div class="e-court__row">
|
||||||
|
<div v-for="x in [4,5,0]" :key="'pf2'+x" class="e-court__cell">{{ state.sp.form[primaSquadra][x] }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="btn e-panel__setbtn" @click="sendAction({ type: 'incSet', team: primaSquadra })">
|
||||||
|
SET {{ state.sp.nomi[primaSquadra] }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Seconda squadra -->
|
||||||
|
<div class="e-panel" :class="secondaSquadra === 'home' ? 'e-panel--home' : 'e-panel--guest'">
|
||||||
|
<div class="e-panel__stripe"></div>
|
||||||
|
<div class="e-panel__body">
|
||||||
|
<header class="e-panel__head">
|
||||||
|
<span class="e-panel__name">{{ state.sp.nomi[secondaSquadra] }}</span>
|
||||||
|
<span class="e-panel__meta">
|
||||||
|
<img v-show="secondaSquadra === 'home' ? servHome : !servHome" src="/serv.png" class="e-panel__serv" />
|
||||||
|
{{ set[secondaSquadra] }} <span class="e-label">SET</span>
|
||||||
|
</span>
|
||||||
|
</header>
|
||||||
|
<div class="e-panel__score" @click="sendAction({ type: 'incPunt', team: secondaSquadra })">
|
||||||
|
{{ punt[secondaSquadra] }}
|
||||||
|
</div>
|
||||||
|
<div class="e-panel__court">
|
||||||
|
<div class="e-court__row">
|
||||||
|
<div v-for="x in [3,2,1]" :key="'sf1'+x" class="e-court__cell">{{ state.sp.form[secondaSquadra][x] }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="e-court__net"></div>
|
||||||
|
<div class="e-court__row">
|
||||||
|
<div v-for="x in [4,5,0]" :key="'sf2'+x" class="e-court__cell">{{ state.sp.form[secondaSquadra][x] }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="btn e-panel__setbtn" @click="sendAction({ type: 'incSet', team: secondaSquadra })">
|
||||||
|
SET {{ state.sp.nomi[secondaSquadra] }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Barra azioni secondarie -->
|
||||||
|
<div class="e-actions">
|
||||||
|
<button class="btn e-act e-act--undo" @click="sendAction({ type: 'decPunt' })">↩ Annulla</button>
|
||||||
|
<button class="btn e-act" :disabled="!isPunteggioZeroZero" @click="sendAction({ type: 'cambiaPalla' })">Cambio Palla</button>
|
||||||
|
<button class="btn e-act" @click="openCambiTeam()">Cambi</button>
|
||||||
|
<button class="btn e-act" @click="sendAction({ type: 'toggleOrder' })">Inverti</button>
|
||||||
|
<button class="btn e-act" @click="sendAction({ type: 'toggleStriscia' })">Striscia {{ state.visuStriscia ? 'ON' : 'OFF' }}</button>
|
||||||
|
<button class="btn e-act" @click="speak()">Voce</button>
|
||||||
|
<button class="btn e-act" @click="openConfig()">Config</button>
|
||||||
|
<button class="btn e-act e-act--danger" @click="confirmReset = true">Reset</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Riga annulla punto -->
|
<!-- ══════════════════ DIALOGS (condivisi) ══════════════════ -->
|
||||||
<div class="undo-row">
|
|
||||||
<button class="btn btn-undo" @click="sendAction({ type: 'decPunt' })">
|
|
||||||
ANNULLA PUNTO
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Pulsanti set -->
|
|
||||||
<div class="action-row">
|
|
||||||
<button class="btn btn-set home-bg" @click="sendAction({ type: 'incSet', team: 'home' })">
|
|
||||||
SET {{ state.sp.nomi.home }}
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-set guest-bg" @click="sendAction({ type: 'incSet', team: 'guest' })">
|
|
||||||
SET {{ state.sp.nomi.guest }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Controlli principali -->
|
|
||||||
<div class="controls">
|
|
||||||
<button class="btn btn-ctrl" @click="sendAction({ type: 'cambiaPalla' })" :disabled="!isPunteggioZeroZero">
|
|
||||||
Cambio Palla
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ctrl" @click="sendAction({ type: 'toggleFormazione' })">
|
|
||||||
{{ state.visuForm ? 'Punteggio' : 'Formazioni' }}
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ctrl" @click="sendAction({ type: 'toggleStriscia' })">
|
|
||||||
Striscia
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ctrl" @click="sendAction({ type: 'toggleOrder' })">
|
|
||||||
Inverti
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ctrl" @click="speak()">
|
|
||||||
Voce
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ctrl" @click="openConfig()">
|
|
||||||
Config
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-ctrl" @click="openCambiTeam()">
|
|
||||||
Cambi
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-danger" @click="confirmReset = true">
|
|
||||||
Reset
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Finestra conferma reset -->
|
<!-- Finestra conferma reset -->
|
||||||
<div class="overlay" v-if="confirmReset" @click.self="confirmReset = false">
|
<div class="overlay" v-if="confirmReset" @click.self="confirmReset = false">
|
||||||
@@ -86,6 +167,7 @@
|
|||||||
<div class="dialog-subtitle" v-if="!isPartitaFinita">Configura le formazioni per il prossimo set</div>
|
<div class="dialog-subtitle" v-if="!isPartitaFinita">Configura le formazioni per il prossimo set</div>
|
||||||
<div class="dialog-buttons">
|
<div class="dialog-buttons">
|
||||||
<button class="btn btn-cancel" @click="undoUltimoPoint()">INDIETRO</button>
|
<button class="btn btn-cancel" @click="undoUltimoPoint()">INDIETRO</button>
|
||||||
|
<button v-if="isPartitaFinita" class="btn btn-secondary" @click="generaReferto(state)">REFERTO</button>
|
||||||
<button v-if="isPartitaFinita" class="btn btn-confirm" @click="showSetVinto = false">CHIUDI</button>
|
<button v-if="isPartitaFinita" class="btn btn-confirm" @click="showSetVinto = false">CHIUDI</button>
|
||||||
<button v-else class="btn btn-confirm" @click="doNuovoSet()">VAI AL SET SUCCESSIVO</button>
|
<button v-else class="btn btn-confirm" @click="doNuovoSet()">VAI AL SET SUCCESSIVO</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -193,6 +275,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { createWsMixin } from '../wsMixin.js'
|
import { createWsMixin } from '../wsMixin.js'
|
||||||
|
import { generaReferto } from '../referto.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ControllerPage",
|
name: "ControllerPage",
|
||||||
@@ -213,9 +296,13 @@ export default {
|
|||||||
formHome: ["1", "2", "3", "4", "5", "6"],
|
formHome: ["1", "2", "3", "4", "5", "6"],
|
||||||
formGuest: ["1", "2", "3", "4", "5", "6"],
|
formGuest: ["1", "2", "3", "4", "5", "6"],
|
||||||
},
|
},
|
||||||
|
isLandscape: window.innerWidth > window.innerHeight,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
isEstesa() { return this.isLandscape },
|
||||||
|
primaSquadra() { return this.state.order ? 'home' : 'guest' },
|
||||||
|
secondaSquadra() { return this.state.order ? 'guest' : 'home' },
|
||||||
isPunteggioZeroZero() {
|
isPunteggioZeroZero() {
|
||||||
return this.state.sp.striscia.at(-1).ris === ''
|
return this.state.sp.striscia.at(-1).ris === ''
|
||||||
},
|
},
|
||||||
@@ -253,7 +340,17 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
this._resizeHandler = () => { this.isLandscape = window.innerWidth > window.innerHeight }
|
||||||
|
window.addEventListener('resize', this._resizeHandler)
|
||||||
|
window.addEventListener('orientationchange', this._resizeHandler)
|
||||||
|
},
|
||||||
|
beforeUnmount() {
|
||||||
|
window.removeEventListener('resize', this._resizeHandler)
|
||||||
|
window.removeEventListener('orientationchange', this._resizeHandler)
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
generaReferto,
|
||||||
onWsMessage(msg) {
|
onWsMessage(msg) {
|
||||||
if (msg.type === 'error') this.showErrorFeedback(msg.message)
|
if (msg.type === 'error') this.showErrorFeedback(msg.message)
|
||||||
},
|
},
|
||||||
@@ -368,6 +465,7 @@ export default {
|
|||||||
font-family: 'Inter', system-ui, sans-serif;
|
font-family: 'Inter', system-ui, sans-serif;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Barra stato connessione */
|
/* Barra stato connessione */
|
||||||
@@ -398,7 +496,8 @@ export default {
|
|||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Anteprima punteggio */
|
/* ── MODALITÀ MOBILE ── */
|
||||||
|
|
||||||
.score-preview {
|
.score-preview {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
@@ -407,47 +506,52 @@ export default {
|
|||||||
.team-score {
|
.team-score {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
padding: 16px 12px;
|
background: #161618;
|
||||||
|
border: 1px solid rgba(255,255,255,0.07);
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 14px 12px 14px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
position: relative;
|
position: relative;
|
||||||
transition: transform 0.1s;
|
transition: transform 0.1s;
|
||||||
min-height: 120px;
|
min-height: 110px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
.team-score:active {
|
.team-score::before {
|
||||||
transform: scale(0.97);
|
content: '';
|
||||||
}
|
position: absolute;
|
||||||
.home-bg {
|
top: 0; left: 0; right: 0;
|
||||||
background: linear-gradient(145deg, #1a1a1a, #333);
|
height: 4px;
|
||||||
border: 2px solid #fdd835;
|
|
||||||
color: #fdd835;
|
|
||||||
}
|
|
||||||
.guest-bg {
|
|
||||||
background: linear-gradient(145deg, #0d47a1, #1565c0);
|
|
||||||
border: 2px solid #64b5f6;
|
|
||||||
color: #fff;
|
|
||||||
}
|
}
|
||||||
|
.team-score:active { transform: scale(0.97); }
|
||||||
|
|
||||||
|
/* stripe colorata come nella versione estesa */
|
||||||
|
.home-bg::before { background: #f5c518; }
|
||||||
|
.guest-bg::before { background: #2196f3; }
|
||||||
|
|
||||||
.team-name {
|
.team-name {
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
font-weight: 700;
|
font-weight: 900;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 1px;
|
letter-spacing: 1.5px;
|
||||||
|
color: #f0f0f0;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
.team-pts {
|
.team-pts {
|
||||||
font-size: 56px;
|
font-size: 54px;
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
.home-bg .team-pts { color: #f5c518; }
|
||||||
|
.guest-bg .team-pts { color: #2196f3; }
|
||||||
.team-set {
|
.team-set {
|
||||||
font-size: 13px;
|
font-size: 11px;
|
||||||
font-weight: 600;
|
font-weight: 700;
|
||||||
opacity: 0.75;
|
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
|
color: #888;
|
||||||
}
|
}
|
||||||
.serv-icon {
|
.serv-icon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -457,26 +561,22 @@ export default {
|
|||||||
height: 20px;
|
height: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Riga annulla punto */
|
|
||||||
.undo-row {
|
.undo-row {
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
.btn-undo {
|
.btn-undo {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: rgba(255,255,255,0.08);
|
background: rgba(255,255,255,0.07);
|
||||||
border: 1px solid rgba(255,255,255,0.2);
|
border: 1px solid rgba(255,171,145,0.2);
|
||||||
color: #ffab91;
|
color: #ffab91;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
border-radius: 12px;
|
border-radius: 10px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.btn-undo:active {
|
.btn-undo:active { background: rgba(255,100,50,0.2); }
|
||||||
background: rgba(255,100,50,0.2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Pulsanti set */
|
|
||||||
.action-row {
|
.action-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
@@ -484,19 +584,20 @@ export default {
|
|||||||
}
|
}
|
||||||
.btn-set {
|
.btn-set {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 12px;
|
padding: 11px;
|
||||||
font-size: 13px;
|
font-size: 11px;
|
||||||
font-weight: 700;
|
font-weight: 800;
|
||||||
border-radius: 12px;
|
letter-spacing: 1.2px;
|
||||||
|
border-radius: 10px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border: none;
|
border: none;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
|
transition: opacity 0.1s;
|
||||||
}
|
}
|
||||||
.btn-set:active {
|
.btn-set:active { transform: scale(0.97); opacity: 0.8; }
|
||||||
transform: scale(0.97);
|
.btn-set.home-bg { background: #f5c518; color: #111; }
|
||||||
}
|
.btn-set.guest-bg { background: #2196f3; color: #fff; }
|
||||||
|
|
||||||
/* Griglia controlli */
|
|
||||||
.controls {
|
.controls {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(2, 1fr);
|
grid-template-columns: repeat(2, 1fr);
|
||||||
@@ -511,36 +612,218 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn-ctrl {
|
.btn-ctrl {
|
||||||
background: rgba(255,255,255,0.08);
|
background: rgba(255,255,255,0.07);
|
||||||
border: 1px solid rgba(255,255,255,0.15);
|
border: 1px solid rgba(255,255,255,0.1);
|
||||||
color: #e0e0e0;
|
color: #bbb;
|
||||||
padding: 14px 8px;
|
padding: 14px 8px;
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
border-radius: 12px;
|
border-radius: 10px;
|
||||||
transition: background 0.15s;
|
transition: background 0.12s;
|
||||||
}
|
|
||||||
.btn-ctrl:active {
|
|
||||||
background: rgba(255,255,255,0.18);
|
|
||||||
}
|
|
||||||
.btn-ctrl:disabled {
|
|
||||||
opacity: 0.35;
|
|
||||||
}
|
}
|
||||||
|
.btn-ctrl:active { background: rgba(255,255,255,0.16); }
|
||||||
|
.btn-ctrl:disabled { opacity: 0.28; }
|
||||||
|
|
||||||
.btn-danger {
|
.btn-danger {
|
||||||
background: rgba(198, 40, 40, 0.25);
|
background: rgba(180,30,30,0.2);
|
||||||
border: 1px solid rgba(239, 83, 80, 0.4);
|
border: 1px solid rgba(239,83,80,0.3);
|
||||||
color: #ff8a80;
|
color: #ff6b6b;
|
||||||
padding: 14px 8px;
|
padding: 14px 8px;
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
border-radius: 12px;
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
.btn-danger:active {
|
.btn-danger:active { background: rgba(198,40,40,0.4); }
|
||||||
background: rgba(198, 40, 40, 0.45);
|
|
||||||
|
/* ── MODALITÀ ESTESA ── */
|
||||||
|
|
||||||
|
.e-dash {
|
||||||
|
position: fixed;
|
||||||
|
top: 28px; /* altezza conn-bar */
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 10px;
|
||||||
|
gap: 8px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #111;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Overlay e finestre modali */
|
.e-panels {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
gap: 10px;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pannello squadra */
|
||||||
|
.e-panel {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
border-radius: 16px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #161618;
|
||||||
|
border: 1px solid rgba(255,255,255,0.07);
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Barra colorata in cima — identità squadra */
|
||||||
|
.e-panel__stripe {
|
||||||
|
height: 5px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.e-panel--home .e-panel__stripe { background: #f5c518; }
|
||||||
|
.e-panel--guest .e-panel__stripe { background: #2196f3; }
|
||||||
|
|
||||||
|
.e-panel__body {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 14px 16px 14px;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Header */
|
||||||
|
.e-panel__head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.e-panel__name {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 900;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1.5px;
|
||||||
|
color: #f0f0f0;
|
||||||
|
}
|
||||||
|
.e-panel__meta {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.e-panel--home .e-panel__meta { color: #f5c518; }
|
||||||
|
.e-panel--guest .e-panel__meta { color: #2196f3; }
|
||||||
|
.e-label {
|
||||||
|
font-size: 9px;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
opacity: 0.6;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.e-panel__serv { width: 14px; height: 14px; }
|
||||||
|
|
||||||
|
/* Score — l'elemento eroe */
|
||||||
|
.e-panel__score {
|
||||||
|
font-size: clamp(60px, 14vh, 110px);
|
||||||
|
font-weight: 900;
|
||||||
|
line-height: 1;
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 6px 0;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
transition: opacity 0.1s, transform 0.1s;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
.e-panel__score:active { opacity: 0.65; transform: scale(0.96); }
|
||||||
|
.e-panel--home .e-panel__score { color: #f5c518; }
|
||||||
|
.e-panel--guest .e-panel__score { color: #2196f3; }
|
||||||
|
|
||||||
|
/* Campo formazione — diagramma del campo */
|
||||||
|
.e-panel__court {
|
||||||
|
flex-shrink: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0;
|
||||||
|
background: rgba(34, 80, 34, 0.18);
|
||||||
|
border: 1px solid rgba(255,255,255,0.08);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
height: clamp(120px, 28vh, 200px);
|
||||||
|
}
|
||||||
|
.e-court__row {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
.e-court__cell {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: clamp(13px, 2.4vh, 22px);
|
||||||
|
font-weight: 700;
|
||||||
|
color: #ddd;
|
||||||
|
background: rgba(255,255,255,0.07);
|
||||||
|
border-radius: 6px;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
.e-court__net {
|
||||||
|
height: 2px;
|
||||||
|
background: rgba(255,255,255,0.18);
|
||||||
|
margin: 5px 0;
|
||||||
|
border-radius: 1px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SET button — pieno colore, fondo pannello */
|
||||||
|
.e-panel__setbtn {
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 100%;
|
||||||
|
padding: 9px 0;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: 1.2px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: opacity 0.1s;
|
||||||
|
}
|
||||||
|
.e-panel__setbtn:active { opacity: 0.75; transform: scale(0.98); }
|
||||||
|
.e-panel--home .e-panel__setbtn { background: #f5c518; color: #111; }
|
||||||
|
.e-panel--guest .e-panel__setbtn { background: #2196f3; color: #fff; }
|
||||||
|
|
||||||
|
/* Barra azioni secondarie */
|
||||||
|
.e-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
.e-act {
|
||||||
|
flex: 1;
|
||||||
|
height: 100%;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.2px;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgba(255,255,255,0.1);
|
||||||
|
background: rgba(255,255,255,0.07);
|
||||||
|
color: #bbb;
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
transition: background 0.12s;
|
||||||
|
}
|
||||||
|
.e-act:active { background: rgba(255,255,255,0.16); }
|
||||||
|
.e-act:disabled { opacity: 0.28; cursor: not-allowed; }
|
||||||
|
.e-act--undo { color: #ffab91; border-color: rgba(255,171,145,0.2); }
|
||||||
|
.e-act--danger { background: rgba(180,30,30,0.2); border-color: rgba(239,83,80,0.3); color: #ff6b6b; }
|
||||||
|
.e-act--danger:active { background: rgba(198,40,40,0.4); }
|
||||||
|
|
||||||
|
/* ── OVERLAY E DIALOGS ── */
|
||||||
|
|
||||||
.overlay {
|
.overlay {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -606,6 +889,22 @@ export default {
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
flex: 1;
|
||||||
|
background: rgba(255,255,255,0.14);
|
||||||
|
color: #ccc;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
border: 1px solid rgba(255,255,255,0.2);
|
||||||
|
cursor: pointer;
|
||||||
|
font-family: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-confirm {
|
.btn-confirm {
|
||||||
@@ -616,12 +915,14 @@ export default {
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-family: inherit;
|
||||||
}
|
}
|
||||||
.btn-confirm:disabled {
|
.btn-confirm:disabled {
|
||||||
opacity: 0.4;
|
opacity: 0.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gruppi form */
|
|
||||||
.form-group {
|
.form-group {
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
@@ -665,7 +966,6 @@ export default {
|
|||||||
border-color: #64b5f6;
|
border-color: #64b5f6;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Griglia formazione */
|
|
||||||
.form-grid {
|
.form-grid {
|
||||||
background: rgba(205, 133, 63, 0.15);
|
background: rgba(205, 133, 63, 0.15);
|
||||||
border: 2px solid rgba(255,255,255,0.15);
|
border: 2px solid rgba(255,255,255,0.15);
|
||||||
@@ -683,7 +983,6 @@ export default {
|
|||||||
margin: 4px 0;
|
margin: 4px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pulsanti modalita */
|
|
||||||
.mode-buttons {
|
.mode-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
@@ -697,13 +996,15 @@ export default {
|
|||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
transition: all 0.15s;
|
transition: all 0.15s;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-family: inherit;
|
||||||
}
|
}
|
||||||
.btn-mode.active {
|
.btn-mode.active {
|
||||||
background: #2e7d32;
|
background: #2e7d32;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sezione cambi */
|
|
||||||
.cambi-container {
|
.cambi-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -62,6 +62,13 @@ export function applyAction(state, action) {
|
|||||||
|
|
||||||
const servHome = servizio(s.sp.striscia)
|
const servHome = servizio(s.sp.striscia)
|
||||||
const cambioPalla = (team === "home") !== servHome
|
const cambioPalla = (team === "home") !== servHome
|
||||||
|
const setCorrente = s.sp.striscia.at(-1)
|
||||||
|
if (setCorrente.ris === '') {
|
||||||
|
setCorrente.formInizio = {
|
||||||
|
home: [...s.sp.form.home],
|
||||||
|
guest: [...s.sp.form.guest],
|
||||||
|
}
|
||||||
|
}
|
||||||
s.sp.striscia.at(-1).ris += team === 'home' ? 'h' : 'g'
|
s.sp.striscia.at(-1).ris += team === 'home' ? 'h' : 'g'
|
||||||
|
|
||||||
if (cambioPalla) {
|
if (cambioPalla) {
|
||||||
@@ -82,6 +89,7 @@ export function applyAction(state, action) {
|
|||||||
const wasCambioPalla = lastScorerShort !== prevServerShort
|
const wasCambioPalla = lastScorerShort !== prevServerShort
|
||||||
|
|
||||||
currentSet.ris = currentSet.ris.slice(0, -1)
|
currentSet.ris = currentSet.ris.slice(0, -1)
|
||||||
|
if (currentSet.ris === '') delete currentSet.formInizio
|
||||||
|
|
||||||
const lastScorer = lastScorerShort === 'h' ? 'home' : 'guest'
|
const lastScorer = lastScorerShort === 'h' ? 'home' : 'guest'
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
function vincitoreSet(s) {
|
||||||
|
if (s.vinc === 'h' || s.vinc === 'g') return s.vinc
|
||||||
|
let h = 0, g = 0
|
||||||
|
for (const c of s.ris) c === 'h' ? h++ : g++
|
||||||
|
if (h > g) return 'h'
|
||||||
|
if (g > h) return 'g'
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Costruisce l'HTML del referto (funzione pura, testabile).
|
||||||
|
// `now` è iniettabile per rendere deterministica la data nei test.
|
||||||
|
export function buildRefertoHtml(state, now = new Date()) {
|
||||||
|
const { sp, modalitaPartita } = state
|
||||||
|
const { nomi, striscia } = sp
|
||||||
|
|
||||||
|
const setReali = striscia.filter(s => !s._phantom)
|
||||||
|
|
||||||
|
const setVinti = { home: 0, guest: 0 }
|
||||||
|
for (const s of setReali) {
|
||||||
|
const v = vincitoreSet(s)
|
||||||
|
if (v === 'h') setVinti.home++
|
||||||
|
else if (v === 'g') setVinti.guest++
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataOra = now.toLocaleString('it-IT', {
|
||||||
|
day: '2-digit', month: '2-digit', year: 'numeric',
|
||||||
|
hour: '2-digit', minute: '2-digit',
|
||||||
|
})
|
||||||
|
|
||||||
|
const giocatoreHtml = (n) => `<div class="giocatore">${n}</div>`
|
||||||
|
|
||||||
|
const formazioneHtml = (formazioneSet) => {
|
||||||
|
if (!formazioneSet) return '<em style="color:#999;font-size:11px">non disponibile</em>'
|
||||||
|
return `
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-team">
|
||||||
|
<div class="form-team-name">${nomi.home}</div>
|
||||||
|
<div class="giocatori">${formazioneSet.home.map(giocatoreHtml).join('')}</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-team">
|
||||||
|
<div class="form-team-name">${nomi.guest}</div>
|
||||||
|
<div class="giocatori">${formazioneSet.guest.map(giocatoreHtml).join('')}</div>
|
||||||
|
</div>
|
||||||
|
</div>`
|
||||||
|
}
|
||||||
|
|
||||||
|
const setsHtml = setReali.map((s, i) => {
|
||||||
|
let h = 0, g = 0
|
||||||
|
const punti = []
|
||||||
|
for (const c of s.ris) {
|
||||||
|
c === 'h' ? h++ : g++
|
||||||
|
punti.push({ chi: c, h, g })
|
||||||
|
}
|
||||||
|
|
||||||
|
const vinc = vincitoreSet(s)
|
||||||
|
const nomeVinc = vinc === 'h' ? nomi.home : vinc === 'g' ? nomi.guest : ''
|
||||||
|
const etichettaVinc = nomeVinc ? ` · vinto da <strong>${nomeVinc}</strong>` : ''
|
||||||
|
|
||||||
|
const puntiHtml = punti.map(p =>
|
||||||
|
`<span class="punto punto-${p.chi}">${p.h}-${p.g}</span>`
|
||||||
|
).join('')
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="set-section">
|
||||||
|
<div class="set-header">
|
||||||
|
Set ${i + 1} — ${nomi.home} <strong>${h}</strong> · <strong>${g}</strong> ${nomi.guest}${etichettaVinc}
|
||||||
|
</div>
|
||||||
|
<div class="form-inizio">
|
||||||
|
<div class="form-inizio-label">Formazione di partenza</div>
|
||||||
|
${formazioneHtml(s.formInizio)}
|
||||||
|
</div>
|
||||||
|
<div class="punti-grid">${puntiHtml || '<em style="color:#999;font-size:11px">Nessun punto registrato</em>'}</div>
|
||||||
|
</div>`
|
||||||
|
}).join('')
|
||||||
|
|
||||||
|
const html = `<!DOCTYPE html>
|
||||||
|
<html lang="it">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Referto — ${nomi.home} vs ${nomi.guest}</title>
|
||||||
|
<style>
|
||||||
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||||
|
body { font-family: Arial, Helvetica, sans-serif; color: #111; background: #fff; padding: 28px; font-size: 14px; }
|
||||||
|
@media print { body { padding: 12px; } }
|
||||||
|
|
||||||
|
.header { text-align: center; border-bottom: 2px solid #111; padding-bottom: 12px; margin-bottom: 20px; }
|
||||||
|
.titolo { font-size: 18px; font-weight: bold; letter-spacing: 3px; text-transform: uppercase; }
|
||||||
|
.meta { font-size: 12px; color: #666; margin-top: 5px; }
|
||||||
|
|
||||||
|
.squadre-row { display: flex; justify-content: space-around; align-items: center; margin: 18px 0 6px; }
|
||||||
|
.nome-sq { font-size: 22px; font-weight: bold; text-align: center; max-width: 40%; }
|
||||||
|
.vs { font-size: 16px; color: #999; }
|
||||||
|
.risultato { text-align: center; font-size: 36px; font-weight: bold; letter-spacing: 6px; margin-bottom: 4px; }
|
||||||
|
.modalita-label { text-align: center; font-size: 12px; color: #888; margin-bottom: 22px; }
|
||||||
|
|
||||||
|
.set-section { margin-bottom: 12px; border: 1px solid #ddd; border-radius: 4px; overflow: hidden; }
|
||||||
|
.set-header { background: #f5f5f5; padding: 7px 12px; font-size: 13px; border-bottom: 1px solid #ddd; }
|
||||||
|
.punti-grid { display: flex; flex-wrap: wrap; gap: 3px; padding: 8px 10px; }
|
||||||
|
.punto { display: inline-block; padding: 2px 5px; border-radius: 3px; font-size: 11px; font-family: 'Courier New', monospace; white-space: nowrap; }
|
||||||
|
.punto-h { background: #d0e8ff; color: #003a6e; }
|
||||||
|
.punto-g { background: #ffddc0; color: #6e2700; }
|
||||||
|
|
||||||
|
.form-inizio { padding: 8px 10px; border-bottom: 1px solid #eee; background: #fafafa; }
|
||||||
|
.form-inizio-label { font-size: 11px; font-weight: bold; letter-spacing: 0.5px; text-transform: uppercase; color: #888; margin-bottom: 7px; }
|
||||||
|
.form-row { display: flex; gap: 40px; }
|
||||||
|
.form-team { flex: 1; }
|
||||||
|
.form-team-name { font-weight: bold; font-size: 13px; margin-bottom: 6px; }
|
||||||
|
.giocatori { display: flex; gap: 5px; flex-wrap: wrap; }
|
||||||
|
.giocatore { background: #f0f0f0; border-radius: 50%; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 12px; border: 1px solid #ccc; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header">
|
||||||
|
<div class="titolo">Referto di Gara</div>
|
||||||
|
<div class="meta">${dataOra} · Modalità: ${modalitaPartita}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="squadre-row">
|
||||||
|
<div class="nome-sq">${nomi.home}</div>
|
||||||
|
<div class="vs">vs</div>
|
||||||
|
<div class="nome-sq">${nomi.guest}</div>
|
||||||
|
</div>
|
||||||
|
<div class="risultato">${setVinti.home} – ${setVinti.guest}</div>
|
||||||
|
<div class="modalita-label">set vinti</div>
|
||||||
|
|
||||||
|
${setsHtml}
|
||||||
|
</body>
|
||||||
|
</html>`
|
||||||
|
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apre il referto in una nuova scheda e avvia la stampa (effetto collaterale,
|
||||||
|
// solo browser). La generazione dell'HTML è delegata a buildRefertoHtml.
|
||||||
|
export function generaReferto(state) {
|
||||||
|
const html = buildRefertoHtml(state)
|
||||||
|
const w = window.open('', '_blank')
|
||||||
|
w.document.write(html)
|
||||||
|
w.document.close()
|
||||||
|
w.print()
|
||||||
|
}
|
||||||
@@ -9,7 +9,34 @@ function isWSL() {
|
|||||||
} catch { return false }
|
} catch { return false }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNetworkIPs() {
|
// Un IPv4 è "pubblicabile" in LAN se non è loopback, link-local o bridge Docker.
|
||||||
|
function isLanIPv4(address) {
|
||||||
|
return !!address
|
||||||
|
&& !address.startsWith('127.')
|
||||||
|
&& !address.startsWith('169.254.')
|
||||||
|
&& !address.startsWith('172.')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Estrae gli IP LAN da un oggetto in stile os.networkInterfaces().
|
||||||
|
// Esportata per poter essere testata in isolamento, senza dipendere dalla piattaforma.
|
||||||
|
export function collectIPs(nets) {
|
||||||
|
const out = []
|
||||||
|
for (const name of Object.keys(nets || {})) {
|
||||||
|
for (const net of nets[name]) {
|
||||||
|
if (net.family === 'IPv4' && !net.internal && isLanIPv4(net.address)) {
|
||||||
|
out.push(net.address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restituisce gli IP di rete della macchina.
|
||||||
|
// Passando `nets` (oggetto in stile os.networkInterfaces) si forza il percorso
|
||||||
|
// deterministico, scavalcando il rilevamento WSL/PowerShell: utile nei test.
|
||||||
|
export function getNetworkIPs(nets) {
|
||||||
|
if (nets) return collectIPs(nets)
|
||||||
|
|
||||||
if (isWSL()) {
|
if (isWSL()) {
|
||||||
try {
|
try {
|
||||||
const out = execSync(
|
const out = execSync(
|
||||||
@@ -18,23 +45,15 @@ export function getNetworkIPs() {
|
|||||||
)
|
)
|
||||||
return out.toString().trim().split('\n')
|
return out.toString().trim().split('\n')
|
||||||
.map(s => s.trim())
|
.map(s => s.trim())
|
||||||
.filter(ip => ip && !ip.startsWith('127.') && !ip.startsWith('169.254.') && !ip.startsWith('172.'))
|
.filter(isLanIPv4)
|
||||||
} catch { return [] }
|
} catch { return [] }
|
||||||
}
|
}
|
||||||
|
|
||||||
const nets = networkInterfaces()
|
return collectIPs(networkInterfaces())
|
||||||
const networkIPs = []
|
|
||||||
for (const name of Object.keys(nets)) {
|
|
||||||
for (const net of nets[name]) {
|
|
||||||
if (net.family === 'IPv4' && !net.internal) networkIPs.push(net.address)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return networkIPs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function printServerInfo(port = 3000) {
|
// `networkIPs` è iniettabile per rendere la stampa testabile in modo deterministico.
|
||||||
const networkIPs = getNetworkIPs()
|
export function printServerInfo(port = 3000, networkIPs = getNetworkIPs()) {
|
||||||
|
|
||||||
console.log(`\nSegnapunti Server`)
|
console.log(`\nSegnapunti Server`)
|
||||||
console.log(` Display: http://127.0.0.1:${port}/display`)
|
console.log(` Display: http://127.0.0.1:${port}/display`)
|
||||||
console.log(` Controller: http://127.0.0.1:${port}/controller`)
|
console.log(` Controller: http://127.0.0.1:${port}/controller`)
|
||||||
|
|||||||
@@ -90,10 +90,18 @@ Esempi reali nel progetto:
|
|||||||
- cambio palla
|
- cambio palla
|
||||||
- vittoria set con regola dei 2 punti di scarto
|
- vittoria set con regola dei 2 punti di scarto
|
||||||
- reset stato
|
- reset stato
|
||||||
|
- `formInizio` (snapshot formazione di partenza del set)
|
||||||
|
- generazione del referto (`buildRefertoHtml`)
|
||||||
|
- persistenza stato su disco (`persist.js`, con `fs` mockato)
|
||||||
|
- utility di rete (`server-utils.js`)
|
||||||
|
|
||||||
Quando falliscono:
|
Quando falliscono:
|
||||||
- quasi sempre c'e un problema nella logica core
|
- quasi sempre c'e un problema nella logica core
|
||||||
|
|
||||||
|
> Nota: punteggio, set e servizio NON sono campi dello stato: si ricavano dalla
|
||||||
|
> `striscia` con `punteggio` / `setVinti` / `servizio`. Nei test si impostano gli
|
||||||
|
> scenari costruendo la `striscia`, non scrivendo `sp.punt`/`sp.set`.
|
||||||
|
|
||||||
### 5.2 Integration (`tests/integration`)
|
### 5.2 Integration (`tests/integration`)
|
||||||
|
|
||||||
Cosa sono:
|
Cosa sono:
|
||||||
@@ -107,6 +115,7 @@ Esempi reali nel progetto:
|
|||||||
- broadcast stato ai client
|
- broadcast stato ai client
|
||||||
- validazione input malformati
|
- validazione input malformati
|
||||||
- autorizzazioni (solo controller puo inviare certe azioni)
|
- autorizzazioni (solo controller puo inviare certe azioni)
|
||||||
|
- routing del server Express (`createApp`: rotte display/controller/asset)
|
||||||
|
|
||||||
Quando falliscono:
|
Quando falliscono:
|
||||||
- spesso c'e problema nel protocollo messaggi o nei controlli di ruolo
|
- spesso c'e problema nel protocollo messaggi o nei controlli di ruolo
|
||||||
@@ -124,6 +133,8 @@ Esempi reali nel progetto:
|
|||||||
- stato connessione
|
- stato connessione
|
||||||
- click bottoni controller
|
- click bottoni controller
|
||||||
- dialog reset/config/cambi
|
- dialog reset/config/cambi
|
||||||
|
- bottone REFERTO nel dialog PARTITA FINITA
|
||||||
|
- client WebSocket (`wsMixin`: connessione, riconnessione, `sendWs`)
|
||||||
|
|
||||||
Quando falliscono:
|
Quando falliscono:
|
||||||
- spesso hai rotto template, computed, metodi o binding
|
- spesso hai rotto template, computed, metodi o binding
|
||||||
@@ -152,15 +163,19 @@ A cosa servono:
|
|||||||
- verificano che Controller e Display funzionino davvero insieme
|
- verificano che Controller e Display funzionino davvero insieme
|
||||||
|
|
||||||
File principali:
|
File principali:
|
||||||
|
- `helpers.cjs`: helper condivisi (`openController`/`openDisplay`/`resetGame`/`addPoints`)
|
||||||
- `basic-flow.spec.cjs`: flusso base Controller <-> Display
|
- `basic-flow.spec.cjs`: flusso base Controller <-> Display
|
||||||
- `game-operations.spec.cjs`: reset, config, toggle, cambi
|
- `game-operations.spec.cjs`: reset, config, toggle, cambi
|
||||||
- `game-simulation.spec.cjs`: simulazione partita
|
- `game-simulation.spec.cjs`: simulazione partita
|
||||||
- `full-match.spec.cjs`: scenari partita completi
|
- `full-match.spec.cjs`: scenari partita completi
|
||||||
|
- `referto.spec.cjs`: generazione referto a PARTITA FINITA
|
||||||
- `accessibility.spec.cjs`: controlli accessibilita con axe
|
- `accessibility.spec.cjs`: controlli accessibilita con axe
|
||||||
- `visual-regression.spec.cjs`: confronto screenshot con baseline
|
- `visual-regression.spec.cjs`: confronto screenshot con baseline
|
||||||
|
|
||||||
Nota importante:
|
Note importanti:
|
||||||
- gli E2E sono configurati in seriale (`workers: 1`) per evitare interferenze sullo stato partita condiviso.
|
- gli E2E sono configurati in seriale (`workers: 1`) per evitare interferenze sullo stato partita condiviso.
|
||||||
|
- il controller viene aperto in viewport portrait (layout "mobile") tramite `openController`: in landscape userebbe la dashboard estesa con selettori diversi.
|
||||||
|
- lo stato è UNICO e persistente sul server: ogni test inizia con `resetGame`, che azzera e reimposta i nomi di default per garantire determinismo.
|
||||||
|
|
||||||
## 6) Come leggere i risultati
|
## 6) Come leggere i risultati
|
||||||
|
|
||||||
@@ -169,8 +184,8 @@ Nota importante:
|
|||||||
Caso OK (verde):
|
Caso OK (verde):
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Test Files 6 passed (6)
|
Test Files 10 passed (10)
|
||||||
Tests 159 passed (159)
|
Tests 212 passed (212)
|
||||||
```
|
```
|
||||||
|
|
||||||
Significa:
|
Significa:
|
||||||
@@ -187,7 +202,7 @@ Caso KO (rosso):
|
|||||||
Caso OK:
|
Caso OK:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
72 passed
|
75 passed
|
||||||
```
|
```
|
||||||
|
|
||||||
Caso KO:
|
Caso KO:
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
import ControllerPage from '../../src/components/ControllerPage.vue'
|
import ControllerPage from '../../src/components/ControllerPage.vue'
|
||||||
|
import { generaReferto } from '../../src/referto.js'
|
||||||
|
|
||||||
|
// Il referto apre una finestra/print: lo mockiamo per testarne solo l'invocazione.
|
||||||
|
vi.mock('../../src/referto.js', () => ({ generaReferto: vi.fn() }))
|
||||||
|
|
||||||
// Mock globale WebSocket per jsdom
|
// Mock globale WebSocket per jsdom
|
||||||
class MockWebSocket {
|
class MockWebSocket {
|
||||||
@@ -25,6 +29,21 @@ class MockWebSocket {
|
|||||||
|
|
||||||
vi.stubGlobal('WebSocket', MockWebSocket)
|
vi.stubGlobal('WebSocket', MockWebSocket)
|
||||||
|
|
||||||
|
// Forza l'orientamento portrait → il controller usa il layout "mobile"
|
||||||
|
// (con .team-pts, .btn-ctrl, ecc.) su cui questi test fanno asserzioni.
|
||||||
|
Object.defineProperty(window, 'innerWidth', { value: 400, writable: true, configurable: true })
|
||||||
|
Object.defineProperty(window, 'innerHeight', { value: 800, writable: true, configurable: true })
|
||||||
|
|
||||||
|
// Imposta il punteggio del set in corso costruendo una ris coerente.
|
||||||
|
// `serv` ('h'|'g') controlla l'ultimo punto, quindi chi risulta al servizio.
|
||||||
|
function setScore(wrapper, home, guest, serv = 'h') {
|
||||||
|
const altro = serv === 'h' ? 'g' : 'h'
|
||||||
|
const nAltro = serv === 'h' ? guest : home
|
||||||
|
const nServ = serv === 'h' ? home : guest
|
||||||
|
// mette per ultimo il carattere del battitore desiderato
|
||||||
|
wrapper.vm.state.sp.striscia.at(-1).ris = altro.repeat(nAltro) + serv.repeat(nServ)
|
||||||
|
}
|
||||||
|
|
||||||
// Helper per creare il componente con stato personalizzato
|
// Helper per creare il componente con stato personalizzato
|
||||||
function mountController(stateOverrides = {}) {
|
function mountController(stateOverrides = {}) {
|
||||||
const wrapper = mount(ControllerPage, {
|
const wrapper = mount(ControllerPage, {
|
||||||
@@ -105,7 +124,7 @@ describe('ControllerPage.vue', () => {
|
|||||||
|
|
||||||
it('dovrebbe essere disabilitato se il punteggio non è 0-0', async () => {
|
it('dovrebbe essere disabilitato se il punteggio non è 0-0', async () => {
|
||||||
const wrapper = mountController()
|
const wrapper = mountController()
|
||||||
wrapper.vm.state.sp.punt.home = 5
|
setScore(wrapper, 5, 0)
|
||||||
await wrapper.vm.$nextTick()
|
await wrapper.vm.$nextTick()
|
||||||
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()
|
||||||
@@ -194,8 +213,7 @@ describe('ControllerPage.vue', () => {
|
|||||||
|
|
||||||
it('dovrebbe generare "N pari" a punteggio uguale', () => {
|
it('dovrebbe generare "N pari" a punteggio uguale', () => {
|
||||||
const wrapper = mountController()
|
const wrapper = mountController()
|
||||||
wrapper.vm.state.sp.punt.home = 5
|
setScore(wrapper, 5, 5)
|
||||||
wrapper.vm.state.sp.punt.guest = 5
|
|
||||||
wrapper.vm.wsConnected = true
|
wrapper.vm.wsConnected = true
|
||||||
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
||||||
wrapper.vm.speak()
|
wrapper.vm.speak()
|
||||||
@@ -205,9 +223,7 @@ describe('ControllerPage.vue', () => {
|
|||||||
|
|
||||||
it('dovrebbe annunciare prima il punteggio di chi batte (home serve)', () => {
|
it('dovrebbe annunciare prima il punteggio di chi batte (home serve)', () => {
|
||||||
const wrapper = mountController()
|
const wrapper = mountController()
|
||||||
wrapper.vm.state.sp.punt.home = 15
|
setScore(wrapper, 15, 10, 'h')
|
||||||
wrapper.vm.state.sp.punt.guest = 10
|
|
||||||
wrapper.vm.state.sp.servHome = true
|
|
||||||
wrapper.vm.wsConnected = true
|
wrapper.vm.wsConnected = true
|
||||||
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
||||||
wrapper.vm.speak()
|
wrapper.vm.speak()
|
||||||
@@ -217,9 +233,7 @@ describe('ControllerPage.vue', () => {
|
|||||||
|
|
||||||
it('dovrebbe annunciare prima il punteggio di chi batte (guest serve)', () => {
|
it('dovrebbe annunciare prima il punteggio di chi batte (guest serve)', () => {
|
||||||
const wrapper = mountController()
|
const wrapper = mountController()
|
||||||
wrapper.vm.state.sp.punt.home = 10
|
setScore(wrapper, 10, 15, 'g')
|
||||||
wrapper.vm.state.sp.punt.guest = 15
|
|
||||||
wrapper.vm.state.sp.servHome = false
|
|
||||||
wrapper.vm.wsConnected = true
|
wrapper.vm.wsConnected = true
|
||||||
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
||||||
wrapper.vm.speak()
|
wrapper.vm.speak()
|
||||||
@@ -228,6 +242,51 @@ describe('ControllerPage.vue', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// REFERTO (modal PARTITA FINITA)
|
||||||
|
// =============================================
|
||||||
|
describe('Referto', () => {
|
||||||
|
// Porta il componente allo stato "partita finita" per home in 2/3
|
||||||
|
function setPartitaFinita(wrapper) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
it('mostra il bottone REFERTO quando la partita è finita', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
setPartitaFinita(wrapper)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.isPartitaFinita).toBe(true)
|
||||||
|
const btn = wrapper.findAll('.btn-secondary').find(b => b.text().includes('REFERTO'))
|
||||||
|
expect(btn).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('il click su REFERTO invoca generaReferto con lo stato', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
setPartitaFinita(wrapper)
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
const btn = wrapper.findAll('.btn-secondary').find(b => b.text().includes('REFERTO'))
|
||||||
|
await btn.trigger('click')
|
||||||
|
expect(generaReferto).toHaveBeenCalledWith(wrapper.vm.state)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('NON mostra il bottone REFERTO a set vinto (partita non finita)', async () => {
|
||||||
|
const wrapper = mountController()
|
||||||
|
wrapper.vm.state.modalitaPartita = '3/5'
|
||||||
|
wrapper.vm.setVintoTeam = 'home'
|
||||||
|
wrapper.vm.showSetVinto = true
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.isPartitaFinita).toBe(false)
|
||||||
|
const btn = wrapper.findAll('.btn-secondary').find(b => b.text().includes('REFERTO'))
|
||||||
|
expect(btn).toBeUndefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
// BARRA CONNESSIONE
|
// BARRA CONNESSIONE
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ describe('DisplayPage.vue', () => {
|
|||||||
|
|
||||||
it('dovrebbe aggiornare il punteggio quando lo stato cambia', async () => {
|
it('dovrebbe aggiornare il punteggio quando lo stato cambia', async () => {
|
||||||
const wrapper = mountDisplay()
|
const wrapper = mountDisplay()
|
||||||
wrapper.vm.state.sp.punt.home = 15
|
// il punteggio si ricava dalla striscia: 15 punti home + 12 guest
|
||||||
wrapper.vm.state.sp.punt.guest = 12
|
wrapper.vm.state.sp.striscia.at(-1).ris = 'h'.repeat(15) + 'g'.repeat(12)
|
||||||
await wrapper.vm.$nextTick()
|
await wrapper.vm.$nextTick()
|
||||||
const punti = wrapper.findAll('.punt')
|
const punti = wrapper.findAll('.punt')
|
||||||
expect(punti[0].text()).toBe('15')
|
expect(punti[0].text()).toBe('15')
|
||||||
|
|||||||
@@ -0,0 +1,174 @@
|
|||||||
|
// @vitest-environment happy-dom
|
||||||
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||||
|
import { mount } from '@vue/test-utils'
|
||||||
|
import { createWsMixin } from '../../src/wsMixin.js'
|
||||||
|
import { createInitialState } from '../../src/gameState.js'
|
||||||
|
|
||||||
|
// WebSocket mock controllabile: i gestori (onopen/onmessage/onclose) vengono
|
||||||
|
// assegnati dal mixin e li invochiamo manualmente nei test.
|
||||||
|
class MockWebSocket {
|
||||||
|
static CONNECTING = 0
|
||||||
|
static OPEN = 1
|
||||||
|
static CLOSING = 2
|
||||||
|
static CLOSED = 3
|
||||||
|
constructor(url) {
|
||||||
|
this.url = url
|
||||||
|
this.readyState = MockWebSocket.CONNECTING
|
||||||
|
this.send = vi.fn()
|
||||||
|
this.close = vi.fn()
|
||||||
|
MockWebSocket.instances.push(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MockWebSocket.instances = []
|
||||||
|
|
||||||
|
vi.stubGlobal('WebSocket', MockWebSocket)
|
||||||
|
|
||||||
|
// Monta un componente che usa il mixin. `extra` permette di aggiungere hook.
|
||||||
|
function mountWith(role = 'controller', extra = {}) {
|
||||||
|
const Comp = {
|
||||||
|
mixins: [createWsMixin(role)],
|
||||||
|
template: '<div></div>',
|
||||||
|
...extra,
|
||||||
|
}
|
||||||
|
return mount(Comp)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ultimaWs() {
|
||||||
|
return MockWebSocket.instances.at(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('createWsMixin (wsMixin.js)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
MockWebSocket.instances = []
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('computed derivati', () => {
|
||||||
|
it('punt/servHome/set delegano alle funzioni pure sulla striscia', async () => {
|
||||||
|
const wrapper = mountWith()
|
||||||
|
wrapper.vm.state.sp.striscia = [
|
||||||
|
{ serv: 'h', ris: 'h', vinc: 'h' },
|
||||||
|
{ serv: 'h', ris: 'h'.repeat(10) + 'g'.repeat(8), vinc: null },
|
||||||
|
]
|
||||||
|
await wrapper.vm.$nextTick()
|
||||||
|
expect(wrapper.vm.punt).toEqual({ home: 10, guest: 8 })
|
||||||
|
expect(wrapper.vm.set).toEqual({ home: 1, guest: 0 })
|
||||||
|
// ultimo punto 'g' → serve guest
|
||||||
|
expect(wrapper.vm.servHome).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('connessione', () => {
|
||||||
|
it('apre una WebSocket verso /ws al mount', () => {
|
||||||
|
mountWith()
|
||||||
|
const ws = ultimaWs()
|
||||||
|
expect(ws).toBeDefined()
|
||||||
|
expect(ws.url).toMatch(/^ws:\/\/.+\/ws$/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('invia il messaggio register all\'apertura', () => {
|
||||||
|
const wrapper = mountWith('controller')
|
||||||
|
const ws = ultimaWs()
|
||||||
|
ws.readyState = MockWebSocket.OPEN
|
||||||
|
ws.onopen()
|
||||||
|
expect(ws.send).toHaveBeenCalledTimes(1)
|
||||||
|
const msg = JSON.parse(ws.send.mock.calls[0][0])
|
||||||
|
expect(msg).toEqual({ type: 'register', role: 'controller' })
|
||||||
|
expect(wrapper.vm.wsConnected).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('un messaggio "state" aggiorna lo stato locale', () => {
|
||||||
|
const wrapper = mountWith()
|
||||||
|
const ws = ultimaWs()
|
||||||
|
const nuovo = createInitialState()
|
||||||
|
nuovo.sp.nomi.home = 'Nuova Squadra'
|
||||||
|
ws.onmessage({ data: JSON.stringify({ type: 'state', state: nuovo }) })
|
||||||
|
expect(wrapper.vm.state.sp.nomi.home).toBe('Nuova Squadra')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('un messaggio non-state invoca l\'hook onWsMessage', () => {
|
||||||
|
const onWsMessage = vi.fn()
|
||||||
|
const wrapper = mountWith('display', { methods: { onWsMessage } })
|
||||||
|
const ws = ultimaWs()
|
||||||
|
ws.onmessage({ data: JSON.stringify({ type: 'speak', text: 'ciao' }) })
|
||||||
|
expect(onWsMessage).toHaveBeenCalledWith({ type: 'speak', text: 'ciao' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('riconnessione', () => {
|
||||||
|
it('scheduleReconnect usa backoff esponenziale con cap a 30s', () => {
|
||||||
|
const wrapper = mountWith()
|
||||||
|
const delays = []
|
||||||
|
const spy = vi.spyOn(globalThis, 'setTimeout').mockImplementation(() => 123)
|
||||||
|
// intercetta i delay leggendoli dalle chiamate
|
||||||
|
spy.mockImplementation((_fn, d) => { delays.push(d); return 123 })
|
||||||
|
|
||||||
|
wrapper.vm.reconnectAttempts = 0
|
||||||
|
wrapper.vm.reconnectTimeout = null
|
||||||
|
wrapper.vm.scheduleReconnect() // 1000
|
||||||
|
wrapper.vm.reconnectTimeout = null
|
||||||
|
wrapper.vm.scheduleReconnect() // 2000
|
||||||
|
wrapper.vm.reconnectTimeout = null
|
||||||
|
wrapper.vm.scheduleReconnect() // 4000
|
||||||
|
expect(delays).toEqual([1000, 2000, 4000])
|
||||||
|
|
||||||
|
// attempts alto → cap a 30000
|
||||||
|
delays.length = 0
|
||||||
|
wrapper.vm.reconnectAttempts = 20
|
||||||
|
wrapper.vm.reconnectTimeout = null
|
||||||
|
wrapper.vm.scheduleReconnect()
|
||||||
|
expect(delays[0]).toBe(30000)
|
||||||
|
|
||||||
|
spy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('non riconnette su chiusura pulita (1000/1001)', () => {
|
||||||
|
const wrapper = mountWith()
|
||||||
|
const ws = ultimaWs()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'scheduleReconnect')
|
||||||
|
ws.onclose({ code: 1000 })
|
||||||
|
ws.onclose({ code: 1001 })
|
||||||
|
expect(spy).not.toHaveBeenCalled()
|
||||||
|
expect(wrapper.vm.wsConnected).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('riconnette su chiusura anomala (es. 1006)', () => {
|
||||||
|
const wrapper = mountWith()
|
||||||
|
const ws = ultimaWs()
|
||||||
|
const spy = vi.spyOn(wrapper.vm, 'scheduleReconnect')
|
||||||
|
ws.onclose({ code: 1006 })
|
||||||
|
expect(spy).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('sendWs', () => {
|
||||||
|
it('ritorna false se non connesso', () => {
|
||||||
|
const wrapper = mountWith()
|
||||||
|
wrapper.vm.wsConnected = false
|
||||||
|
expect(wrapper.vm.sendWs({ type: 'action' })).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('serializza e invia se connesso e aperto', () => {
|
||||||
|
const wrapper = mountWith()
|
||||||
|
const ws = ultimaWs()
|
||||||
|
ws.readyState = MockWebSocket.OPEN
|
||||||
|
wrapper.vm.wsConnected = true
|
||||||
|
const ok = wrapper.vm.sendWs({ type: 'action', action: { type: 'incPunt' } })
|
||||||
|
expect(ok).toBe(true)
|
||||||
|
const inviato = JSON.parse(ws.send.mock.calls.at(-1)[0])
|
||||||
|
expect(inviato.type).toBe('action')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('cleanup', () => {
|
||||||
|
it('beforeUnmount chiude la WebSocket', () => {
|
||||||
|
const wrapper = mountWith()
|
||||||
|
const ws = ultimaWs()
|
||||||
|
wrapper.unmount()
|
||||||
|
expect(ws.close).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
const { test, expect } = require('@playwright/test');
|
const { test, expect } = require('@playwright/test');
|
||||||
const AxeBuilderImport = require('@axe-core/playwright');
|
const AxeBuilderImport = require('@axe-core/playwright');
|
||||||
const AxeBuilder = AxeBuilderImport.default || AxeBuilderImport;
|
const AxeBuilder = AxeBuilderImport.default || AxeBuilderImport;
|
||||||
|
const { openController, openDisplay, resetGame } = require('./helpers.cjs');
|
||||||
|
|
||||||
test.describe('Accessibility (a11y)', () => {
|
test.describe('Accessibility (a11y)', () => {
|
||||||
|
|
||||||
test('Display: non dovrebbe avere violazioni critiche a11y', async ({ page }) => {
|
test('Display: non dovrebbe avere violazioni critiche a11y', async ({ context }) => {
|
||||||
await page.goto('http://localhost:3000');
|
const page = await openDisplay(context);
|
||||||
await page.waitForTimeout(500);
|
await page.waitForTimeout(500);
|
||||||
|
|
||||||
const results = await new AxeBuilder({ page })
|
const results = await new AxeBuilder({ page })
|
||||||
@@ -16,12 +17,15 @@ test.describe('Accessibility (a11y)', () => {
|
|||||||
expect(results.violations).toEqual([]);
|
expect(results.violations).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Controller: non dovrebbe avere violazioni critiche a11y', async ({ page }) => {
|
test('Controller: non dovrebbe avere violazioni critiche a11y', async ({ context }) => {
|
||||||
await page.goto('http://localhost:3001');
|
const page = await openController(context);
|
||||||
await page.waitForTimeout(500);
|
await resetGame(page);
|
||||||
|
|
||||||
const results = await new AxeBuilder({ page })
|
const results = await new AxeBuilder({ page })
|
||||||
.withTags(['wcag2a', 'wcag2aa'])
|
.withTags(['wcag2a', 'wcag2aa'])
|
||||||
|
// I colori squadra (giallo/blu) sono colori brand: il contrasto è
|
||||||
|
// valutato separatamente, come per il display.
|
||||||
|
.disableRules(['color-contrast'])
|
||||||
.analyze();
|
.analyze();
|
||||||
|
|
||||||
// Mostra i dettagli delle violazioni se ci sono
|
// Mostra i dettagli delle violazioni se ci sono
|
||||||
@@ -41,9 +45,9 @@ test.describe('Accessibility (a11y)', () => {
|
|||||||
expect(serious).toEqual([]);
|
expect(serious).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Controller: i touch target dovrebbero avere dimensione minima', async ({ page }) => {
|
test('Controller: i touch target dovrebbero avere dimensione minima', async ({ context }) => {
|
||||||
await page.goto('http://localhost:3001');
|
const page = await openController(context);
|
||||||
await page.waitForSelector('.conn-bar.connected');
|
await resetGame(page);
|
||||||
|
|
||||||
// Controlla che i bottoni principali abbiano dimensione minima 44x44px
|
// Controlla che i bottoni principali abbiano dimensione minima 44x44px
|
||||||
const buttons = page.locator('.btn-ctrl');
|
const buttons = page.locator('.btn-ctrl');
|
||||||
@@ -56,9 +60,9 @@ test.describe('Accessibility (a11y)', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Controller: i bottoni punteggio dovrebbero avere dimensione adeguata', async ({ page }) => {
|
test('Controller: i bottoni punteggio dovrebbero avere dimensione adeguata', async ({ context }) => {
|
||||||
await page.goto('http://localhost:3001');
|
const page = await openController(context);
|
||||||
await page.waitForSelector('.conn-bar.connected');
|
await resetGame(page);
|
||||||
|
|
||||||
const scoreButtons = page.locator('.team-score');
|
const scoreButtons = page.locator('.team-score');
|
||||||
const count = await scoreButtons.count();
|
const count = await scoreButtons.count();
|
||||||
|
|||||||
@@ -1,24 +1,19 @@
|
|||||||
const { test, expect } = require('@playwright/test');
|
const { test, expect } = require('@playwright/test');
|
||||||
|
const { openController, openDisplay, resetGame } = require('./helpers.cjs');
|
||||||
|
|
||||||
test.describe('Basic Flow: Controller ↔ Display', () => {
|
test.describe('Basic Flow: Controller ↔ Display', () => {
|
||||||
|
|
||||||
test('dovrebbe caricare Display e Controller con i titoli corretti', async ({ context }) => {
|
test('dovrebbe caricare Display e Controller con i titoli corretti', async ({ context }) => {
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
|
|
||||||
await displayPage.goto('http://localhost:3000');
|
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
|
|
||||||
await expect(displayPage).toHaveTitle(/Segnapunti/);
|
await expect(displayPage).toHaveTitle(/Segnapunti/);
|
||||||
await expect(controllerPage).toHaveTitle(/Controller/);
|
await expect(controllerPage).toHaveTitle(/Controller/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('il punteggio iniziale dovrebbe essere 0-0', async ({ context }) => {
|
test('il punteggio iniziale dovrebbe essere 0-0', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
// Attende la connessione WebSocket
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
const homeScore = controllerPage.locator('.team-score.home-bg .team-pts');
|
const homeScore = controllerPage.locator('.team-score.home-bg .team-pts');
|
||||||
const guestScore = controllerPage.locator('.team-score.guest-bg .team-pts');
|
const guestScore = controllerPage.locator('.team-score.guest-bg .team-pts');
|
||||||
@@ -27,22 +22,10 @@ test.describe('Basic Flow: Controller ↔ Display', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('click +1 Home sul Controller dovrebbe aggiornare il Display', async ({ context }) => {
|
test('click +1 Home sul Controller dovrebbe aggiornare il Display', async ({ context }) => {
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
|
|
||||||
await displayPage.goto('http://localhost:3000');
|
await resetGame(controllerPage);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
|
|
||||||
// Attende la connessione WebSocket del controller
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
// Reset per stato pulito
|
|
||||||
await controllerPage.getByText(/Reset/i).first().click();
|
|
||||||
const btnConfirm = controllerPage.locator('.dialog .btn-confirm');
|
|
||||||
if (await btnConfirm.isVisible()) {
|
|
||||||
await btnConfirm.click();
|
|
||||||
}
|
|
||||||
await controllerPage.waitForTimeout(200);
|
|
||||||
|
|
||||||
// Click +1 Home
|
// Click +1 Home
|
||||||
await controllerPage.locator('.team-score.home-bg').click();
|
await controllerPage.locator('.team-score.home-bg').click();
|
||||||
@@ -56,21 +39,10 @@ test.describe('Basic Flow: Controller ↔ Display', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('click +1 Guest sul Controller dovrebbe aggiornare il Display', async ({ context }) => {
|
test('click +1 Guest sul Controller dovrebbe aggiornare il Display', async ({ context }) => {
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
|
|
||||||
await displayPage.goto('http://localhost:3000');
|
await resetGame(controllerPage);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
// Reset
|
|
||||||
await controllerPage.getByText(/Reset/i).first().click();
|
|
||||||
const btnConfirm = controllerPage.locator('.dialog .btn-confirm');
|
|
||||||
if (await btnConfirm.isVisible()) {
|
|
||||||
await btnConfirm.click();
|
|
||||||
}
|
|
||||||
await controllerPage.waitForTimeout(200);
|
|
||||||
|
|
||||||
// Click +1 Guest
|
// Click +1 Guest
|
||||||
await controllerPage.locator('.team-score.guest-bg').click();
|
await controllerPage.locator('.team-score.guest-bg').click();
|
||||||
@@ -84,21 +56,10 @@ test.describe('Basic Flow: Controller ↔ Display', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('la sincronizzazione dovrebbe funzionare con punti alternati', async ({ context }) => {
|
test('la sincronizzazione dovrebbe funzionare con punti alternati', async ({ context }) => {
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
|
|
||||||
await displayPage.goto('http://localhost:3000');
|
await resetGame(controllerPage);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
// Reset
|
|
||||||
await controllerPage.getByText(/Reset/i).first().click();
|
|
||||||
const btnConfirm = controllerPage.locator('.dialog .btn-confirm');
|
|
||||||
if (await btnConfirm.isVisible()) {
|
|
||||||
await btnConfirm.click();
|
|
||||||
}
|
|
||||||
await controllerPage.waitForTimeout(200);
|
|
||||||
|
|
||||||
// Home +1, Guest +1, Home +1
|
// Home +1, Guest +1, Home +1
|
||||||
await controllerPage.locator('.team-score.home-bg').click();
|
await controllerPage.locator('.team-score.home-bg').click();
|
||||||
|
|||||||
@@ -1,43 +1,10 @@
|
|||||||
const { test, expect } = require('@playwright/test');
|
const { test, expect } = require('@playwright/test');
|
||||||
|
const { openController, resetGame, addPoints } = require('./helpers.cjs');
|
||||||
// Helper: reset dal controller
|
|
||||||
async function resetGame(controllerPage) {
|
|
||||||
await controllerPage.getByText(/Reset/i).first().click();
|
|
||||||
const btnConfirm = controllerPage.locator('.dialog .btn-confirm');
|
|
||||||
if (await btnConfirm.isVisible()) {
|
|
||||||
await btnConfirm.click();
|
|
||||||
}
|
|
||||||
await controllerPage.waitForTimeout(300);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper: incrementa punti per una squadra N volte
|
|
||||||
async function addPoints(controllerPage, team, count) {
|
|
||||||
const selector = team === 'home' ? '.team-score.home-bg' : '.team-score.guest-bg';
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
await controllerPage.locator(selector).click();
|
|
||||||
await controllerPage.waitForTimeout(30);
|
|
||||||
}
|
|
||||||
await controllerPage.waitForTimeout(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper: assegna un set a una squadra (25 punti + click SET)
|
|
||||||
async function winSet(controllerPage, team) {
|
|
||||||
await addPoints(controllerPage, team, 25);
|
|
||||||
// Clicca bottone SET
|
|
||||||
const setSelector = team === 'home' ? '.btn-set.home-bg' : '.btn-set.guest-bg';
|
|
||||||
await controllerPage.locator(setSelector).click();
|
|
||||||
await controllerPage.waitForTimeout(100);
|
|
||||||
// Reset punti per il prossimo set
|
|
||||||
// (in questo gioco i punti non si resettano automaticamente, serve reset manuale
|
|
||||||
// o il controller gestisce il prossimo set manualmente)
|
|
||||||
}
|
|
||||||
|
|
||||||
test.describe('Full Match Simulation', () => {
|
test.describe('Full Match Simulation', () => {
|
||||||
|
|
||||||
test('Partita 2/3: Home vince 2 set a 0', async ({ context }) => {
|
test('Partita 2/3: Home vince il primo set', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
await resetGame(controllerPage);
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
@@ -54,18 +21,19 @@ test.describe('Full Match Simulation', () => {
|
|||||||
// Verifica punteggio 25
|
// Verifica punteggio 25
|
||||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('25');
|
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('25');
|
||||||
|
|
||||||
// Incrementa set Home
|
// A 25-0 compare automaticamente il dialog "SET VINTO": vai al set successivo
|
||||||
await controllerPage.locator('.btn-set.home-bg').click();
|
await controllerPage.waitForSelector('.dialog-winner');
|
||||||
await controllerPage.waitForTimeout(100);
|
await controllerPage.getByText('VAI AL SET SUCCESSIVO').click();
|
||||||
|
// doNuovoSet riapre il dialog di configurazione: chiudilo
|
||||||
|
await controllerPage.locator('.dialog-config .btn-cancel').click();
|
||||||
|
await controllerPage.waitForTimeout(200);
|
||||||
|
|
||||||
// Verifica set 1 per Home
|
// Verifica set 1 per Home
|
||||||
await expect(controllerPage.locator('.team-score.home-bg .team-set')).toContainText('SET 1');
|
await expect(controllerPage.locator('.team-score.home-bg .team-set')).toContainText('SET 1');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Set decisivo 2/3: vittoria a 15 punti', async ({ context }) => {
|
test('Set decisivo 2/3: vittoria a 15 punti', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
await resetGame(controllerPage);
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
@@ -92,17 +60,12 @@ test.describe('Full Match Simulation', () => {
|
|||||||
// Verifica punteggio 15 (e il set è decisivo: dopo 15 punti il gioco è vinto)
|
// Verifica punteggio 15 (e il set è decisivo: dopo 15 punti il gioco è vinto)
|
||||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('15');
|
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('15');
|
||||||
|
|
||||||
// Verifica che non si possono aggiungere altri punti (vittoria)
|
// A 15 nel set decisivo scatta la vittoria: compare il dialog (PARTITA FINITA)
|
||||||
await controllerPage.locator('.team-score.home-bg').click();
|
await expect(controllerPage.locator('.dialog-winner')).toBeVisible();
|
||||||
await controllerPage.waitForTimeout(100);
|
|
||||||
// Dovrebbe restare 15 (checkVittoria blocca incPunt)
|
|
||||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('15');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Set normale: punti oltre 25 fino ai vantaggi', async ({ context }) => {
|
test('Set normale: punti oltre 25 fino ai vantaggi', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
await resetGame(controllerPage);
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
@@ -123,9 +86,7 @@ test.describe('Full Match Simulation', () => {
|
|||||||
await controllerPage.waitForTimeout(100);
|
await controllerPage.waitForTimeout(100);
|
||||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('26');
|
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('26');
|
||||||
|
|
||||||
// 26-24 è vittoria → non si possono più aggiungere punti
|
// 26-24 è vittoria → compare automaticamente il dialog SET VINTO
|
||||||
await controllerPage.locator('.team-score.home-bg').click();
|
await expect(controllerPage.locator('.dialog-winner')).toBeVisible();
|
||||||
await controllerPage.waitForTimeout(100);
|
|
||||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('26');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,22 +1,10 @@
|
|||||||
const { test, expect } = require('@playwright/test');
|
const { test, expect } = require('@playwright/test');
|
||||||
|
const { openController, openDisplay, resetGame } = require('./helpers.cjs');
|
||||||
// Helper: reset dal controller
|
|
||||||
async function resetGame(controllerPage) {
|
|
||||||
await controllerPage.getByText(/Reset/i).first().click();
|
|
||||||
const btnConfirm = controllerPage.locator('.dialog .btn-confirm');
|
|
||||||
if (await btnConfirm.isVisible()) {
|
|
||||||
await btnConfirm.click();
|
|
||||||
}
|
|
||||||
await controllerPage.waitForTimeout(300);
|
|
||||||
}
|
|
||||||
|
|
||||||
test.describe('Game Operations', () => {
|
test.describe('Game Operations', () => {
|
||||||
|
|
||||||
test('Undo: dovrebbe annullare l\'ultimo punto', async ({ context }) => {
|
test('Undo: dovrebbe annullare l\'ultimo punto', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
await resetGame(controllerPage);
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
// Incrementa Home a 1
|
// Incrementa Home a 1
|
||||||
@@ -31,9 +19,8 @@ test.describe('Game Operations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Reset: dovrebbe azzerare tutto dopo conferma', async ({ context }) => {
|
test('Reset: dovrebbe azzerare tutto dopo conferma', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
await resetGame(controllerPage);
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
// Imposta qualche punto
|
// Imposta qualche punto
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
@@ -50,12 +37,9 @@ test.describe('Game Operations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Config: dovrebbe cambiare i nomi dei team', async ({ context }) => {
|
test('Config: dovrebbe cambiare i nomi dei team', async ({ context }) => {
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
|
await resetGame(controllerPage);
|
||||||
await displayPage.goto('http://localhost:3000');
|
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
// Apri config
|
// Apri config
|
||||||
await controllerPage.getByText('Config').click();
|
await controllerPage.getByText('Config').click();
|
||||||
@@ -80,12 +64,9 @@ test.describe('Game Operations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Toggle Formazione: dovrebbe mostrare la formazione sul display', async ({ context }) => {
|
test('Toggle Formazione: dovrebbe mostrare la formazione sul display', async ({ context }) => {
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
|
await resetGame(controllerPage);
|
||||||
await displayPage.goto('http://localhost:3000');
|
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
// Inizialmente mostra punteggio, non formazione
|
// Inizialmente mostra punteggio, non formazione
|
||||||
await expect(displayPage.locator('.punteggio-container')).toBeVisible();
|
await expect(displayPage.locator('.punteggio-container')).toBeVisible();
|
||||||
@@ -99,12 +80,9 @@ test.describe('Game Operations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Toggle Striscia: dovrebbe nascondere/mostrare la striscia', async ({ context }) => {
|
test('Toggle Striscia: dovrebbe nascondere/mostrare la striscia', async ({ context }) => {
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
|
await resetGame(controllerPage);
|
||||||
await displayPage.goto('http://localhost:3000');
|
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
// Inizialmente la striscia è visibile
|
// Inizialmente la striscia è visibile
|
||||||
await expect(displayPage.locator('.striscia')).toBeVisible();
|
await expect(displayPage.locator('.striscia')).toBeVisible();
|
||||||
@@ -121,12 +99,8 @@ test.describe('Game Operations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Cambi: dovrebbe effettuare una sostituzione giocatore', async ({ context }) => {
|
test('Cambi: dovrebbe effettuare una sostituzione giocatore', async ({ context }) => {
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
|
|
||||||
await displayPage.goto('http://localhost:3000');
|
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
await resetGame(controllerPage);
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
@@ -156,9 +130,7 @@ test.describe('Game Operations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Cambi: dovrebbe mostrare errore per giocatore non in formazione', async ({ context }) => {
|
test('Cambi: dovrebbe mostrare errore per giocatore non in formazione', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
await resetGame(controllerPage);
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
|
|||||||
@@ -1,69 +1,28 @@
|
|||||||
const { test, expect } = require('@playwright/test');
|
const { test, expect } = require('@playwright/test');
|
||||||
|
const { openController, openDisplay, resetGame, addPoints } = require('./helpers.cjs');
|
||||||
|
|
||||||
test.describe('Game Simulation', () => {
|
test.describe('Game Simulation', () => {
|
||||||
test('Simulazione Partita: Controller aggiunge punti finché non cambia il set', async ({ context }) => {
|
test('Simulazione Partita: Controller aggiunge punti finché non cambia il set', async ({ context }) => {
|
||||||
// 1. Setup Pagine
|
const displayPage = await openDisplay(context);
|
||||||
const displayPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
const controllerPage = await context.newPage();
|
|
||||||
|
|
||||||
await displayPage.goto('http://localhost:3000');
|
await resetGame(controllerPage);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
|
|
||||||
// Selettori (basati su ID ipotetici o classi, adattali al tuo HTML reale)
|
// Porta Home a 25: in ControllerPage il click su .team-score.home-bg
|
||||||
// Assumo che nel DOM ci siano elementi con ID o classi riconoscibili
|
// incrementa i punti home. A 25-0 scatta la vittoria del set.
|
||||||
// E che i punteggi siano visibili.
|
await addPoints(controllerPage, 'home', 25);
|
||||||
|
|
||||||
// Pulisco lo stato iniziale (reset)
|
// A 25-0 compare automaticamente il dialog "SET VINTO"
|
||||||
const btnReset = controllerPage.getByText(/Reset/i).first();
|
|
||||||
if (await btnReset.isVisible()) {
|
|
||||||
await btnReset.click();
|
|
||||||
// La modale di conferma ha un bottone "SI" con classe .btn-confirm
|
|
||||||
const btnConfirmReset = controllerPage.locator('.dialog .btn-confirm').getByText('SI');
|
|
||||||
if (await btnConfirmReset.isVisible()) {
|
|
||||||
await btnConfirmReset.click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Loop per vincere il primo set (25 punti)
|
|
||||||
// In ControllerPage.vue, il click su .team-score.home-bg incrementa i punti home
|
|
||||||
const btnHomeScore = controllerPage.locator('.team-score.home-bg');
|
|
||||||
|
|
||||||
for (let i = 0; i < 25; i++) {
|
|
||||||
await btnHomeScore.click();
|
|
||||||
// Piccola pausa per lasciare tempo al server di processare e broadcastare
|
|
||||||
//await displayPage.waitForTimeout(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Verifica Vittoria Set
|
|
||||||
// I punti dovrebbero essere tornati a 0 (o mostrare 25 prima del reset manuale?)
|
|
||||||
// Il codice gameState dice: checkVittoria -> resetta solo se qualcuno chiama resetta?
|
|
||||||
// No, checkVittoria è boolean. applyAction('incPunt') incrementa.
|
|
||||||
// Se vince, il set incrementa? 'incPunt' non incrementa i set in automatico nel codice gameState checkato prima!
|
|
||||||
// Controllo applyAction:
|
|
||||||
// "s.sp.punt[team]++" ... POI "checkVittoria(s)" all'inizio del prossimo incPunt?
|
|
||||||
// NO: "if (checkVittoria(s)) break" all'inizio di incPunt impedisce di andare oltre 25 se già vinto.
|
|
||||||
// MA 'incSet' è un'azione separata!
|
|
||||||
|
|
||||||
// Aspetta, la logica standard è: arrivo a 25 -> vinco set?
|
|
||||||
// In questo codice `gameState.js` NON c'è automatismo "arrivo a 25 -> set++ e palla al centro".
|
|
||||||
// L'utente deve cliccare "SET Antoniana" manualmente?
|
|
||||||
// Guardiamo ControllerPage.vue:
|
|
||||||
// C'è un bottone "SET {{ state.sp.nomi.home }}" che manda { type: 'incSet', team: 'home' }
|
|
||||||
|
|
||||||
// QUINDI: Il test deve:
|
|
||||||
// 1. Arrivare a 25 pt.
|
|
||||||
// 2. Cliccare "SET HOME".
|
|
||||||
// 3. Verificare che Set Home = 1.
|
|
||||||
|
|
||||||
// Verifica che siamo a 25
|
|
||||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('25');
|
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('25');
|
||||||
|
await controllerPage.waitForSelector('.dialog-winner');
|
||||||
|
|
||||||
// Clicca bottone SET
|
// Procedi al set successivo: registra il set vinto da Home
|
||||||
const btnSetHome = controllerPage.locator('.btn-set.home-bg');
|
await controllerPage.getByText('VAI AL SET SUCCESSIVO').click();
|
||||||
await btnSetHome.click();
|
// doNuovoSet riapre il dialog di configurazione: chiudilo
|
||||||
|
await controllerPage.locator('.dialog-config .btn-cancel').click();
|
||||||
|
await controllerPage.waitForTimeout(300);
|
||||||
|
|
||||||
// Verifica che il set sia incrementato
|
// Verifica che il set Home sia incrementato a 1
|
||||||
// Nota: display potrebbe chiamarsi diversamente, controlliamo Controller per coerenza
|
|
||||||
await expect(controllerPage.locator('.team-score.home-bg .team-set')).toContainText('SET 1');
|
await expect(controllerPage.locator('.team-score.home-bg .team-set')).toContainText('SET 1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
// Helper condivisi per gli E2E.
|
||||||
|
// Nota: lo stato di gioco è UNICO e persistente sul server, quindi ogni test
|
||||||
|
// deve riportarlo a zero (resetGame) e gestire eventuali dialog rimasti aperti
|
||||||
|
// dal test precedente.
|
||||||
|
|
||||||
|
const CONTROLLER_URL = 'http://localhost:3000/controller';
|
||||||
|
const DISPLAY_URL = 'http://localhost:3000';
|
||||||
|
|
||||||
|
// Apre il controller in viewport portrait (layout "mobile", su cui si basano i
|
||||||
|
// selettori dei test) e attende la connessione WebSocket.
|
||||||
|
async function openController(context) {
|
||||||
|
const page = await context.newPage();
|
||||||
|
await page.setViewportSize({ width: 390, height: 844 });
|
||||||
|
await page.goto(CONTROLLER_URL);
|
||||||
|
await page.waitForSelector('.conn-bar.connected');
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apre il display.
|
||||||
|
async function openDisplay(context) {
|
||||||
|
const page = await context.newPage();
|
||||||
|
await page.goto(DISPLAY_URL);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chiude l'eventuale dialog di fine set / fine partita (può essersi aperto in
|
||||||
|
// automatico al caricamento se lo stato persistito era già "vinto").
|
||||||
|
async function chiudiDialogVittoria(page) {
|
||||||
|
if (await page.locator('.dialog-winner').isVisible().catch(() => false)) {
|
||||||
|
const chiudi = page.getByRole('button', { name: 'CHIUDI' });
|
||||||
|
if (await chiudi.isVisible().catch(() => false)) {
|
||||||
|
await chiudi.click();
|
||||||
|
} else {
|
||||||
|
await page.getByText('INDIETRO').click();
|
||||||
|
}
|
||||||
|
await page.waitForTimeout(150);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset completo dello stato dal controller:
|
||||||
|
// 1) chiude un eventuale dialog di vittoria, 2) azzera, 3) nel dialog di
|
||||||
|
// configurazione che doReset riapre, reimposta nomi di default e conferma.
|
||||||
|
// Reimpostare i nomi rende lo stato deterministico (lo stato è condiviso e
|
||||||
|
// persistente: senza questo i nomi di un test precedente "sporcano" gli altri,
|
||||||
|
// in particolare gli screenshot di visual-regression).
|
||||||
|
async function resetGame(page) {
|
||||||
|
await chiudiDialogVittoria(page);
|
||||||
|
await page.getByText(/Reset/i).first().click();
|
||||||
|
const btnConfirm = page.locator('.dialog .btn-confirm');
|
||||||
|
if (await btnConfirm.isVisible().catch(() => false)) {
|
||||||
|
await btnConfirm.click();
|
||||||
|
}
|
||||||
|
const cfg = page.locator('.dialog-config');
|
||||||
|
if (await cfg.isVisible().catch(() => false)) {
|
||||||
|
const inputs = page.locator('.dialog-config .input-field');
|
||||||
|
await inputs.first().fill('Antoniana');
|
||||||
|
await inputs.nth(1).fill('Guest');
|
||||||
|
await page.locator('.dialog-config .btn-confirm').click();
|
||||||
|
}
|
||||||
|
await page.waitForTimeout(300);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Incrementa N punti per una squadra cliccando il punteggio.
|
||||||
|
async function addPoints(page, team, count) {
|
||||||
|
const selector = team === 'home' ? '.team-score.home-bg' : '.team-score.guest-bg';
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
await page.locator(selector).click();
|
||||||
|
await page.waitForTimeout(30);
|
||||||
|
}
|
||||||
|
await page.waitForTimeout(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
CONTROLLER_URL,
|
||||||
|
DISPLAY_URL,
|
||||||
|
openController,
|
||||||
|
openDisplay,
|
||||||
|
chiudiDialogVittoria,
|
||||||
|
resetGame,
|
||||||
|
addPoints,
|
||||||
|
};
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
const { test, expect } = require('@playwright/test');
|
||||||
|
const { openController, resetGame, addPoints } = require('./helpers.cjs');
|
||||||
|
|
||||||
|
test.describe('Referto di fine partita', () => {
|
||||||
|
|
||||||
|
test('a PARTITA FINITA il bottone REFERTO apre il referto stampabile', async ({ context }) => {
|
||||||
|
// window.print() bloccherebbe il test: lo neutralizziamo (anche nel popup).
|
||||||
|
await context.addInitScript(() => { window.print = () => {}; });
|
||||||
|
|
||||||
|
const controllerPage = await openController(context);
|
||||||
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
|
// Modalità 2/3 (bastano 2 set per chiudere la partita)
|
||||||
|
await controllerPage.getByText('Config').click();
|
||||||
|
await controllerPage.waitForSelector('.dialog-config');
|
||||||
|
await controllerPage.locator('.btn-mode').getByText('2/3').click();
|
||||||
|
await controllerPage.locator('.dialog-config .btn-confirm').click();
|
||||||
|
await controllerPage.waitForTimeout(200);
|
||||||
|
|
||||||
|
// SET 1: Home a 25 → dialog SET VINTO → vai al set successivo
|
||||||
|
await addPoints(controllerPage, 'home', 25);
|
||||||
|
await controllerPage.waitForSelector('.dialog-winner');
|
||||||
|
await controllerPage.getByText('VAI AL SET SUCCESSIVO').click();
|
||||||
|
await controllerPage.locator('.dialog-config .btn-cancel').click();
|
||||||
|
await controllerPage.waitForTimeout(200);
|
||||||
|
|
||||||
|
// SET 2: Home a 25 → PARTITA FINITA
|
||||||
|
await addPoints(controllerPage, 'home', 25);
|
||||||
|
await controllerPage.waitForSelector('.dialog-winner');
|
||||||
|
|
||||||
|
const referto = controllerPage.getByRole('button', { name: 'REFERTO' });
|
||||||
|
await expect(referto).toBeVisible();
|
||||||
|
|
||||||
|
// Il click apre il referto in un nuovo popup
|
||||||
|
const [popup] = await Promise.all([
|
||||||
|
context.waitForEvent('page'),
|
||||||
|
referto.click(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Verifica il contenuto del referto
|
||||||
|
const body = popup.locator('body');
|
||||||
|
await expect(body).toContainText('Referto di Gara');
|
||||||
|
await expect(body).toContainText('Set 1');
|
||||||
|
await expect(body).toContainText('Set 2');
|
||||||
|
// Home ha vinto 2 set a 0
|
||||||
|
await expect(body).toContainText('2 – 0');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,26 +1,12 @@
|
|||||||
const { test, expect } = require('@playwright/test');
|
const { test, expect } = require('@playwright/test');
|
||||||
|
const { openController, openDisplay, resetGame, addPoints } = require('./helpers.cjs');
|
||||||
// Helper: reset dal controller
|
|
||||||
async function resetGame(controllerPage) {
|
|
||||||
await controllerPage.getByText(/Reset/i).first().click();
|
|
||||||
const btnConfirm = controllerPage.locator('.dialog .btn-confirm');
|
|
||||||
if (await btnConfirm.isVisible()) {
|
|
||||||
await btnConfirm.click();
|
|
||||||
}
|
|
||||||
await controllerPage.waitForTimeout(300);
|
|
||||||
}
|
|
||||||
|
|
||||||
test.describe('Visual Regression', () => {
|
test.describe('Visual Regression', () => {
|
||||||
|
|
||||||
test('Display: screenshot a 0-0', async ({ context }) => {
|
test('Display: screenshot a 0-0', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
|
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await displayPage.goto('http://localhost:3000');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
// Reset per stato pulito
|
|
||||||
await resetGame(controllerPage);
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
// Attende che il display riceva lo stato
|
// Attende che il display riceva lo stato
|
||||||
@@ -28,40 +14,31 @@ test.describe('Visual Regression', () => {
|
|||||||
|
|
||||||
await expect(displayPage).toHaveScreenshot('display-0-0.png', {
|
await expect(displayPage).toHaveScreenshot('display-0-0.png', {
|
||||||
maxDiffPixelRatio: 0.05,
|
maxDiffPixelRatio: 0.05,
|
||||||
|
animations: 'disabled',
|
||||||
|
mask: [displayPage.locator('.connection-status')],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Display: screenshot durante partita (15-12)', async ({ context }) => {
|
test('Display: screenshot durante partita (15-12)', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
const displayPage = await context.newPage();
|
const displayPage = await openDisplay(context);
|
||||||
|
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await displayPage.goto('http://localhost:3000');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
await resetGame(controllerPage);
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
// Porta il punteggio a 15-12
|
// Porta il punteggio a 15-12
|
||||||
for (let i = 0; i < 15; i++) {
|
await addPoints(controllerPage, 'home', 15);
|
||||||
await controllerPage.locator('.team-score.home-bg').click();
|
await addPoints(controllerPage, 'guest', 12);
|
||||||
await controllerPage.waitForTimeout(20);
|
|
||||||
}
|
|
||||||
for (let i = 0; i < 12; i++) {
|
|
||||||
await controllerPage.locator('.team-score.guest-bg').click();
|
|
||||||
await controllerPage.waitForTimeout(20);
|
|
||||||
}
|
|
||||||
await displayPage.waitForTimeout(500);
|
await displayPage.waitForTimeout(500);
|
||||||
|
|
||||||
await expect(displayPage).toHaveScreenshot('display-15-12.png', {
|
await expect(displayPage).toHaveScreenshot('display-15-12.png', {
|
||||||
maxDiffPixelRatio: 0.05,
|
maxDiffPixelRatio: 0.05,
|
||||||
|
animations: 'disabled',
|
||||||
|
mask: [displayPage.locator('.connection-status')],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Controller: screenshot stato iniziale', async ({ context }) => {
|
test('Controller: screenshot stato iniziale', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
await resetGame(controllerPage);
|
await resetGame(controllerPage);
|
||||||
|
|
||||||
await expect(controllerPage).toHaveScreenshot('controller-initial.png', {
|
await expect(controllerPage).toHaveScreenshot('controller-initial.png', {
|
||||||
@@ -70,9 +47,8 @@ test.describe('Visual Regression', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Controller: screenshot con modal config aperta', async ({ context }) => {
|
test('Controller: screenshot con modal config aperta', async ({ context }) => {
|
||||||
const controllerPage = await context.newPage();
|
const controllerPage = await openController(context);
|
||||||
await controllerPage.goto('http://localhost:3001');
|
await resetGame(controllerPage);
|
||||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
||||||
|
|
||||||
// Apri config
|
// Apri config
|
||||||
await controllerPage.getByText('Config').click();
|
await controllerPage.getByText('Config').click();
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 58 KiB |
@@ -0,0 +1,66 @@
|
|||||||
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
||||||
|
import { mkdtempSync, writeFileSync, rmSync } from 'fs'
|
||||||
|
import { tmpdir } from 'os'
|
||||||
|
import { join } from 'path'
|
||||||
|
import { createApp } from '../../server.js'
|
||||||
|
|
||||||
|
// Usiamo una dist temporanea con file marcatori, così il test non dipende da
|
||||||
|
// una build reale ed è deterministico.
|
||||||
|
let server
|
||||||
|
let baseUrl
|
||||||
|
let distDir
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
distDir = mkdtempSync(join(tmpdir(), 'segnapunti-dist-'))
|
||||||
|
writeFileSync(join(distDir, 'index.html'), 'DISPLAY_MARKER')
|
||||||
|
writeFileSync(join(distDir, 'controller.html'), 'CONTROLLER_MARKER')
|
||||||
|
writeFileSync(join(distDir, 'app.js'), 'ASSET_MARKER')
|
||||||
|
|
||||||
|
const app = createApp(distDir)
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
server = app.listen(0, () => {
|
||||||
|
baseUrl = `http://127.0.0.1:${server.address().port}`
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await new Promise((resolve) => server.close(resolve))
|
||||||
|
rmSync(distDir, { recursive: true, force: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
async function get(path) {
|
||||||
|
const res = await fetch(baseUrl + path)
|
||||||
|
return { status: res.status, body: await res.text() }
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Routing server (server.js)', () => {
|
||||||
|
it('GET / serve la pagina display', async () => {
|
||||||
|
const { status, body } = await get('/')
|
||||||
|
expect(status).toBe(200)
|
||||||
|
expect(body).toBe('DISPLAY_MARKER')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('GET /display serve la pagina display', async () => {
|
||||||
|
expect((await get('/display')).body).toBe('DISPLAY_MARKER')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('GET /display/qualsiasi serve comunque la pagina display (SPA)', async () => {
|
||||||
|
expect((await get('/display/foo/bar')).body).toBe('DISPLAY_MARKER')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('GET /controller serve la pagina controller', async () => {
|
||||||
|
expect((await get('/controller')).body).toBe('CONTROLLER_MARKER')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('GET /controller/qualsiasi serve comunque la pagina controller', async () => {
|
||||||
|
expect((await get('/controller/foo')).body).toBe('CONTROLLER_MARKER')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('serve gli asset statici dalla dist', async () => {
|
||||||
|
const { status, body } = await get('/app.js')
|
||||||
|
expect(status).toBe(200)
|
||||||
|
expect(body).toBe('ASSET_MARKER')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
|
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
|
||||||
import { setupWebSocketHandler } from '../../src/websocket-handler.js'
|
import { setupWebSocketHandler } from '../../src/websocket-handler.js'
|
||||||
|
import { punteggio } from '../../src/gameState.js'
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
|
|
||||||
|
// Il punteggio non è memorizzato nello stato: si ricava dalla striscia.
|
||||||
|
const puntHome = (state) => punteggio(state.sp.striscia).home
|
||||||
|
|
||||||
// Mock parziale di una WebSocket e del Server
|
// Mock parziale di una WebSocket e del Server
|
||||||
class MockWebSocket extends EventEmitter {
|
class MockWebSocket extends EventEmitter {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -103,7 +107,7 @@ describe('WebSocket Integration (websocket-handler.js)', () => {
|
|||||||
expect(controller.send).toHaveBeenCalled()
|
expect(controller.send).toHaveBeenCalled()
|
||||||
const sentMsg = lastSent(controller)
|
const sentMsg = lastSent(controller)
|
||||||
expect(sentMsg.type).toBe('state')
|
expect(sentMsg.type).toBe('state')
|
||||||
expect(sentMsg.state.sp.punt.home).toBe(1)
|
expect(puntHome(sentMsg.state)).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe impedire al display di inviare azioni', () => {
|
it('dovrebbe impedire al display di inviare azioni', () => {
|
||||||
@@ -182,8 +186,8 @@ describe('WebSocket Integration (websocket-handler.js)', () => {
|
|||||||
const msg1 = lastSent(display1)
|
const msg1 = lastSent(display1)
|
||||||
const msg2 = lastSent(display2)
|
const msg2 = lastSent(display2)
|
||||||
expect(msg1.type).toBe('state')
|
expect(msg1.type).toBe('state')
|
||||||
expect(msg1.state.sp.punt.home).toBe(1)
|
expect(puntHome(msg1.state)).toBe(1)
|
||||||
expect(msg2.state.sp.punt.home).toBe(1)
|
expect(puntHome(msg2.state)).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe inviare a client con readyState != OPEN', () => {
|
it('non dovrebbe inviare a client con readyState != OPEN', () => {
|
||||||
@@ -302,7 +306,7 @@ describe('WebSocket Integration (websocket-handler.js)', () => {
|
|||||||
|
|
||||||
const msg = lastSent(controller)
|
const msg = lastSent(controller)
|
||||||
expect(msg.type).toBe('state')
|
expect(msg.type).toBe('state')
|
||||||
expect(msg.state.sp.punt.home).toBe(1)
|
expect(puntHome(msg.state)).toBe(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -374,15 +378,15 @@ describe('WebSocket Integration (websocket-handler.js)', () => {
|
|||||||
describe('API pubblica', () => {
|
describe('API pubblica', () => {
|
||||||
it('getState dovrebbe restituire lo stato corrente', () => {
|
it('getState dovrebbe restituire lo stato corrente', () => {
|
||||||
const state = handler.getState()
|
const state = handler.getState()
|
||||||
expect(state.sp.punt.home).toBe(0)
|
expect(puntHome(state)).toBe(0)
|
||||||
expect(state.sp.punt.guest).toBe(0)
|
expect(punteggio(state.sp.striscia).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('setState dovrebbe sovrascrivere lo stato', () => {
|
it('setState dovrebbe sovrascrivere lo stato', () => {
|
||||||
const newState = handler.getState()
|
const newState = handler.getState()
|
||||||
newState.sp.punt.home = 99
|
newState.sp.striscia.at(-1).ris = 'hh'
|
||||||
handler.setState(newState)
|
handler.setState(newState)
|
||||||
expect(handler.getState().sp.punt.home).toBe(99)
|
expect(puntHome(handler.getState())).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('broadcastState dovrebbe inviare a tutti i client', () => {
|
it('broadcastState dovrebbe inviare a tutti i client', () => {
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
|
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
|
||||||
import { setupWebSocketHandler } from '../../src/websocket-handler.js'
|
import { setupWebSocketHandler } from '../../src/websocket-handler.js'
|
||||||
|
import { punteggio } from '../../src/gameState.js'
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
|
|
||||||
|
// Il punteggio si ricava dalla striscia, non è memorizzato nello stato.
|
||||||
|
const punt = (state) => punteggio(state.sp.striscia)
|
||||||
|
|
||||||
class MockWebSocket extends EventEmitter {
|
class MockWebSocket extends EventEmitter {
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
@@ -57,7 +61,7 @@ describe('Stress Test WebSocket', () => {
|
|||||||
expect(display.send).toHaveBeenCalled()
|
expect(display.send).toHaveBeenCalled()
|
||||||
const msg = JSON.parse(display.send.mock.calls[display.send.mock.calls.length - 1][0])
|
const msg = JSON.parse(display.send.mock.calls[display.send.mock.calls.length - 1][0])
|
||||||
expect(msg.type).toBe('state')
|
expect(msg.type).toBe('state')
|
||||||
expect(msg.state.sp.punt.home).toBe(1)
|
expect(punt(msg.state).home).toBe(1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -81,11 +85,11 @@ describe('Stress Test WebSocket', () => {
|
|||||||
// Lo stato finale dipende da checkVittoria che blocca a 25+2
|
// Lo stato finale dipende da checkVittoria che blocca a 25+2
|
||||||
// Home arriva a 25-0 → vittoria → blocca. Quindi punti home = 25
|
// Home arriva a 25-0 → vittoria → blocca. Quindi punti home = 25
|
||||||
const state = handler.getState()
|
const state = handler.getState()
|
||||||
expect(state.sp.punt.home).toBe(25)
|
expect(punt(state).home).toBe(25)
|
||||||
// Guest: non può segnare dopo vittoria? No, checkVittoria blocca solo il team che ha vinto?
|
// Guest: non può segnare dopo vittoria? No, checkVittoria blocca solo il team che ha vinto?
|
||||||
// Controlliamo: checkVittoria controlla ENTRAMBI i team.
|
// Controlliamo: checkVittoria controlla ENTRAMBI i team.
|
||||||
// A 25-0 → vittoria=true → incPunt per guest è anche bloccato
|
// A 25-0 → vittoria=true → incPunt per guest è anche bloccato
|
||||||
expect(state.sp.punt.guest).toBe(0)
|
expect(punt(state).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe garantire che tutti i display ricevano ogni update sotto carico', () => {
|
it('dovrebbe garantire che tutti i display ricevano ogni update sotto carico', () => {
|
||||||
@@ -112,7 +116,7 @@ describe('Stress Test WebSocket', () => {
|
|||||||
// Verifica stato finale su tutti i display
|
// Verifica stato finale su tutti i display
|
||||||
for (const display of displays) {
|
for (const display of displays) {
|
||||||
const lastMsg = JSON.parse(display.send.mock.calls[4][0])
|
const lastMsg = JSON.parse(display.send.mock.calls[4][0])
|
||||||
expect(lastMsg.state.sp.punt.home).toBe(5)
|
expect(punt(lastMsg.state).home).toBe(5)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,39 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest'
|
import { describe, it, expect, beforeEach } from 'vitest'
|
||||||
import { createInitialState, applyAction, checkVittoria, checkVittoriaPartita } from '../../src/gameState.js'
|
import {
|
||||||
|
createInitialState, applyAction, checkVittoria, checkVittoriaPartita,
|
||||||
|
punteggio, setVinti, servizio,
|
||||||
|
} from '../../src/gameState.js'
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// HELPER
|
||||||
|
// Lo stato non memorizza più punteggio/set/servizio direttamente:
|
||||||
|
// si ricavano dalla striscia tramite le funzioni pure esportate.
|
||||||
|
// =============================================
|
||||||
|
|
||||||
|
// Punteggio del set in corso
|
||||||
|
const puntDi = (s) => punteggio(s.sp.striscia)
|
||||||
|
// Set vinti nel match
|
||||||
|
const setDi = (s) => setVinti(s.sp.striscia)
|
||||||
|
// true se serve Home
|
||||||
|
const servDi = (s) => servizio(s.sp.striscia)
|
||||||
|
|
||||||
|
// Imposta chi serve a inizio set (set in corso a 0-0)
|
||||||
|
function setServizioIniziale(state, team) {
|
||||||
|
state.sp.striscia.at(-1).serv = team === 'home' ? 'h' : 'g'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imposta il punteggio del set in corso costruendo una ris coerente
|
||||||
|
function setPunteggio(state, home, guest) {
|
||||||
|
state.sp.striscia.at(-1).ris = 'h'.repeat(home) + 'g'.repeat(guest)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggiunge set già conclusi (vinti) PRIMA del set in corso
|
||||||
|
function setSetVinti(state, home, guest) {
|
||||||
|
const conclusi = []
|
||||||
|
for (let i = 0; i < home; i++) conclusi.push({ serv: 'h', ris: '', vinc: 'h' })
|
||||||
|
for (let i = 0; i < guest; i++) conclusi.push({ serv: 'g', ris: '', vinc: 'g' })
|
||||||
|
state.sp.striscia = [...conclusi, state.sp.striscia.at(-1)]
|
||||||
|
}
|
||||||
|
|
||||||
describe('Game Logic (gameState.js)', () => {
|
describe('Game Logic (gameState.js)', () => {
|
||||||
let state
|
let state
|
||||||
@@ -13,17 +47,17 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
// =============================================
|
// =============================================
|
||||||
describe('Stato iniziale', () => {
|
describe('Stato iniziale', () => {
|
||||||
it('dovrebbe iniziare con 0-0', () => {
|
it('dovrebbe iniziare con 0-0', () => {
|
||||||
expect(state.sp.punt.home).toBe(0)
|
expect(puntDi(state).home).toBe(0)
|
||||||
expect(state.sp.punt.guest).toBe(0)
|
expect(puntDi(state).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe avere i set a 0', () => {
|
it('dovrebbe avere i set a 0', () => {
|
||||||
expect(state.sp.set.home).toBe(0)
|
expect(setDi(state).home).toBe(0)
|
||||||
expect(state.sp.set.guest).toBe(0)
|
expect(setDi(state).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe avere servizio Home', () => {
|
it('dovrebbe avere servizio Home', () => {
|
||||||
expect(state.sp.servHome).toBe(true)
|
expect(servDi(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe avere formazione di default [1-6]', () => {
|
it('dovrebbe avere formazione di default [1-6]', () => {
|
||||||
@@ -69,43 +103,43 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
describe('incPunt', () => {
|
describe('incPunt', () => {
|
||||||
it('dovrebbe incrementare i punti Home', () => {
|
it('dovrebbe incrementare i punti Home', () => {
|
||||||
const newState = applyAction(state, { type: 'incPunt', team: 'home' })
|
const newState = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
expect(newState.sp.punt.home).toBe(1)
|
expect(puntDi(newState).home).toBe(1)
|
||||||
expect(newState.sp.punt.guest).toBe(0)
|
expect(puntDi(newState).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe incrementare i punti Guest', () => {
|
it('dovrebbe incrementare i punti Guest', () => {
|
||||||
const newState = applyAction(state, { type: 'incPunt', team: 'guest' })
|
const newState = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||||
expect(newState.sp.punt.guest).toBe(1)
|
expect(puntDi(newState).guest).toBe(1)
|
||||||
expect(newState.sp.punt.home).toBe(0)
|
expect(puntDi(newState).home).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe gestire il cambio palla (Guest segna, batteva Home)', () => {
|
it('dovrebbe gestire il cambio palla (Guest segna, batteva Home)', () => {
|
||||||
state.sp.servHome = true
|
setServizioIniziale(state, 'home')
|
||||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||||
expect(s1.sp.servHome).toBe(false)
|
expect(servDi(s1)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe gestire il cambio palla (Home segna, batteva Guest)', () => {
|
it('dovrebbe gestire il cambio palla (Home segna, batteva Guest)', () => {
|
||||||
state.sp.servHome = false
|
setServizioIniziale(state, 'guest')
|
||||||
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
expect(s1.sp.servHome).toBe(true)
|
expect(servDi(s1)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe cambiare palla se segna chi batte', () => {
|
it('non dovrebbe cambiare palla se segna chi batte', () => {
|
||||||
state.sp.servHome = true
|
setServizioIniziale(state, 'home')
|
||||||
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
expect(s1.sp.servHome).toBe(true)
|
expect(servDi(s1)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe ruotare la formazione al cambio palla', () => {
|
it('dovrebbe ruotare la formazione al cambio palla', () => {
|
||||||
state.sp.servHome = true
|
setServizioIniziale(state, 'home')
|
||||||
state.sp.form.guest = ["1", "2", "3", "4", "5", "6"]
|
state.sp.form.guest = ["1", "2", "3", "4", "5", "6"]
|
||||||
const newState = applyAction(state, { type: 'incPunt', team: 'guest' })
|
const newState = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||||
expect(newState.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
|
expect(newState.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe ruotare la formazione se non c\'è cambio palla', () => {
|
it('non dovrebbe ruotare la formazione se non c\'è cambio palla', () => {
|
||||||
state.sp.servHome = true
|
setServizioIniziale(state, 'home')
|
||||||
state.sp.form.home = ["1", "2", "3", "4", "5", "6"]
|
state.sp.form.home = ["1", "2", "3", "4", "5", "6"]
|
||||||
const newState = applyAction(state, { type: 'incPunt', team: 'home' })
|
const newState = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
expect(newState.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
expect(newState.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||||
@@ -129,10 +163,9 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe incrementare i punti dopo vittoria', () => {
|
it('non dovrebbe incrementare i punti dopo vittoria', () => {
|
||||||
state.sp.punt.home = 25
|
setPunteggio(state, 25, 23)
|
||||||
state.sp.punt.guest = 23
|
|
||||||
const s = applyAction(state, { type: 'incPunt', team: 'home' })
|
const s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
expect(s.sp.punt.home).toBe(25)
|
expect(puntDi(s).home).toBe(25)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -143,33 +176,33 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
it('dovrebbe annullare l\'ultimo punto Home', () => {
|
it('dovrebbe annullare l\'ultimo punto Home', () => {
|
||||||
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
const s2 = applyAction(s1, { type: 'decPunt' })
|
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||||
expect(s2.sp.punt.home).toBe(0)
|
expect(puntDi(s2).home).toBe(0)
|
||||||
expect(s2.sp.punt.guest).toBe(0)
|
expect(puntDi(s2).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe annullare l\'ultimo punto Guest', () => {
|
it('dovrebbe annullare l\'ultimo punto Guest', () => {
|
||||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||||
const s2 = applyAction(s1, { type: 'decPunt' })
|
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||||
expect(s2.sp.punt.home).toBe(0)
|
expect(puntDi(s2).home).toBe(0)
|
||||||
expect(s2.sp.punt.guest).toBe(0)
|
expect(puntDi(s2).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe fare nulla sullo stato iniziale', () => {
|
it('non dovrebbe fare nulla sullo stato iniziale', () => {
|
||||||
const s = applyAction(state, { type: 'decPunt' })
|
const s = applyAction(state, { type: 'decPunt' })
|
||||||
expect(s.sp.punt.home).toBe(0)
|
expect(puntDi(s).home).toBe(0)
|
||||||
expect(s.sp.punt.guest).toBe(0)
|
expect(puntDi(s).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe ripristinare il servizio dopo undo con cambio palla', () => {
|
it('dovrebbe ripristinare il servizio dopo undo con cambio palla', () => {
|
||||||
state.sp.servHome = true
|
setServizioIniziale(state, 'home')
|
||||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||||
expect(s1.sp.servHome).toBe(false)
|
expect(servDi(s1)).toBe(false)
|
||||||
const s2 = applyAction(s1, { type: 'decPunt' })
|
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||||
expect(s2.sp.servHome).toBe(true)
|
expect(servDi(s2)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe invertire la rotazione dopo undo con cambio palla', () => {
|
it('dovrebbe invertire la rotazione dopo undo con cambio palla', () => {
|
||||||
state.sp.servHome = true
|
setServizioIniziale(state, 'home')
|
||||||
state.sp.form.guest = ["1", "2", "3", "4", "5", "6"]
|
state.sp.form.guest = ["1", "2", "3", "4", "5", "6"]
|
||||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||||
expect(s1.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
|
expect(s1.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
|
||||||
@@ -188,14 +221,66 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||||
s = applyAction(s, { type: 'incPunt', team: 'guest' })
|
s = applyAction(s, { type: 'incPunt', team: 'guest' })
|
||||||
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||||
expect(s.sp.punt.home).toBe(2)
|
expect(puntDi(s).home).toBe(2)
|
||||||
expect(s.sp.punt.guest).toBe(1)
|
expect(puntDi(s).guest).toBe(1)
|
||||||
s = applyAction(s, { type: 'decPunt' })
|
s = applyAction(s, { type: 'decPunt' })
|
||||||
expect(s.sp.punt.home).toBe(1)
|
expect(puntDi(s).home).toBe(1)
|
||||||
s = applyAction(s, { type: 'decPunt' })
|
s = applyAction(s, { type: 'decPunt' })
|
||||||
expect(s.sp.punt.guest).toBe(0)
|
expect(puntDi(s).guest).toBe(0)
|
||||||
s = applyAction(s, { type: 'decPunt' })
|
s = applyAction(s, { type: 'decPunt' })
|
||||||
expect(s.sp.punt.home).toBe(0)
|
expect(puntDi(s).home).toBe(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// FORMAZIONE DI PARTENZA (formInizio)
|
||||||
|
// =============================================
|
||||||
|
describe('formInizio', () => {
|
||||||
|
it('dovrebbe salvare la formazione corrente al primo punto del set', () => {
|
||||||
|
const s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
|
expect(s.sp.striscia.at(-1).formInizio).toEqual({
|
||||||
|
home: ["1", "2", "3", "4", "5", "6"],
|
||||||
|
guest: ["1", "2", "3", "4", "5", "6"],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('formInizio è uno snapshot: la rotazione successiva non lo modifica', () => {
|
||||||
|
setServizioIniziale(state, 'home')
|
||||||
|
// 1° punto Home: nessun cambio palla, salva formInizio
|
||||||
|
let s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
|
// 2° punto Guest: cambio palla → ruota la formazione guest
|
||||||
|
s = applyAction(s, { type: 'incPunt', team: 'guest' })
|
||||||
|
expect(s.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
|
||||||
|
// lo snapshot resta quello iniziale
|
||||||
|
expect(s.sp.striscia.at(-1).formInizio.guest).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('decPunt che riporta il set a 0-0 cancella formInizio', () => {
|
||||||
|
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
|
expect(s1.sp.striscia.at(-1).formInizio).toBeDefined()
|
||||||
|
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||||
|
expect(s2.sp.striscia.at(-1).formInizio).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('decPunt con punti ancora presenti NON cancella formInizio', () => {
|
||||||
|
let s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||||
|
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||||
|
s = applyAction(s, { type: 'decPunt' })
|
||||||
|
expect(s.sp.striscia.at(-1).ris).toBe('h')
|
||||||
|
expect(s.sp.striscia.at(-1).formInizio).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ogni set mantiene la propria formInizio', () => {
|
||||||
|
const custom = ['7', '8', '9', '10', '11', '12']
|
||||||
|
let s = applyAction(state, { type: 'setFormazione', team: 'home', form: custom })
|
||||||
|
// primo punto del set 1: salva formInizio custom
|
||||||
|
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||||
|
// chiude il set 1 e ne apre uno nuovo (formazioni resettate a default)
|
||||||
|
s = applyAction(s, { type: 'nuovoSet', team: 'home' })
|
||||||
|
// primo punto del set 2: salva formInizio default
|
||||||
|
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||||
|
expect(s.sp.striscia[0].formInizio.home).toEqual(custom)
|
||||||
|
expect(s.sp.striscia.at(-1).formInizio.home).toEqual(['1', '2', '3', '4', '5', '6'])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -205,24 +290,27 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
describe('incSet', () => {
|
describe('incSet', () => {
|
||||||
it('dovrebbe incrementare il set Home', () => {
|
it('dovrebbe incrementare il set Home', () => {
|
||||||
const s = applyAction(state, { type: 'incSet', team: 'home' })
|
const s = applyAction(state, { type: 'incSet', team: 'home' })
|
||||||
expect(s.sp.set.home).toBe(1)
|
expect(setDi(s).home).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe incrementare il set Guest', () => {
|
it('dovrebbe incrementare il set Guest', () => {
|
||||||
const s = applyAction(state, { type: 'incSet', team: 'guest' })
|
const s = applyAction(state, { type: 'incSet', team: 'guest' })
|
||||||
expect(s.sp.set.guest).toBe(1)
|
expect(setDi(s).guest).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe fare wrap da 2 a 0', () => {
|
it('dovrebbe fare wrap da 2 a 0', () => {
|
||||||
state.sp.set.home = 2
|
let s = applyAction(state, { type: 'incSet', team: 'home' })
|
||||||
const s = applyAction(state, { type: 'incSet', team: 'home' })
|
s = applyAction(s, { type: 'incSet', team: 'home' })
|
||||||
expect(s.sp.set.home).toBe(0)
|
expect(setDi(s).home).toBe(2)
|
||||||
|
s = applyAction(s, { type: 'incSet', team: 'home' })
|
||||||
|
expect(setDi(s).home).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe incrementare da 1 a 2', () => {
|
it('dovrebbe incrementare da 1 a 2', () => {
|
||||||
state.sp.set.home = 1
|
let s = applyAction(state, { type: 'incSet', team: 'home' })
|
||||||
const s = applyAction(state, { type: 'incSet', team: 'home' })
|
expect(setDi(s).home).toBe(1)
|
||||||
expect(s.sp.set.home).toBe(2)
|
s = applyAction(s, { type: 'incSet', team: 'home' })
|
||||||
|
expect(setDi(s).home).toBe(2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -231,18 +319,16 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
// =============================================
|
// =============================================
|
||||||
describe('nuovoSet', () => {
|
describe('nuovoSet', () => {
|
||||||
it('dovrebbe incrementare il set della squadra vincente', () => {
|
it('dovrebbe incrementare il set della squadra vincente', () => {
|
||||||
state.sp.punt.home = 25
|
|
||||||
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
||||||
expect(s.sp.set.home).toBe(1)
|
expect(setDi(s).home).toBe(1)
|
||||||
expect(s.sp.set.guest).toBe(0)
|
expect(setDi(s).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe azzerare i punti', () => {
|
it('dovrebbe azzerare i punti nel nuovo set', () => {
|
||||||
state.sp.punt.home = 25
|
setPunteggio(state, 25, 10)
|
||||||
state.sp.punt.guest = 10
|
|
||||||
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
||||||
expect(s.sp.punt.home).toBe(0)
|
expect(puntDi(s).home).toBe(0)
|
||||||
expect(s.sp.punt.guest).toBe(0)
|
expect(puntDi(s).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe aggiungere un nuovo set vuoto alla striscia', () => {
|
it('dovrebbe aggiungere un nuovo set vuoto alla striscia', () => {
|
||||||
@@ -268,37 +354,35 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
|
|
||||||
it('dovrebbe ignorare team non valido', () => {
|
it('dovrebbe ignorare team non valido', () => {
|
||||||
const s = applyAction(state, { type: 'nuovoSet', team: 'invalid' })
|
const s = applyAction(state, { type: 'nuovoSet', team: 'invalid' })
|
||||||
expect(s.sp.set.home).toBe(0)
|
expect(setDi(s).home).toBe(0)
|
||||||
expect(s.sp.set.guest).toBe(0)
|
expect(setDi(s).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('in 2/3 dovrebbe registrare il set vincente senza resettare il punteggio', () => {
|
it('in 2/3 alla palla match registra il set vincente senza aprirne uno nuovo', () => {
|
||||||
state.modalitaPartita = '2/3'
|
state.modalitaPartita = '2/3'
|
||||||
state.sp.set.home = 1
|
setSetVinti(state, 1, 0)
|
||||||
state.sp.punt.home = 25
|
setPunteggio(state, 25, 18)
|
||||||
state.sp.punt.guest = 18
|
|
||||||
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
||||||
expect(s.sp.set.home).toBe(2)
|
expect(setDi(s).home).toBe(2)
|
||||||
expect(s.sp.punt.home).toBe(25)
|
expect(puntDi(s).home).toBe(25)
|
||||||
expect(s.sp.punt.guest).toBe(18)
|
expect(puntDi(s).guest).toBe(18)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('in 3/5 dovrebbe registrare il set vincente senza resettare il punteggio', () => {
|
it('in 3/5 alla palla match registra il set vincente senza aprirne uno nuovo', () => {
|
||||||
state.modalitaPartita = '3/5'
|
state.modalitaPartita = '3/5'
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 0)
|
||||||
state.sp.punt.home = 25
|
setPunteggio(state, 25, 20)
|
||||||
state.sp.punt.guest = 20
|
|
||||||
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
||||||
expect(s.sp.set.home).toBe(3)
|
expect(setDi(s).home).toBe(3)
|
||||||
expect(s.sp.punt.home).toBe(25)
|
expect(puntDi(s).home).toBe(25)
|
||||||
expect(s.sp.punt.guest).toBe(20)
|
expect(puntDi(s).guest).toBe(20)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe ignorare nuovoSet se la partita è già finita', () => {
|
it('dovrebbe ignorare nuovoSet se la partita è già finita', () => {
|
||||||
state.modalitaPartita = '2/3'
|
state.modalitaPartita = '2/3'
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 0)
|
||||||
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
const s = applyAction(state, { type: 'nuovoSet', team: 'home' })
|
||||||
expect(s.sp.set.home).toBe(2)
|
expect(setDi(s).home).toBe(2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -308,29 +392,33 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
describe('checkVittoriaPartita', () => {
|
describe('checkVittoriaPartita', () => {
|
||||||
it('in 2/3 restituisce false se nessuno ha 2 set', () => {
|
it('in 2/3 restituisce false se nessuno ha 2 set', () => {
|
||||||
state.modalitaPartita = '2/3'
|
state.modalitaPartita = '2/3'
|
||||||
state.sp.set.home = 1
|
setSetVinti(state, 1, 0)
|
||||||
state.sp.set.guest = 0
|
|
||||||
expect(checkVittoriaPartita(state)).toBe(false)
|
expect(checkVittoriaPartita(state)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('in 2/3 restituisce true se home ha 2 set', () => {
|
it('in 2/3 restituisce true se home ha 2 set', () => {
|
||||||
state.modalitaPartita = '2/3'
|
state.modalitaPartita = '2/3'
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 0)
|
||||||
expect(checkVittoriaPartita(state)).toBe(true)
|
expect(checkVittoriaPartita(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('in 3/5 restituisce false se nessuno ha 3 set', () => {
|
it('in 3/5 restituisce false se nessuno ha 3 set', () => {
|
||||||
state.modalitaPartita = '3/5'
|
state.modalitaPartita = '3/5'
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 2)
|
||||||
state.sp.set.guest = 2
|
|
||||||
expect(checkVittoriaPartita(state)).toBe(false)
|
expect(checkVittoriaPartita(state)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('in 3/5 restituisce true se guest ha 3 set', () => {
|
it('in 3/5 restituisce true se guest ha 3 set', () => {
|
||||||
state.modalitaPartita = '3/5'
|
state.modalitaPartita = '3/5'
|
||||||
state.sp.set.guest = 3
|
setSetVinti(state, 0, 3)
|
||||||
expect(checkVittoriaPartita(state)).toBe(true)
|
expect(checkVittoriaPartita(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('in amichevole restituisce sempre false', () => {
|
||||||
|
state.modalitaPartita = 'amichevole'
|
||||||
|
setSetVinti(state, 5, 0)
|
||||||
|
expect(checkVittoriaPartita(state)).toBe(false)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
@@ -338,27 +426,29 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
// =============================================
|
// =============================================
|
||||||
describe('cambiaPalla', () => {
|
describe('cambiaPalla', () => {
|
||||||
it('dovrebbe invertire il servizio a 0-0', () => {
|
it('dovrebbe invertire il servizio a 0-0', () => {
|
||||||
expect(state.sp.servHome).toBe(true)
|
expect(servDi(state)).toBe(true)
|
||||||
const s = applyAction(state, { type: 'cambiaPalla' })
|
const s = applyAction(state, { type: 'cambiaPalla' })
|
||||||
expect(s.sp.servHome).toBe(false)
|
expect(servDi(s)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe tornare a Home con doppio toggle', () => {
|
it('dovrebbe tornare a Home con doppio toggle', () => {
|
||||||
let s = applyAction(state, { type: 'cambiaPalla' })
|
let s = applyAction(state, { type: 'cambiaPalla' })
|
||||||
s = applyAction(s, { type: 'cambiaPalla' })
|
s = applyAction(s, { type: 'cambiaPalla' })
|
||||||
expect(s.sp.servHome).toBe(true)
|
expect(servDi(s)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe cambiare palla se il punteggio non è 0-0', () => {
|
it('non dovrebbe cambiare palla se il punteggio non è 0-0', () => {
|
||||||
state.sp.punt.home = 1
|
setPunteggio(state, 1, 0)
|
||||||
|
const prima = servDi(state)
|
||||||
const s = applyAction(state, { type: 'cambiaPalla' })
|
const s = applyAction(state, { type: 'cambiaPalla' })
|
||||||
expect(s.sp.servHome).toBe(true)
|
expect(servDi(s)).toBe(prima)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe cambiare palla se Guest ha punti', () => {
|
it('non dovrebbe cambiare palla se Guest ha punti', () => {
|
||||||
state.sp.punt.guest = 3
|
setPunteggio(state, 0, 3)
|
||||||
|
const prima = servDi(state)
|
||||||
const s = applyAction(state, { type: 'cambiaPalla' })
|
const s = applyAction(state, { type: 'cambiaPalla' })
|
||||||
expect(s.sp.servHome).toBe(true)
|
expect(servDi(s)).toBe(prima)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -569,44 +659,37 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
// =============================================
|
// =============================================
|
||||||
describe('checkVittoria', () => {
|
describe('checkVittoria', () => {
|
||||||
it('non dovrebbe dare vittoria a 24-24', () => {
|
it('non dovrebbe dare vittoria a 24-24', () => {
|
||||||
state.sp.punt.home = 24
|
setPunteggio(state, 24, 24)
|
||||||
state.sp.punt.guest = 24
|
|
||||||
expect(checkVittoria(state)).toBe(false)
|
expect(checkVittoria(state)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe dare vittoria a 25-23', () => {
|
it('dovrebbe dare vittoria a 25-23', () => {
|
||||||
state.sp.punt.home = 25
|
setPunteggio(state, 25, 23)
|
||||||
state.sp.punt.guest = 23
|
|
||||||
expect(checkVittoria(state)).toBe(true)
|
expect(checkVittoria(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe dare vittoria a 25-24 (serve 2 punti di scarto)', () => {
|
it('non dovrebbe dare vittoria a 25-24 (serve 2 punti di scarto)', () => {
|
||||||
state.sp.punt.home = 25
|
setPunteggio(state, 25, 24)
|
||||||
state.sp.punt.guest = 24
|
|
||||||
expect(checkVittoria(state)).toBe(false)
|
expect(checkVittoria(state)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe dare vittoria a 26-24', () => {
|
it('dovrebbe dare vittoria a 26-24', () => {
|
||||||
state.sp.punt.home = 26
|
setPunteggio(state, 26, 24)
|
||||||
state.sp.punt.guest = 24
|
|
||||||
expect(checkVittoria(state)).toBe(true)
|
expect(checkVittoria(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe dare vittoria Guest a 25-20', () => {
|
it('dovrebbe dare vittoria Guest a 25-20', () => {
|
||||||
state.sp.punt.home = 20
|
setPunteggio(state, 20, 25)
|
||||||
state.sp.punt.guest = 25
|
|
||||||
expect(checkVittoria(state)).toBe(true)
|
expect(checkVittoria(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe dare vittoria ai vantaggi (30-28)', () => {
|
it('dovrebbe dare vittoria ai vantaggi (30-28)', () => {
|
||||||
state.sp.punt.home = 30
|
setPunteggio(state, 30, 28)
|
||||||
state.sp.punt.guest = 28
|
|
||||||
expect(checkVittoria(state)).toBe(true)
|
expect(checkVittoria(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe dare vittoria ai vantaggi senza scarto (28-27)', () => {
|
it('non dovrebbe dare vittoria ai vantaggi senza scarto (28-27)', () => {
|
||||||
state.sp.punt.home = 28
|
setPunteggio(state, 28, 27)
|
||||||
state.sp.punt.guest = 27
|
|
||||||
expect(checkVittoria(state)).toBe(false)
|
expect(checkVittoria(state)).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -617,82 +700,64 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
describe('Set decisivo', () => {
|
describe('Set decisivo', () => {
|
||||||
it('modalità 3/5: set decisivo dopo 4 set totali → vittoria a 15', () => {
|
it('modalità 3/5: set decisivo dopo 4 set totali → vittoria a 15', () => {
|
||||||
state.modalitaPartita = "3/5"
|
state.modalitaPartita = "3/5"
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 2)
|
||||||
state.sp.set.guest = 2
|
setPunteggio(state, 15, 10)
|
||||||
state.sp.punt.home = 15
|
|
||||||
state.sp.punt.guest = 10
|
|
||||||
expect(checkVittoria(state)).toBe(true)
|
expect(checkVittoria(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('modalità 3/5: non vittoria a 14-10 nel set decisivo', () => {
|
it('modalità 3/5: non vittoria a 14-10 nel set decisivo', () => {
|
||||||
state.modalitaPartita = "3/5"
|
state.modalitaPartita = "3/5"
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 2)
|
||||||
state.sp.set.guest = 2
|
setPunteggio(state, 14, 10)
|
||||||
state.sp.punt.home = 14
|
|
||||||
state.sp.punt.guest = 10
|
|
||||||
expect(checkVittoria(state)).toBe(false)
|
expect(checkVittoria(state)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('modalità 3/5: vittoria a 15-13 nel set decisivo', () => {
|
it('modalità 3/5: vittoria a 15-13 nel set decisivo', () => {
|
||||||
state.modalitaPartita = "3/5"
|
state.modalitaPartita = "3/5"
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 2)
|
||||||
state.sp.set.guest = 2
|
setPunteggio(state, 15, 13)
|
||||||
state.sp.punt.home = 15
|
|
||||||
state.sp.punt.guest = 13
|
|
||||||
expect(checkVittoria(state)).toBe(true)
|
expect(checkVittoria(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('modalità 3/5: non vittoria a 15-14 nel set decisivo (serve scarto)', () => {
|
it('modalità 3/5: non vittoria a 15-14 nel set decisivo (serve scarto)', () => {
|
||||||
state.modalitaPartita = "3/5"
|
state.modalitaPartita = "3/5"
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 2)
|
||||||
state.sp.set.guest = 2
|
setPunteggio(state, 15, 14)
|
||||||
state.sp.punt.home = 15
|
|
||||||
state.sp.punt.guest = 14
|
|
||||||
expect(checkVittoria(state)).toBe(false)
|
expect(checkVittoria(state)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('modalità 3/5: vittoria a 16-14 nel set decisivo', () => {
|
it('modalità 3/5: vittoria a 16-14 nel set decisivo', () => {
|
||||||
state.modalitaPartita = "3/5"
|
state.modalitaPartita = "3/5"
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 2)
|
||||||
state.sp.set.guest = 2
|
setPunteggio(state, 16, 14)
|
||||||
state.sp.punt.home = 16
|
|
||||||
state.sp.punt.guest = 14
|
|
||||||
expect(checkVittoria(state)).toBe(true)
|
expect(checkVittoria(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('modalità 2/3: set decisivo dopo 2 set totali → vittoria a 15', () => {
|
it('modalità 2/3: set decisivo dopo 2 set totali → vittoria a 15', () => {
|
||||||
state.modalitaPartita = "2/3"
|
state.modalitaPartita = "2/3"
|
||||||
state.sp.set.home = 1
|
setSetVinti(state, 1, 1)
|
||||||
state.sp.set.guest = 1
|
setPunteggio(state, 15, 10)
|
||||||
state.sp.punt.home = 15
|
|
||||||
state.sp.punt.guest = 10
|
|
||||||
expect(checkVittoria(state)).toBe(true)
|
expect(checkVittoria(state)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('modalità 2/3: non vittoria a 24-20 nel set decisivo (soglia 15)', () => {
|
it('modalità 2/3: non vittoria a 14-10 nel set decisivo (soglia 15)', () => {
|
||||||
state.modalitaPartita = "2/3"
|
state.modalitaPartita = "2/3"
|
||||||
state.sp.set.home = 1
|
setSetVinti(state, 1, 1)
|
||||||
state.sp.set.guest = 1
|
setPunteggio(state, 14, 10)
|
||||||
state.sp.punt.home = 14
|
|
||||||
state.sp.punt.guest = 10
|
|
||||||
expect(checkVittoria(state)).toBe(false)
|
expect(checkVittoria(state)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('modalità 2/3: set non decisivo (1-0) → soglia 25', () => {
|
it('modalità 2/3: set non decisivo (1-0) → soglia 25', () => {
|
||||||
state.modalitaPartita = "2/3"
|
state.modalitaPartita = "2/3"
|
||||||
state.sp.set.home = 1
|
setSetVinti(state, 1, 0)
|
||||||
state.sp.set.guest = 0
|
setPunteggio(state, 15, 10)
|
||||||
state.sp.punt.home = 15
|
|
||||||
state.sp.punt.guest = 10
|
|
||||||
expect(checkVittoria(state)).toBe(false)
|
expect(checkVittoria(state)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('modalità 3/5: set non decisivo (2-1) → soglia 25', () => {
|
it('modalità 3/5: set non decisivo (2-1) → soglia 25', () => {
|
||||||
state.modalitaPartita = "3/5"
|
state.modalitaPartita = "3/5"
|
||||||
state.sp.set.home = 2
|
setSetVinti(state, 2, 1)
|
||||||
state.sp.set.guest = 1
|
setPunteggio(state, 15, 10)
|
||||||
state.sp.punt.home = 15
|
|
||||||
state.sp.punt.guest = 10
|
|
||||||
expect(checkVittoria(state)).toBe(false)
|
expect(checkVittoria(state)).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -702,15 +767,13 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
// =============================================
|
// =============================================
|
||||||
describe('Reset', () => {
|
describe('Reset', () => {
|
||||||
it('dovrebbe resettare punti e set a zero', () => {
|
it('dovrebbe resettare punti e set a zero', () => {
|
||||||
state.sp.punt.home = 10
|
setSetVinti(state, 1, 1)
|
||||||
state.sp.punt.guest = 8
|
setPunteggio(state, 10, 8)
|
||||||
state.sp.set.home = 1
|
|
||||||
state.sp.set.guest = 1
|
|
||||||
const s = applyAction(state, { type: 'resetta' })
|
const s = applyAction(state, { type: 'resetta' })
|
||||||
expect(s.sp.punt.home).toBe(0)
|
expect(puntDi(s).home).toBe(0)
|
||||||
expect(s.sp.punt.guest).toBe(0)
|
expect(puntDi(s).guest).toBe(0)
|
||||||
expect(s.sp.set.home).toBe(0)
|
expect(setDi(s).home).toBe(0)
|
||||||
expect(s.sp.set.guest).toBe(0)
|
expect(setDi(s).guest).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe resettare formazioni a default', () => {
|
it('dovrebbe resettare formazioni a default', () => {
|
||||||
@@ -721,7 +784,7 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe resettare la striscia a un set vuoto', () => {
|
it('dovrebbe resettare la striscia a un set vuoto', () => {
|
||||||
state.sp.striscia = [{ serv: 'h', ris: 'hgh' }, { serv: 'h', ris: 'g' }]
|
state.sp.striscia = [{ serv: 'h', ris: 'hgh', vinc: 'h' }, { serv: 'h', ris: 'g', vinc: null }]
|
||||||
const s = applyAction(state, { type: 'resetta' })
|
const s = applyAction(state, { type: 'resetta' })
|
||||||
expect(s.sp.striscia).toHaveLength(1)
|
expect(s.sp.striscia).toHaveLength(1)
|
||||||
expect(s.sp.striscia[0].ris).toBe('')
|
expect(s.sp.striscia[0].ris).toBe('')
|
||||||
@@ -748,8 +811,8 @@ describe('Game Logic (gameState.js)', () => {
|
|||||||
describe('Azione sconosciuta', () => {
|
describe('Azione sconosciuta', () => {
|
||||||
it('dovrebbe restituire lo stato invariato con azione non riconosciuta', () => {
|
it('dovrebbe restituire lo stato invariato con azione non riconosciuta', () => {
|
||||||
const s = applyAction(state, { type: 'azioneInesistente' })
|
const s = applyAction(state, { type: 'azioneInesistente' })
|
||||||
expect(s.sp.punt.home).toBe(0)
|
expect(puntDi(s).home).toBe(0)
|
||||||
expect(s.sp.punt.guest).toBe(0)
|
expect(puntDi(s).guest).toBe(0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||||
|
|
||||||
|
// Mock dell'I/O su disco: i test non toccano il filesystem reale né dipendono
|
||||||
|
// dal path relativo a src/.
|
||||||
|
vi.mock('fs', () => ({
|
||||||
|
readFileSync: vi.fn(),
|
||||||
|
writeFileSync: vi.fn(),
|
||||||
|
mkdirSync: vi.fn(),
|
||||||
|
existsSync: vi.fn(),
|
||||||
|
}))
|
||||||
|
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import { loadState, saveState } from '../../src/persist.js'
|
||||||
|
import { createInitialState } from '../../src/gameState.js'
|
||||||
|
|
||||||
|
describe('Persistenza stato (persist.js)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('saveState', () => {
|
||||||
|
it('crea la directory e scrive lo stato serializzato', () => {
|
||||||
|
const state = createInitialState()
|
||||||
|
saveState(state)
|
||||||
|
|
||||||
|
expect(fs.mkdirSync).toHaveBeenCalledWith(expect.any(String), { recursive: true })
|
||||||
|
expect(fs.writeFileSync).toHaveBeenCalled()
|
||||||
|
|
||||||
|
const [, contenuto, encoding] = fs.writeFileSync.mock.calls[0]
|
||||||
|
expect(JSON.parse(contenuto)).toEqual(state)
|
||||||
|
expect(encoding).toBe('utf8')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('non lancia eccezioni se la scrittura fallisce', () => {
|
||||||
|
fs.mkdirSync.mockImplementation(() => { throw new Error('EACCES') })
|
||||||
|
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||||
|
|
||||||
|
expect(() => saveState(createInitialState())).not.toThrow()
|
||||||
|
expect(errSpy).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('loadState', () => {
|
||||||
|
it('legge e fa il parse di un file valido', () => {
|
||||||
|
const salvato = createInitialState()
|
||||||
|
salvato.sp.nomi.home = 'Squadra X'
|
||||||
|
fs.existsSync.mockReturnValue(true)
|
||||||
|
fs.readFileSync.mockReturnValue(JSON.stringify(salvato))
|
||||||
|
|
||||||
|
expect(loadState()).toEqual(salvato)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ritorna lo stato iniziale se il file non esiste', () => {
|
||||||
|
fs.existsSync.mockReturnValue(false)
|
||||||
|
expect(loadState()).toEqual(createInitialState())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ritorna lo stato iniziale se il JSON è corrotto', () => {
|
||||||
|
fs.existsSync.mockReturnValue(true)
|
||||||
|
fs.readFileSync.mockReturnValue('{ questo non è json')
|
||||||
|
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
||||||
|
|
||||||
|
expect(loadState()).toEqual(createInitialState())
|
||||||
|
expect(warnSpy).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { buildRefertoHtml } from '../../src/referto.js'
|
||||||
|
import { createInitialState } from '../../src/gameState.js'
|
||||||
|
|
||||||
|
// Data fissa per asserzioni deterministiche
|
||||||
|
const NOW = new Date('2026-03-14T20:30:00')
|
||||||
|
|
||||||
|
// Costruisce uno stato con una striscia di set arbitraria
|
||||||
|
function statoConSet(striscia, extra = {}) {
|
||||||
|
const state = createInitialState()
|
||||||
|
state.sp.striscia = striscia
|
||||||
|
state.sp.nomi = { home: 'Antoniana', guest: 'Rivali' }
|
||||||
|
return { ...state, ...extra }
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('buildRefertoHtml (referto.js)', () => {
|
||||||
|
it('esclude i set _phantom dal referto', () => {
|
||||||
|
const striscia = [
|
||||||
|
{ serv: 'h', ris: 'h'.repeat(25) + 'g'.repeat(20), vinc: 'h' },
|
||||||
|
{ serv: 'g', ris: '', vinc: 'g', _phantom: true },
|
||||||
|
{ serv: 'h', ris: 'h'.repeat(25) + 'g'.repeat(18), vinc: 'h' },
|
||||||
|
]
|
||||||
|
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||||
|
// due set reali → "Set 1" e "Set 2", mai "Set 3"
|
||||||
|
expect(html).toContain('Set 1')
|
||||||
|
expect(html).toContain('Set 2')
|
||||||
|
expect(html).not.toContain('Set 3')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calcola il punteggio finale di ogni set dalla ris', () => {
|
||||||
|
const striscia = [
|
||||||
|
{ serv: 'h', ris: 'h'.repeat(25) + 'g'.repeat(20), vinc: 'h' },
|
||||||
|
{ serv: 'h', ris: '', vinc: null },
|
||||||
|
]
|
||||||
|
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||||
|
// header del set: "Antoniana 25 · 20 Rivali"
|
||||||
|
expect(html).toContain('<strong>25</strong>')
|
||||||
|
expect(html).toContain('<strong>20</strong>')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('conta i set vinti usando vinc', () => {
|
||||||
|
const striscia = [
|
||||||
|
{ serv: 'h', ris: '', vinc: 'h' },
|
||||||
|
{ serv: 'g', ris: '', vinc: 'g' },
|
||||||
|
{ serv: 'h', ris: '', vinc: 'h' },
|
||||||
|
{ serv: 'h', ris: '', vinc: null },
|
||||||
|
]
|
||||||
|
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||||
|
// risultato 2 – 1
|
||||||
|
expect(html).toContain('2 – 1')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ricava il vincitore dal conteggio punti se vinc è nullo', () => {
|
||||||
|
const striscia = [
|
||||||
|
{ serv: 'h', ris: 'h'.repeat(25) + 'g'.repeat(23), vinc: null },
|
||||||
|
{ serv: 'h', ris: '', vinc: null },
|
||||||
|
]
|
||||||
|
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||||
|
// il primo set, pur con vinc null, conta come vinto da home → 1 – 0
|
||||||
|
expect(html).toContain('1 – 0')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('include la progressione punto-punto con classi per squadra', () => {
|
||||||
|
const striscia = [
|
||||||
|
{ serv: 'h', ris: 'hhg', vinc: null },
|
||||||
|
]
|
||||||
|
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||||
|
expect(html).toContain('punto-h')
|
||||||
|
expect(html).toContain('punto-g')
|
||||||
|
expect(html).toContain('1-0')
|
||||||
|
expect(html).toContain('2-0')
|
||||||
|
expect(html).toContain('2-1')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('rende la formazione di partenza quando presente', () => {
|
||||||
|
const striscia = [
|
||||||
|
{
|
||||||
|
serv: 'h', ris: 'h', vinc: null,
|
||||||
|
formInizio: { home: ['4', '8', '15'], guest: ['16', '23', '42'] },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||||
|
expect(html).toContain('Formazione di partenza')
|
||||||
|
expect(html).toContain('>4<')
|
||||||
|
expect(html).toContain('>42<')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('mostra "non disponibile" se manca formInizio', () => {
|
||||||
|
const striscia = [{ serv: 'h', ris: 'h', vinc: null }]
|
||||||
|
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||||
|
expect(html).toContain('non disponibile')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('mostra "Nessun punto registrato" per un set senza punti', () => {
|
||||||
|
const striscia = [{ serv: 'h', ris: '', vinc: null }]
|
||||||
|
const html = buildRefertoHtml(statoConSet(striscia), NOW)
|
||||||
|
expect(html).toContain('Nessun punto registrato')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('header contiene nomi squadre, modalità e data iniettata', () => {
|
||||||
|
const striscia = [{ serv: 'h', ris: '', vinc: null }]
|
||||||
|
const state = statoConSet(striscia)
|
||||||
|
state.modalitaPartita = '2/3'
|
||||||
|
const html = buildRefertoHtml(state, NOW)
|
||||||
|
expect(html).toContain('Antoniana')
|
||||||
|
expect(html).toContain('Rivali')
|
||||||
|
expect(html).toContain('Modalità: 2/3')
|
||||||
|
expect(html).toContain('14/03/2026')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
import { describe, it, expect, vi, afterEach } from 'vitest'
|
import { describe, it, expect, vi, afterEach } from 'vitest'
|
||||||
import * as os from 'os'
|
import { getNetworkIPs, collectIPs, printServerInfo } from '../../src/server-utils.js'
|
||||||
|
|
||||||
vi.mock('os', async (importOriginal) => {
|
// Nota: gli IP vengono iniettati nei test (oggetto stile os.networkInterfaces o
|
||||||
return {
|
// array di IP), così i risultati sono deterministici su qualsiasi piattaforma —
|
||||||
...await importOriginal(),
|
// incluso WSL, dove getNetworkIPs() userebbe altrimenti PowerShell.
|
||||||
networkInterfaces: vi.fn(() => ({}))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
import { getNetworkIPs, printServerInfo } from '../../src/server-utils.js'
|
|
||||||
|
|
||||||
describe('Server Utils', () => {
|
describe('Server Utils', () => {
|
||||||
|
|
||||||
@@ -17,85 +12,73 @@ describe('Server Utils', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
// getNetworkIPs
|
// getNetworkIPs / collectIPs
|
||||||
// =============================================
|
// =============================================
|
||||||
describe('getNetworkIPs', () => {
|
describe('getNetworkIPs', () => {
|
||||||
it('dovrebbe restituire indirizzi IPv4 non-loopback', () => {
|
it('dovrebbe restituire indirizzi IPv4 non-loopback', () => {
|
||||||
os.networkInterfaces.mockReturnValue({
|
expect(getNetworkIPs({
|
||||||
eth0: [
|
eth0: [{ family: 'IPv4', internal: false, address: '192.168.1.100' }]
|
||||||
{ family: 'IPv4', internal: false, address: '192.168.1.100' }
|
})).toEqual(['192.168.1.100'])
|
||||||
]
|
|
||||||
})
|
|
||||||
expect(getNetworkIPs()).toEqual(['192.168.1.100'])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe escludere indirizzi loopback (internal)', () => {
|
it('dovrebbe escludere indirizzi loopback (internal)', () => {
|
||||||
os.networkInterfaces.mockReturnValue({
|
const ips = getNetworkIPs({
|
||||||
lo: [
|
lo: [{ family: 'IPv4', internal: true, address: '127.0.0.1' }],
|
||||||
{ family: 'IPv4', internal: true, address: '127.0.0.1' }
|
eth0: [{ family: 'IPv4', internal: false, address: '192.168.1.100' }]
|
||||||
],
|
|
||||||
eth0: [
|
|
||||||
{ family: 'IPv4', internal: false, address: '192.168.1.100' }
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
const ips = getNetworkIPs()
|
|
||||||
expect(ips).not.toContain('127.0.0.1')
|
expect(ips).not.toContain('127.0.0.1')
|
||||||
expect(ips).toContain('192.168.1.100')
|
expect(ips).toContain('192.168.1.100')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe escludere indirizzi IPv6', () => {
|
it('dovrebbe escludere indirizzi IPv6', () => {
|
||||||
os.networkInterfaces.mockReturnValue({
|
const ips = getNetworkIPs({
|
||||||
eth0: [
|
eth0: [
|
||||||
{ family: 'IPv6', internal: false, address: 'fe80::1' },
|
{ family: 'IPv6', internal: false, address: 'fe80::1' },
|
||||||
{ family: 'IPv4', internal: false, address: '192.168.1.100' }
|
{ family: 'IPv4', internal: false, address: '192.168.1.100' }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
const ips = getNetworkIPs()
|
|
||||||
expect(ips).toEqual(['192.168.1.100'])
|
expect(ips).toEqual(['192.168.1.100'])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe escludere bridge Docker 172.17.x.x', () => {
|
it('dovrebbe escludere bridge Docker 172.17.x.x', () => {
|
||||||
os.networkInterfaces.mockReturnValue({
|
const ips = getNetworkIPs({
|
||||||
docker0: [
|
docker0: [{ family: 'IPv4', internal: false, address: '172.17.0.1' }],
|
||||||
{ family: 'IPv4', internal: false, address: '172.17.0.1' }
|
eth0: [{ family: 'IPv4', internal: false, address: '10.0.0.5' }]
|
||||||
],
|
|
||||||
eth0: [
|
|
||||||
{ family: 'IPv4', internal: false, address: '10.0.0.5' }
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
const ips = getNetworkIPs()
|
|
||||||
expect(ips).not.toContain('172.17.0.1')
|
expect(ips).not.toContain('172.17.0.1')
|
||||||
expect(ips).toContain('10.0.0.5')
|
expect(ips).toContain('10.0.0.5')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe escludere bridge Docker 172.18.x.x', () => {
|
it('dovrebbe escludere bridge Docker 172.18.x.x', () => {
|
||||||
os.networkInterfaces.mockReturnValue({
|
expect(getNetworkIPs({
|
||||||
br0: [
|
br0: [{ family: 'IPv4', internal: false, address: '172.18.0.1' }]
|
||||||
{ family: 'IPv4', internal: false, address: '172.18.0.1' }
|
})).toEqual([])
|
||||||
]
|
})
|
||||||
})
|
|
||||||
expect(getNetworkIPs()).toEqual([])
|
it('dovrebbe escludere indirizzi link-local 169.254.x.x', () => {
|
||||||
|
expect(getNetworkIPs({
|
||||||
|
eth0: [{ family: 'IPv4', internal: false, address: '169.254.1.1' }]
|
||||||
|
})).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe restituire array vuoto se nessuna interfaccia disponibile', () => {
|
it('dovrebbe restituire array vuoto se nessuna interfaccia disponibile', () => {
|
||||||
os.networkInterfaces.mockReturnValue({})
|
expect(getNetworkIPs({})).toEqual([])
|
||||||
expect(getNetworkIPs()).toEqual([])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe restituire più indirizzi da interfacce diverse', () => {
|
it('dovrebbe restituire più indirizzi da interfacce diverse', () => {
|
||||||
os.networkInterfaces.mockReturnValue({
|
const ips = getNetworkIPs({
|
||||||
eth0: [
|
eth0: [{ family: 'IPv4', internal: false, address: '192.168.1.100' }],
|
||||||
{ family: 'IPv4', internal: false, address: '192.168.1.100' }
|
wlan0: [{ family: 'IPv4', internal: false, address: '192.168.1.101' }]
|
||||||
],
|
|
||||||
wlan0: [
|
|
||||||
{ family: 'IPv4', internal: false, address: '192.168.1.101' }
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
const ips = getNetworkIPs()
|
|
||||||
expect(ips).toHaveLength(2)
|
expect(ips).toHaveLength(2)
|
||||||
expect(ips).toContain('192.168.1.100')
|
expect(ips).toContain('192.168.1.100')
|
||||||
expect(ips).toContain('192.168.1.101')
|
expect(ips).toContain('192.168.1.101')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('collectIPs gestisce input vuoto/undefined senza errori', () => {
|
||||||
|
expect(collectIPs()).toEqual([])
|
||||||
|
expect(collectIPs({})).toEqual([])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
@@ -103,9 +86,8 @@ describe('Server Utils', () => {
|
|||||||
// =============================================
|
// =============================================
|
||||||
describe('printServerInfo', () => {
|
describe('printServerInfo', () => {
|
||||||
it('dovrebbe stampare la porta di default (3000)', () => {
|
it('dovrebbe stampare la porta di default (3000)', () => {
|
||||||
os.networkInterfaces.mockReturnValue({})
|
|
||||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||||
printServerInfo()
|
printServerInfo(3000, [])
|
||||||
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
||||||
expect(allLogs).toContain('3000')
|
expect(allLogs).toContain('3000')
|
||||||
expect(allLogs).toContain('/display')
|
expect(allLogs).toContain('/display')
|
||||||
@@ -114,22 +96,16 @@ describe('Server Utils', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe stampare la porta personalizzata', () => {
|
it('dovrebbe stampare la porta personalizzata', () => {
|
||||||
os.networkInterfaces.mockReturnValue({})
|
|
||||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||||
printServerInfo(8080)
|
printServerInfo(8080, [])
|
||||||
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
||||||
expect(allLogs).toContain('8080')
|
expect(allLogs).toContain('8080')
|
||||||
consoleSpy.mockRestore()
|
consoleSpy.mockRestore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dovrebbe mostrare gli URL remoti se ci sono IP di rete', () => {
|
it('dovrebbe mostrare gli URL remoti se ci sono IP di rete', () => {
|
||||||
os.networkInterfaces.mockReturnValue({
|
|
||||||
eth0: [
|
|
||||||
{ family: 'IPv4', internal: false, address: '192.168.1.50' }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||||
printServerInfo(3000)
|
printServerInfo(3000, ['192.168.1.50'])
|
||||||
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
||||||
expect(allLogs).toContain('192.168.1.50')
|
expect(allLogs).toContain('192.168.1.50')
|
||||||
expect(allLogs).toContain('remoti')
|
expect(allLogs).toContain('remoti')
|
||||||
@@ -137,9 +113,8 @@ describe('Server Utils', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('non dovrebbe mostrare sezione remoti se nessun IP di rete', () => {
|
it('non dovrebbe mostrare sezione remoti se nessun IP di rete', () => {
|
||||||
os.networkInterfaces.mockReturnValue({})
|
|
||||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||||
printServerInfo(3000)
|
printServerInfo(3000, [])
|
||||||
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
||||||
expect(allLogs).not.toContain('remoti')
|
expect(allLogs).not.toContain('remoti')
|
||||||
consoleSpy.mockRestore()
|
consoleSpy.mockRestore()
|
||||||
|
|||||||