Compare commits
5 Commits
71119da727
...
aa88e2b7a1
| Author | SHA1 | Date | |
|---|---|---|---|
| aa88e2b7a1 | |||
| e4d212eea3 | |||
| 33e2583b4d | |||
| be286ec069 | |||
| 0b154d9e56 |
275
README.md
@@ -6,34 +6,39 @@ Applicazione web **Progressive Web App (PWA)** per tracciare i punteggi di parti
|
||||
|
||||
## Panoramica
|
||||
|
||||
**Segnapunti Anto** è un'applicazione digitale per il tracciamento dei punteggi durante partite di pallavolo, ottimizzata per l'uso su tablet e smartphone. Sviluppata per il team Antoniana, l'app fornisce un'interfaccia fullscreen touch-friendly con supporto offline e controlli da tastiera.
|
||||
**Segnapunti Anto** e un'applicazione digitale per il tracciamento del punteggio durante partite di pallavolo, ottimizzata per tablet e smartphone.
|
||||
|
||||
### Funzionalità Principali
|
||||
L'app e composta da due interfacce:
|
||||
- **Display** (tabellone pubblico)
|
||||
- **Controller** (pannello operatore)
|
||||
|
||||
- **Gestione Completa Partite**
|
||||
- Tracciamento punti in tempo reale per entrambe le squadre
|
||||
- Conteggio automatico dei set (modalità 2/3 o 3/5)
|
||||
- Indicatore visivo del servizio
|
||||
- Blocco incremento punti a set concluso
|
||||
- Cronologia punti con striscia visiva
|
||||
Le due interfacce condividono lo stato in tempo reale tramite WebSocket.
|
||||
|
||||
- **Formazioni Squadra**
|
||||
- Visualizzazione interattiva dei 6 giocatori in campo
|
||||
- Rotazione automatica regolamentare al cambio palla
|
||||
- Configurazione manuale dei numeri di maglia
|
||||
- Dialog cambi con uno o due cambi (IN → OUT) e validazioni
|
||||
- Supporto logica pallavolo ufficiale (25 punti + 2 di vantaggio, tie-break a 15 nel set decisivo)
|
||||
### Funzionalita Principali
|
||||
|
||||
- **Controlli Multimodali**
|
||||
- Scorciatoie da tastiera complete (vedi sezione [Shortcuts](#shortcuts))
|
||||
- Sintesi vocale per annunci punteggio in italiano (Web Speech API)
|
||||
- **Gestione partita in tempo reale**
|
||||
- Tracciamento punti home/guest
|
||||
- Gestione set
|
||||
- Indicatore servizio
|
||||
- Storico punti (striscia)
|
||||
- Blocchi logici quando il set e gia vinto
|
||||
|
||||
- **Personalizzazione**
|
||||
- Configurazione dinamica nomi squadre
|
||||
- Selettore modalità partita: al meglio di 3 o al meglio di 5
|
||||
- Toggle layout orizzontale (inverti home/guest)
|
||||
- Modalità visualizzazione: punteggio semplice o formazioni complete
|
||||
- Nascondi/mostra controlli e cronologia
|
||||
- **Regole pallavolo integrate**
|
||||
- Set normali: vittoria a 25 con almeno 2 punti di scarto
|
||||
- Set decisivo: vittoria a 15 con almeno 2 punti di scarto
|
||||
- Modalita partita `2/3` o `3/5`
|
||||
|
||||
- **Formazioni e cambi**
|
||||
- Gestione formazione a 6 giocatori
|
||||
- Rotazione automatica al cambio palla
|
||||
- Dialog cambi con validazioni (`IN -> OUT`)
|
||||
|
||||
- **Controlli e personalizzazione**
|
||||
- Configurazione nomi squadre
|
||||
- Toggle ordine squadre (inverti)
|
||||
- Toggle visualizzazione punteggio/formazioni
|
||||
- Toggle striscia storico
|
||||
- Sintesi vocale punteggio (Web Speech API)
|
||||
|
||||
---
|
||||
|
||||
@@ -42,33 +47,41 @@ Applicazione web **Progressive Web App (PWA)** per tracciare i punteggi di parti
|
||||
### Requisiti di Sistema
|
||||
|
||||
#### Per Sviluppo
|
||||
- **Sistema Operativo**: Linux, macOS, Windows (WSL2 consigliato)
|
||||
- **Node.js**: v20.2.0 o superiore (LTS consigliato)
|
||||
- **npm**: v9.0.0 o superiore (incluso con Node.js)
|
||||
- **RAM**: Minimo 2GB, consigliato 4GB
|
||||
- **Spazio Disco**: ~500MB per dipendenze e build
|
||||
- **Sistema Operativo**: Linux, macOS, Windows
|
||||
- **Node.js**: `>= 18.19.0` (consigliato `20 LTS`)
|
||||
- **npm**: `>= 9`
|
||||
- **RAM**: minimo 2GB (consigliato 4GB)
|
||||
|
||||
#### Per Deployment
|
||||
- **Server Web**: Qualsiasi server statico (nginx, Apache, Vercel, Netlify)
|
||||
- **HTTPS**: Obbligatorio per Service Worker e PWA (eccetto localhost)
|
||||
- **Connessione Internet**: Solo per primo caricamento (poi funziona offline)
|
||||
#### Per Esecuzione Test E2E
|
||||
- Browser Playwright installati (`chromium`, `firefox`)
|
||||
- Su Linux, eventuali dipendenze sistema per browser headless
|
||||
|
||||
Comandi utili:
|
||||
|
||||
```bash
|
||||
node -v
|
||||
npm -v
|
||||
npx playwright install chromium firefox
|
||||
# Linux, se necessario:
|
||||
# npx playwright install --with-deps chromium firefox
|
||||
```
|
||||
|
||||
### Requisiti Browser (Utente Finale)
|
||||
|
||||
| Requisito | Dettaglio | Necessità |
|
||||
| Requisito | Dettaglio | Necessita |
|
||||
|-----------|-----------|-----------|
|
||||
| **JavaScript ES6+** | Supporto moduli, arrow functions, async/await | Obbligatorio |
|
||||
| **Service Worker API** | Per funzionalità offline PWA | Obbligatorio |
|
||||
| **Fullscreen API** | Per modalità schermo intero | Consigliato |
|
||||
| **Web Speech API** | Per sintesi vocale punteggi | Opzionale |
|
||||
| **Local Storage** | Per persistenza configurazioni | Consigliato |
|
||||
| JavaScript ES6+ | Moduli, async/await | Obbligatorio |
|
||||
| WebSocket | Sincronizzazione stato live | Obbligatorio |
|
||||
| Service Worker API | Supporto PWA offline | Consigliato |
|
||||
| Web Speech API | Annunci vocali | Opzionale |
|
||||
|
||||
### Browser Testati e Supportati
|
||||
|
||||
| Browser | Versione Minima | Supporto | Note |
|
||||
|---------|-----------------|----------|------|
|
||||
| Chrome/Chromium | 90+ | ✅ Completo | Consigliato per tutte le features |
|
||||
| Firefox | 88+ | ✅ Completo | Supporto completo PWA e Speech API |
|
||||
| Browser | Supporto | Note |
|
||||
|---------|----------|------|
|
||||
| Chrome/Chromium | ✅ | Completo |
|
||||
| Firefox | ✅ | Completo |
|
||||
| Mobile Chrome (Playwright Pixel 5) | ✅ | Copertura E2E mobile |
|
||||
|
||||
---
|
||||
|
||||
@@ -76,21 +89,14 @@ Applicazione web **Progressive Web App (PWA)** per tracciare i punteggi di parti
|
||||
|
||||
### Prerequisiti
|
||||
|
||||
- **Node.js** v20.2.0 (consigliato)
|
||||
- **npm** o **yarn**
|
||||
- Node.js `>= 18.19.0`
|
||||
- npm `>= 9`
|
||||
|
||||
### Installazione con NVM (consigliato)
|
||||
### Installazione
|
||||
|
||||
```bash
|
||||
# Installa la versione corretta di Node.js
|
||||
nvm install v20.2.0
|
||||
nvm use v20.2.0
|
||||
|
||||
# Clona il repository
|
||||
git clone <repository-url>
|
||||
git clone https://santantonio.sytes.net/attilio/segnapunti.git
|
||||
cd segnapunti
|
||||
|
||||
# Installa le dipendenze
|
||||
npm install
|
||||
```
|
||||
|
||||
@@ -100,19 +106,20 @@ npm install
|
||||
|
||||
### Dev Server
|
||||
|
||||
Avvia il server di sviluppo con hot-reload:
|
||||
Avvia il server di sviluppo Vite:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
L'applicazione sarà disponibile su [http://localhost:5173](http://localhost:5173)
|
||||
Accesso tipico in sviluppo:
|
||||
- `http://localhost:5173/` -> Display
|
||||
- `http://localhost:5173/controller.html` -> Controller
|
||||
|
||||
### Modalità Sviluppo
|
||||
- Hot Module Replacement (HMR) attivo
|
||||
- Source maps per debugging
|
||||
- Vue DevTools supportato
|
||||
- Errori e warnings in console
|
||||
### Modalita Sviluppo
|
||||
- Hot reload attivo
|
||||
- Build veloce lato Vite
|
||||
- Buona per sviluppo UI/UX
|
||||
|
||||
---
|
||||
|
||||
@@ -120,102 +127,46 @@ L'applicazione sarà disponibile su [http://localhost:5173](http://localhost:517
|
||||
|
||||
### Build Produzione
|
||||
|
||||
Genera i file ottimizzati per il deployment:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
**Output:**
|
||||
- Cartella `/dist` con file statici ottimizzati
|
||||
- Service Worker generato automaticamente
|
||||
- PWA manifest configurato
|
||||
- Assets minificati e con hash per cache busting
|
||||
- Base path: `/segnap` (modificabile in `vite.config.js`)
|
||||
Output:
|
||||
- cartella `dist/`
|
||||
- asset ottimizzati
|
||||
- file PWA (manifest + service worker)
|
||||
|
||||
### Preview Build
|
||||
### Avvio Server Applicativo Locale (Display + Controller)
|
||||
|
||||
Anteprima locale della build di produzione:
|
||||
```bash
|
||||
npm run serve
|
||||
```
|
||||
|
||||
Espone:
|
||||
- `http://localhost:3000` -> Display
|
||||
- `http://localhost:3001` -> Controller
|
||||
|
||||
### Altri comandi utili
|
||||
|
||||
```bash
|
||||
npm run preview
|
||||
npm run start
|
||||
```
|
||||
|
||||
Serve i file dalla cartella `/dist` per testare la build prima del deploy.
|
||||
|
||||
---
|
||||
|
||||
## Shortcuts
|
||||
|
||||
### Controlli Tastiera Squadra Home
|
||||
|
||||
| Scorciatoia | Azione |
|
||||
|-------------|--------|
|
||||
| `Ctrl + ↑` | Incrementa punti |
|
||||
| `Ctrl + ↓` | Decrementa punti |
|
||||
| `Ctrl + →` | Incrementa set |
|
||||
| `Ctrl + C` | Apri dialog cambi |
|
||||
|
||||
### Controlli Tastiera Squadra Guest
|
||||
|
||||
| Scorciatoia | Azione |
|
||||
|-------------|--------|
|
||||
| `Shift + ↑` | Incrementa punti |
|
||||
| `Shift + ↓` | Decrementa punti |
|
||||
| `Shift + →` | Incrementa set |
|
||||
| `Shift + C` | Apri dialog cambi |
|
||||
|
||||
### Comandi Globali
|
||||
|
||||
| Scorciatoia | Azione |
|
||||
|-------------|--------|
|
||||
| `Ctrl + ←` | Cambio palla (servizio) - **solo a 0-0** |
|
||||
| `Ctrl + M` | Apri configurazione nomi squadre e formazioni |
|
||||
| `Ctrl + B` | Toggle visibilità barra pulsanti |
|
||||
| `Ctrl + F` | Attiva/disattiva fullscreen |
|
||||
| `Ctrl + S` | Annuncio vocale punteggio corrente |
|
||||
| `Ctrl + Z` | Switch tra visualizzazione formazioni e punteggio |
|
||||
|
||||
---
|
||||
|
||||
## Configurazione PWA
|
||||
|
||||
L'applicazione è configurata come **Progressive Web App** nel file [vite.config.js](vite.config.js):
|
||||
L'app usa `vite-plugin-pwa` (vedi `vite.config.js`) con:
|
||||
- `registerType: 'autoUpdate'`
|
||||
- manifest installabile
|
||||
- orientamento landscape
|
||||
- modalita fullscreen
|
||||
|
||||
```javascript
|
||||
VitePWA({
|
||||
registerType: 'autoUpdate',
|
||||
manifest: {
|
||||
name: "app_segnap",
|
||||
short_name: "segnap",
|
||||
description: "Segnapunti standalone.",
|
||||
background_color: "#eee",
|
||||
theme_color: '#ffffff',
|
||||
display: "fullscreen",
|
||||
orientation: "landscape",
|
||||
icons: [
|
||||
{ src: 'segnap-192x192.png', sizes: '192x192', type: 'image/png' },
|
||||
{ src: 'segnap-512x512.png', sizes: '512x512', type: 'image/png' }
|
||||
]
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Caratteristiche PWA
|
||||
|
||||
- **Display**: Fullscreen per massimizzare lo spazio visivo
|
||||
- **Orientamento**: Landscape (orizzontale) ottimizzato per tablet
|
||||
- **Auto-update**: Service Worker con aggiornamento automatico
|
||||
- **Offline**: Funzionamento completo senza connessione internet
|
||||
- **Installabile**: Aggiungibile alla home screen come app nativa
|
||||
|
||||
### Installazione PWA
|
||||
|
||||
**Android/Desktop (Chrome):**
|
||||
- Menu → "Installa app" o icona (⊕) nella barra degli indirizzi
|
||||
|
||||
**iOS (Safari):**
|
||||
- Share (□↑) → "Aggiungi a Home"
|
||||
Caratteristiche principali:
|
||||
- installabile su dispositivi supportati
|
||||
- aggiornamento automatico del service worker
|
||||
- supporto utilizzo offline (in base alle risorse cache)
|
||||
|
||||
---
|
||||
|
||||
@@ -223,33 +174,35 @@ VitePWA({
|
||||
|
||||
### Vittoria Set
|
||||
|
||||
- **Set regolari (1-4)**: Primo a 25 punti con almeno 2 di vantaggio
|
||||
- **Set decisivo**:
|
||||
- Modalità 2/3: 3° set a 15 punti con almeno 2 di vantaggio
|
||||
- Modalità 3/5: 5° set a 15 punti con almeno 2 di vantaggio
|
||||
- **Blocco automatico**: Non consente assegnare punti oltre la vittoria
|
||||
- Set normali: vittoria a 25 con almeno 2 punti di scarto
|
||||
- Set decisivo: vittoria a 15 con almeno 2 punti di scarto
|
||||
- Modalita partita supportate: `2/3` e `3/5`
|
||||
|
||||
### Rotazione Formazione
|
||||
|
||||
La rotazione avviene **automaticamente** quando:
|
||||
1. La squadra **conquista il servizio** (cambio palla)
|
||||
2. Il punteggio è diverso da 0-0
|
||||
|
||||
**Limitazione cambio palla manuale:**
|
||||
- Il cambio manuale del servizio (`Ctrl + ←`) è consentito **solo a 0-0**
|
||||
- Questa limitazione previene errori nella rotazione delle formazioni
|
||||
La rotazione avviene durante i cambi palla secondo la logica implementata in `src/gameState.js`.
|
||||
|
||||
### Formazione in Campo
|
||||
|
||||
Visualizzazione a 6 posizioni standard:
|
||||
Il sistema gestisce 6 posizioni per squadra e permette cambi validati da Controller.
|
||||
|
||||
```
|
||||
Rete
|
||||
┌─────┬─────┬─────┐
|
||||
│ 4 │ 3 │ 2 │ ← Fila anteriore
|
||||
├─────┼─────┼─────┤
|
||||
│ 5 │ 6 │ 1 │ ← Fila posteriore
|
||||
└─────┴─────┴─────┘
|
||||
---
|
||||
|
||||
## Test (stato attuale)
|
||||
|
||||
Suite presenti:
|
||||
- Unit
|
||||
- Integration
|
||||
- Component
|
||||
- Stress
|
||||
- E2E (Playwright)
|
||||
|
||||
Comandi principali:
|
||||
|
||||
```bash
|
||||
npm run test:all
|
||||
npm run test:e2e
|
||||
```
|
||||
|
||||
La rotazione avviene in senso orario: 1→6→5→4→3→2→1
|
||||
Guida completa test:
|
||||
- `tests/README.md`
|
||||
|
||||
601
package-lock.json
generated
@@ -15,11 +15,14 @@
|
||||
"ws": "^8.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@axe-core/playwright": "^4.11.1",
|
||||
"@playwright/test": "^1.58.2",
|
||||
"@types/node": "^25.2.3",
|
||||
"@vitejs/plugin-vue": "^4.1.0",
|
||||
"@vitest/ui": "^4.0.18",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
"concurrently": "^9.2.1",
|
||||
"happy-dom": "^20.6.1",
|
||||
"jsdom": "^28.0.0",
|
||||
"vite": "^4.3.9",
|
||||
"vite-plugin-pwa": "^0.16.0",
|
||||
@@ -112,6 +115,18 @@
|
||||
"integrity": "sha512-n8GuYSrI9bF7FFZ/SjhwevlHc8xaVlb/7HmHelnc/PZXBD2ZR49NnN9sMMuDdEGPeeRQ5d0hqlSlEpgCX3Wl0Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@axe-core/playwright": {
|
||||
"version": "4.11.1",
|
||||
"resolved": "https://registry.npmjs.org/@axe-core/playwright/-/playwright-4.11.1.tgz",
|
||||
"integrity": "sha512-mKEfoUIB1MkVTht0BGZFXtSAEKXMJoDkyV5YZ9jbBmZCcWDz71tegNsdTkIN8zc/yMi5Gm2kx7Z5YQ9PfWNAWw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"axe-core": "~4.11.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"playwright-core": ">= 1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/code-frame": {
|
||||
"version": "7.21.4",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.21.4.tgz",
|
||||
@@ -2336,6 +2351,102 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui": {
|
||||
"version": "8.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
|
||||
"integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"string-width": "^5.1.2",
|
||||
"string-width-cjs": "npm:string-width@^4.2.0",
|
||||
"strip-ansi": "^7.0.1",
|
||||
"strip-ansi-cjs": "npm:strip-ansi@^6.0.1",
|
||||
"wrap-ansi": "^8.1.0",
|
||||
"wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/ansi-regex": {
|
||||
"version": "6.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz",
|
||||
"integrity": "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/ansi-regex?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/ansi-styles": {
|
||||
"version": "6.2.3",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
|
||||
"integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/emoji-regex": {
|
||||
"version": "9.2.2",
|
||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz",
|
||||
"integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/string-width": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
|
||||
"integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"eastasianwidth": "^0.2.0",
|
||||
"emoji-regex": "^9.2.2",
|
||||
"strip-ansi": "^7.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/strip-ansi": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.2.tgz",
|
||||
"integrity": "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-regex": "^6.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/strip-ansi?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/wrap-ansi": {
|
||||
"version": "8.1.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz",
|
||||
"integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-styles": "^6.1.0",
|
||||
"string-width": "^5.0.1",
|
||||
"strip-ansi": "^7.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/gen-mapping": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz",
|
||||
@@ -2434,6 +2545,22 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/@one-ini/wasm": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@one-ini/wasm/-/wasm-0.1.1.tgz",
|
||||
"integrity": "sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@pkgjs/parseargs": {
|
||||
"version": "0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
|
||||
"integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/@playwright/test": {
|
||||
"version": "1.58.2",
|
||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.58.2.tgz",
|
||||
@@ -2941,6 +3068,21 @@
|
||||
"integrity": "sha512-NfQ4gyz38SL8sDNrSixxU2Os1a5xcdFxipAFxYEuLUlvU2uDwS4NUpsImcf1//SlWItCVMMLiylsxbmNMToV/g==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/whatwg-mimetype": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/whatwg-mimetype/-/whatwg-mimetype-3.0.2.tgz",
|
||||
"integrity": "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/ws": {
|
||||
"version": "8.18.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
|
||||
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitejs/plugin-vue": {
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-4.2.3.tgz",
|
||||
@@ -3149,6 +3291,25 @@
|
||||
"resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.5.28.tgz",
|
||||
"integrity": "sha512-cfWa1fCGBxrvaHRhvV3Is0MgmrbSCxYTXCSCau2I0a1Xw1N1pHAvkWCiXPRAqjvToILvguNyEwjevUqAuBQWvQ=="
|
||||
},
|
||||
"node_modules/@vue/test-utils": {
|
||||
"version": "2.4.6",
|
||||
"resolved": "https://registry.npmjs.org/@vue/test-utils/-/test-utils-2.4.6.tgz",
|
||||
"integrity": "sha512-FMxEjOpYNYiFe0GkaHsnJPXFHxQ6m4t8vI/ElPGpMWxZKpmRvQ33OIrvRXemy6yha03RxhOlQuy+gZMC3CQSow==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"js-beautify": "^1.14.9",
|
||||
"vue-component-type-helpers": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/abbrev": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-2.0.0.tgz",
|
||||
"integrity": "sha512-6/mh1E2u2YgEsCHdY0Yx5oW+61gZU+1vXaoiHHrpKeuRNNgFvS+/jrwHiQhB5apAf5oB7UB7E19ol2R2LKH8hQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
|
||||
@@ -3268,6 +3429,15 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/axe-core": {
|
||||
"version": "4.11.1",
|
||||
"resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.11.1.tgz",
|
||||
"integrity": "sha512-BASOg+YwO2C+346x3LZOeoovTIoTrRqEsqMa6fmfAV0P+U9mFr9NsyOEpiYvFjbc64NMrSswhV50WdXzdb/Z5A==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/babel-plugin-polyfill-corejs2": {
|
||||
"version": "0.4.3",
|
||||
"resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.3.tgz",
|
||||
@@ -3666,6 +3836,16 @@
|
||||
"url": "https://github.com/chalk/supports-color?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/config-chain": {
|
||||
"version": "1.1.13",
|
||||
"resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.13.tgz",
|
||||
"integrity": "sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ini": "^1.3.4",
|
||||
"proto-list": "~1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/content-disposition": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.1.tgz",
|
||||
@@ -3721,6 +3901,20 @@
|
||||
"url": "https://opencollective.com/core-js"
|
||||
}
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"path-key": "^3.1.0",
|
||||
"shebang-command": "^2.0.0",
|
||||
"which": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/crypto-random-string": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz",
|
||||
@@ -3888,6 +4082,66 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/eastasianwidth": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
|
||||
"integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/editorconfig": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-1.0.4.tgz",
|
||||
"integrity": "sha512-L9Qe08KWTlqYMVvMcTIvMAdl1cDUubzRNYL+WfA4bLDMHe4nemKkpmYzkznE1FwLKu0EEmy6obgQKzMJrg4x9Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@one-ini/wasm": "0.1.1",
|
||||
"commander": "^10.0.0",
|
||||
"minimatch": "9.0.1",
|
||||
"semver": "^7.5.3"
|
||||
},
|
||||
"bin": {
|
||||
"editorconfig": "bin/editorconfig"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/editorconfig/node_modules/commander": {
|
||||
"version": "10.0.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz",
|
||||
"integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/editorconfig/node_modules/minimatch": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.1.tgz",
|
||||
"integrity": "sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"brace-expansion": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.17"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/editorconfig/node_modules/semver": {
|
||||
"version": "7.7.4",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
|
||||
"integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
@@ -4295,6 +4549,22 @@
|
||||
"is-callable": "^1.1.3"
|
||||
}
|
||||
},
|
||||
"node_modules/foreground-child": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz",
|
||||
"integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"cross-spawn": "^7.0.6",
|
||||
"signal-exit": "^4.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||
@@ -4529,6 +4799,44 @@
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/happy-dom": {
|
||||
"version": "20.6.1",
|
||||
"resolved": "https://registry.npmjs.org/happy-dom/-/happy-dom-20.6.1.tgz",
|
||||
"integrity": "sha512-+0vhESXXhFwkdjZnJ5DlmJIfUYGgIEEjzIjB+aKJbFuqlvvKyOi+XkI1fYbgYR9QCxG5T08koxsQ6HrQfa5gCQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": ">=20.0.0",
|
||||
"@types/whatwg-mimetype": "^3.0.2",
|
||||
"@types/ws": "^8.18.1",
|
||||
"entities": "^6.0.1",
|
||||
"whatwg-mimetype": "^3.0.0",
|
||||
"ws": "^8.18.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/happy-dom/node_modules/entities": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/entities/-/entities-6.0.1.tgz",
|
||||
"integrity": "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=0.12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/entities?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/happy-dom/node_modules/whatwg-mimetype": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz",
|
||||
"integrity": "sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/has": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
||||
@@ -4713,6 +5021,12 @@
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"node_modules/ini": {
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
|
||||
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/internal-slot": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.5.tgz",
|
||||
@@ -5018,6 +5332,27 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/jackspeak": {
|
||||
"version": "3.4.3",
|
||||
"resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz",
|
||||
"integrity": "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@isaacs/cliui": "^8.0.2"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@pkgjs/parseargs": "^0.11.0"
|
||||
}
|
||||
},
|
||||
"node_modules/jake": {
|
||||
"version": "10.8.7",
|
||||
"resolved": "https://registry.npmjs.org/jake/-/jake-10.8.7.tgz",
|
||||
@@ -5141,6 +5476,72 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/js-beautify": {
|
||||
"version": "1.15.4",
|
||||
"resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.15.4.tgz",
|
||||
"integrity": "sha512-9/KXeZUKKJwqCXUdBxFJ3vPh467OCckSBmYDwSK/EtV090K+iMJ7zx2S3HLVDIWFQdqMIsZWbnaGiba18aWhaA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"config-chain": "^1.1.13",
|
||||
"editorconfig": "^1.0.4",
|
||||
"glob": "^10.4.2",
|
||||
"js-cookie": "^3.0.5",
|
||||
"nopt": "^7.2.1"
|
||||
},
|
||||
"bin": {
|
||||
"css-beautify": "js/bin/css-beautify.js",
|
||||
"html-beautify": "js/bin/html-beautify.js",
|
||||
"js-beautify": "js/bin/js-beautify.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/js-beautify/node_modules/glob": {
|
||||
"version": "10.5.0",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz",
|
||||
"integrity": "sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==",
|
||||
"deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"foreground-child": "^3.1.0",
|
||||
"jackspeak": "^3.1.2",
|
||||
"minimatch": "^9.0.4",
|
||||
"minipass": "^7.1.2",
|
||||
"package-json-from-dist": "^1.0.0",
|
||||
"path-scurry": "^1.11.1"
|
||||
},
|
||||
"bin": {
|
||||
"glob": "dist/esm/bin.mjs"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/js-beautify/node_modules/minimatch": {
|
||||
"version": "9.0.5",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz",
|
||||
"integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"brace-expansion": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.17"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/js-cookie": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz",
|
||||
"integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/js-tokens": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
||||
@@ -5428,6 +5829,15 @@
|
||||
"concat-map": "0.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/minipass": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz",
|
||||
"integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/mrmime": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz",
|
||||
@@ -5473,6 +5883,21 @@
|
||||
"integrity": "sha512-QzsYKWhXTWx8h1kIvqfnC++o0pEmpRQA/aenALsL2F4pqNVr7YzcdMlDij5WBnwftRbJCNJL/O7zdKaxKPHqgQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/nopt": {
|
||||
"version": "7.2.1",
|
||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-7.2.1.tgz",
|
||||
"integrity": "sha512-taM24ViiimT/XntxbPyJQzCG+p4EKOpgD3mxFwW38mGjVUrfERQOeY4EDHjdnptttfHuHQXFx+lTP08Q+mLa/w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"abbrev": "^2.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"nopt": "bin/nopt.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/object-inspect": {
|
||||
"version": "1.13.4",
|
||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
|
||||
@@ -5540,6 +5965,12 @@
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"node_modules/package-json-from-dist": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz",
|
||||
"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/parse5": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/parse5/-/parse5-8.0.0.tgz",
|
||||
@@ -5581,12 +6012,43 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/path-key": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
|
||||
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/path-parse": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
|
||||
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/path-scurry": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz",
|
||||
"integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"lru-cache": "^10.2.0",
|
||||
"minipass": "^5.0.0 || ^6.0.2 || ^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/path-scurry/node_modules/lru-cache": {
|
||||
"version": "10.4.3",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz",
|
||||
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/path-to-regexp": {
|
||||
"version": "8.3.0",
|
||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz",
|
||||
@@ -5702,6 +6164,12 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/proto-list": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz",
|
||||
"integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
@@ -6116,6 +6584,27 @@
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
|
||||
},
|
||||
"node_modules/shebang-command": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"shebang-regex": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/shebang-regex": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
||||
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/shell-quote": {
|
||||
"version": "1.8.3",
|
||||
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.3.tgz",
|
||||
@@ -6202,6 +6691,18 @@
|
||||
"integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/signal-exit": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
|
||||
"integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/sirv": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/sirv/-/sirv-3.0.2.tgz",
|
||||
@@ -6296,6 +6797,21 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/string-width-cjs": {
|
||||
"name": "string-width",
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"emoji-regex": "^8.0.0",
|
||||
"is-fullwidth-code-point": "^3.0.0",
|
||||
"strip-ansi": "^6.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/string.prototype.matchall": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.8.tgz",
|
||||
@@ -6386,6 +6902,19 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-ansi-cjs": {
|
||||
"name": "strip-ansi",
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-regex": "^5.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-comments": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-comments/-/strip-comments-2.0.1.tgz",
|
||||
@@ -7582,6 +8111,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/vue-component-type-helpers": {
|
||||
"version": "2.2.12",
|
||||
"resolved": "https://registry.npmjs.org/vue-component-type-helpers/-/vue-component-type-helpers-2.2.12.tgz",
|
||||
"integrity": "sha512-YbGqHZ5/eW4SnkPNR44mKVc6ZKQoRs/Rux1sxC6rdwXb4qpbOSYfDr9DsTHolOTGmIKgM9j141mZbBeg05R1pw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/vue-router": {
|
||||
"version": "4.6.4",
|
||||
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.6.4.tgz",
|
||||
@@ -7645,6 +8180,21 @@
|
||||
"webidl-conversions": "^4.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"isexe": "^2.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"node-which": "bin/node-which"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/which-boxed-primitive": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz",
|
||||
@@ -7917,6 +8467,57 @@
|
||||
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/wrap-ansi-cjs": {
|
||||
"name": "wrap-ansi",
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
|
||||
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-styles": "^4.0.0",
|
||||
"string-width": "^4.1.0",
|
||||
"strip-ansi": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/wrap-ansi-cjs/node_modules/ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"color-convert": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/wrap-ansi-cjs/node_modules/color-convert": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"color-name": "~1.1.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/wrap-ansi-cjs/node_modules/color-name": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/wrap-ansi/node_modules/ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
|
||||
12
package.json
@@ -11,10 +11,13 @@
|
||||
"serve": "vite build && node server.js",
|
||||
"test": "vitest",
|
||||
"test:unit": "vitest run tests/unit tests/integration",
|
||||
"test:component": "vitest run tests/component",
|
||||
"test:stress": "vitest run tests/stress",
|
||||
"test:all": "vitest run",
|
||||
"test:ui": "vitest --ui",
|
||||
"test:e2e": "playwright test",
|
||||
"test:e2e:ui": "playwright test --ui",
|
||||
"test:e2e:codegen": "playwright codegen"
|
||||
"test:e2e": "playwright test --config=playwright.config.cjs",
|
||||
"test:e2e:ui": "playwright test --config=playwright.config.cjs --ui",
|
||||
"test:e2e:codegen": "playwright codegen --config=playwright.config.cjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^5.2.1",
|
||||
@@ -24,11 +27,14 @@
|
||||
"ws": "^8.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@axe-core/playwright": "^4.11.1",
|
||||
"@playwright/test": "^1.58.2",
|
||||
"@types/node": "^25.2.3",
|
||||
"@vitejs/plugin-vue": "^4.1.0",
|
||||
"@vitest/ui": "^4.0.18",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
"concurrently": "^9.2.1",
|
||||
"happy-dom": "^20.6.1",
|
||||
"jsdom": "^28.0.0",
|
||||
"vite": "^4.3.9",
|
||||
"vite-plugin-pwa": "^0.16.0",
|
||||
|
||||
38
playwright.config.cjs
Normal file
@@ -0,0 +1,38 @@
|
||||
const { defineConfig, devices } = require('@playwright/test');
|
||||
|
||||
/**
|
||||
* See https://playwright.dev/docs/test-configuration.
|
||||
*/
|
||||
module.exports = defineConfig({
|
||||
testDir: './tests/e2e',
|
||||
fullyParallel: false,
|
||||
forbidOnly: !!process.env.CI,
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
workers: 1,
|
||||
reporter: 'html',
|
||||
use: {
|
||||
trace: 'on-first-retry',
|
||||
},
|
||||
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
{
|
||||
name: 'firefox',
|
||||
use: { ...devices['Desktop Firefox'] },
|
||||
},
|
||||
{
|
||||
name: 'Mobile Chrome',
|
||||
use: { ...devices['Pixel 5'] },
|
||||
},
|
||||
],
|
||||
|
||||
webServer: {
|
||||
command: 'npm run serve',
|
||||
url: 'http://localhost:3000',
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120 * 1000,
|
||||
},
|
||||
});
|
||||
@@ -50,14 +50,10 @@ export default defineConfig({
|
||||
// },
|
||||
|
||||
/* Test against mobile viewports. */
|
||||
// {
|
||||
// name: 'Mobile Chrome',
|
||||
// use: { ...devices['Pixel 5'] },
|
||||
// },
|
||||
// {
|
||||
// name: 'Mobile Safari',
|
||||
// use: { ...devices['iPhone 12'] },
|
||||
// },
|
||||
{
|
||||
name: 'Mobile Chrome',
|
||||
use: { ...devices['Pixel 5'] },
|
||||
},
|
||||
|
||||
/* Test against branded browsers. */
|
||||
// {
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
<div class="team-name">{{ state.sp.nomi.home }}</div>
|
||||
<div class="team-pts">{{ state.sp.punt.home }}</div>
|
||||
<div class="team-set">SET {{ state.sp.set.home }}</div>
|
||||
<img v-show="state.sp.servHome" src="/serv.png" class="serv-icon" />
|
||||
<img v-show="state.sp.servHome" src="/serv.png" class="serv-icon" alt="Servizio" />
|
||||
</div>
|
||||
<div class="team-score guest-bg" @click="sendAction({ type: 'incPunt', team: 'guest' })">
|
||||
<div class="team-name">{{ state.sp.nomi.guest }}</div>
|
||||
<div class="team-pts">{{ state.sp.punt.guest }}</div>
|
||||
<div class="team-set">SET {{ state.sp.set.guest }}</div>
|
||||
<img v-show="!state.sp.servHome" src="/serv.png" class="serv-icon" />
|
||||
<img v-show="!state.sp.servHome" src="/serv.png" class="serv-icon" alt="Servizio" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -713,7 +713,7 @@ export default {
|
||||
.btn-danger {
|
||||
background: rgba(198, 40, 40, 0.25);
|
||||
border: 1px solid rgba(239, 83, 80, 0.4);
|
||||
color: #ef5350;
|
||||
color: #ff8a80;
|
||||
padding: 14px 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<span :style="{ 'float': 'left' }">
|
||||
{{ state.sp.nomi.home }}
|
||||
<span class="serv-slot">
|
||||
<img v-show="state.sp.servHome" src="/serv.png" width="25" />
|
||||
<img v-show="state.sp.servHome" src="/serv.png" width="25" alt="Servizio" />
|
||||
</span>
|
||||
<span v-if="state.visuForm" class="score-inline">{{ state.sp.punt.home }}</span>
|
||||
</span>
|
||||
@@ -18,7 +18,7 @@
|
||||
<span :style="{ 'float': 'right' }">
|
||||
<span v-if="state.visuForm" class="score-inline">{{ state.sp.punt.guest }}</span>
|
||||
<span class="serv-slot">
|
||||
<img v-show="!state.sp.servHome" src="/serv.png" width="25" />
|
||||
<img v-show="!state.sp.servHome" src="/serv.png" width="25" alt="Servizio" />
|
||||
</span>
|
||||
{{ state.sp.nomi.guest }}
|
||||
</span>
|
||||
@@ -51,7 +51,7 @@
|
||||
<span :style="{ 'float': 'left' }">
|
||||
{{ state.sp.nomi.guest }}
|
||||
<span class="serv-slot">
|
||||
<img v-show="!state.sp.servHome" src="/serv.png" width="25" />
|
||||
<img v-show="!state.sp.servHome" src="/serv.png" width="25" alt="Servizio" />
|
||||
</span>
|
||||
<span v-if="state.visuForm" class="score-inline">{{ state.sp.punt.guest }}</span>
|
||||
</span>
|
||||
@@ -62,7 +62,7 @@
|
||||
<span :style="{ 'float': 'right' }">
|
||||
<span v-if="state.visuForm" class="score-inline">{{ state.sp.punt.home }}</span>
|
||||
<span class="serv-slot">
|
||||
<img v-show="state.sp.servHome" src="/serv.png" width="25" />
|
||||
<img v-show="state.sp.servHome" src="/serv.png" width="25" alt="Servizio" />
|
||||
</span>
|
||||
{{ state.sp.nomi.home }}
|
||||
</span>
|
||||
|
||||
364
tests/README.md
@@ -1,169 +1,281 @@
|
||||
# Guida ai Test per Principianti - Segnapunti
|
||||
# Guida ai Test
|
||||
|
||||
Benvenuto nella guida ai test del progetto!
|
||||
Obiettivo della guida:
|
||||
- capire che tipi di test esistono nel progetto
|
||||
- capire a cosa servono davvero
|
||||
- sapere come lanciarli senza errori
|
||||
- sapere come leggere i risultati
|
||||
- sapere cosa fare quando qualcosa fallisce
|
||||
|
||||
Questo progetto usa tre tipi di test:
|
||||
## 0) Perche facciamo i test?
|
||||
|
||||
Un test è un controllo automatico.
|
||||
|
||||
In pratica:
|
||||
- tu cambi il codice
|
||||
- lanci i test
|
||||
- i test ti dicono se hai rotto qualcosa
|
||||
|
||||
Se i test sono verdi, hai una buona probabilita che il progetto sia ancora stabile.
|
||||
Se i test sono rossi, c'e un problema da capire e sistemare.
|
||||
|
||||
## 1) Struttura delle cartelle test
|
||||
|
||||
```text
|
||||
tests/
|
||||
├── unit/ # Test veloci per logica pura (funzioni, classi)
|
||||
├── integration/ # Test per componenti che interagiscono (es. WebSocket)
|
||||
├── e2e/ # Test simil-utente reale (Controller -> Display flux)
|
||||
└── README.md # Questa guida
|
||||
├── unit/ # Test della logica pura (molto veloci)
|
||||
├── integration/ # Test di moduli che comunicano tra loro
|
||||
├── component/ # Test dei componenti Vue in isolamento
|
||||
├── stress/ # Test sotto carico (molti client/azioni)
|
||||
├── e2e/ # Test end-to-end su browser reale
|
||||
└── README.md # Questa guida
|
||||
```
|
||||
|
||||
1. **Test Unitari (unit) (Vitest)**: Si occupano di verificare le singole funzioni, i componenti e la logica di business in isolamento. Sono progettati per essere estremamente veloci e fornire un feedback immediato sulla correttezza del codice durante lo sviluppo, garantendo che ogni piccola parte del sistema funzioni come previsto.
|
||||
2. **Test di Integrazione (integration) (Vitest)**: Verificano che diversi moduli o servizi (come la comunicazione tramite WebSocket tra server e client) funzionino correttamente insieme, garantendo che i messaggi e gli eventi vengano scambiati e gestiti come previsto.
|
||||
3. **Test End-to-End (E2E) (Playwright)**: Questi test simulano il comportamento di un utente reale all'interno di un browser (come Chrome o Firefox). Verificano che l'intera applicazione funzioni correttamente dall'inizio alla fine, testando l'interfaccia utente, le API e il database insieme per assicurarsi che i flussi principali (come la creazione di una partita) non presentino errori.
|
||||
## 2) Tecnologie usate
|
||||
|
||||
---
|
||||
- `Vitest`: per `unit`, `integration`, `component`, `stress`
|
||||
- `Playwright`: per `e2e`
|
||||
|
||||
## 1. Come eseguire i Test Veloci (Unit)
|
||||
Tradotto in modo semplice:
|
||||
- Vitest controlla parti interne del progetto
|
||||
- Playwright controlla il comportamento reale dell'app nel browser
|
||||
|
||||
Questi test controllano che la logica interna del server funzioni correttamente.
|
||||
## 3) Prerequisiti (prima di tutto)
|
||||
|
||||
### Cosa viene testato?
|
||||
### 3.1 Installa dipendenze
|
||||
|
||||
#### `gameState.test.js` (Logica di Gioco)
|
||||
|
||||
- **Punteggio**: Verifica che i punti aumentino correttamente (0 -> 1).
|
||||
- **Cambio Palla**: Controlla che il servizio passi all'avversario e che la formazione ruoti.
|
||||
- **Vittoria Set**:
|
||||
- Verifica la vittoria a 25 punti.
|
||||
- Verifica la regola dei vantaggi (si vince solo con 2 punti di scarto, es. 26-24).
|
||||
- **Reset**: Controlla che il tasto Reset azzeri punti, set e formazioni.
|
||||
|
||||
#### `server-utils.test.js` (Utility)
|
||||
|
||||
- **Stampa Info**: Verifica che il server stampi gli indirizzi IP corretti all'avvio.
|
||||
|
||||
### Comando
|
||||
|
||||
Apri il terminale nella cartella del progetto e scrivi:
|
||||
Dalla root del progetto:
|
||||
|
||||
```bash
|
||||
npm run test:unit
|
||||
npm install
|
||||
```
|
||||
|
||||
### Cosa succede se va tutto bene?
|
||||
|
||||
Vedrai delle scritte verdi con la spunta `✓`.
|
||||
Esempio:
|
||||
|
||||
```
|
||||
✓ tests/unit/server-utils.test.js (1 test)
|
||||
Test Files 1 passed (1)
|
||||
Tests 1 passed (1)
|
||||
```
|
||||
|
||||
Significa che il codice funziona come previsto!
|
||||
|
||||
### Cosa succede se c'è un errore?
|
||||
|
||||
Vedrai delle scritte rosse `×` e un messaggio che ti dice cosa non va.
|
||||
Esempio:
|
||||
|
||||
```
|
||||
× tests/unit/server-utils.test.js > Server Utils > ...
|
||||
AssertionError: expected 'A' to include 'B'
|
||||
```
|
||||
|
||||
Significa che hai rotto qualcosa nel codice. Leggi l'errore per capire dove (ti dirà il file e la riga).
|
||||
|
||||
---
|
||||
|
||||
## 2. Come eseguire i Test di Integrazione (Integration)
|
||||
|
||||
Questi test verificano che i componenti del sistema comunichino correttamente tra loro (es. il Server e i Client WebSocket).
|
||||
|
||||
### Cosa viene testato?
|
||||
|
||||
#### `websocket.test.js` (Integrazione WebSocket)
|
||||
|
||||
- **Registrazione**: Verifica che un client riceva lo stato del gioco appena si collega.
|
||||
- **Flusso Messaggi**: Controlla che quando il Controller invia un comando, il Server lo riceva e lo inoltri a tutti (es. Display).
|
||||
- **Sicurezza**: Assicura che solo il "Controller" possa cambiare i punti (il "Display" non può inviare comandi di modifica).
|
||||
|
||||
### Comando
|
||||
|
||||
I test di integrazione sono eseguiti insieme agli unit test:
|
||||
### 3.2 Installa browser Playwright (solo E2E)
|
||||
|
||||
```bash
|
||||
npm run test:unit
|
||||
npx playwright install chromium firefox
|
||||
```
|
||||
|
||||
*(Se vuoi eseguire solo gli integrazione, puoi usare `npx vitest tests/integration`)*
|
||||
Se non fai questo passo, gli E2E possono fallire subito con errore tipo:
|
||||
- `Executable doesn't exist`
|
||||
|
||||
### Cosa succede se va tutto bene?
|
||||
|
||||
Come per gli unit test, vedrai delle spunte verdi `✓` anche per i file nella cartella `tests/integration/`.
|
||||
|
||||
### Cosa succede se c'è un errore?
|
||||
|
||||
Vedrai un errore simile agli unit test, ma spesso legato a problemi di comunicazione (es. "expected message not received").
|
||||
|
||||
---
|
||||
|
||||
## 3. Come eseguire i Test Completi (E2E)
|
||||
|
||||
Questi test simulano un utente che apre il sito. Il computer farà partire il server, aprirà un browser invisibile (o visibile) e proverà a usare il sito come farebbe una persona.
|
||||
|
||||
### Cosa viene testato?
|
||||
|
||||
#### `game-simulation.spec.js` (Simulazione Partita)
|
||||
|
||||
Un "robot" esegue queste azioni automaticamente:
|
||||
|
||||
1. Apre il **Display** e il **Controller** in due schede diverse.
|
||||
2. Premi **Reset** per essere sicuro di partire da zero.
|
||||
3. Clicca **25 volte** sul tasto "+" del Controller.
|
||||
4. Controlla che sul **Display** appaia che il set è stato vinto (Punteggio Set: 1).
|
||||
|
||||
### Comando
|
||||
## 4) Comandi principali
|
||||
|
||||
```bash
|
||||
npm run test:e2e
|
||||
npm run test # Vitest in watch mode (resta in ascolto)
|
||||
npm run test:all # Tutta la suite Vitest una volta
|
||||
npm run test:unit # Unit + integration
|
||||
npm run test:component # Solo component test
|
||||
npm run test:stress # Solo stress test
|
||||
npm run test:e2e # Tutti gli E2E Playwright
|
||||
npm run test:e2e:ui # Playwright con interfaccia grafica
|
||||
```
|
||||
|
||||
(Oppure `npx playwright test` per maggiori opzioni)
|
||||
Ordine consigliato (quando vuoi verificare tutto):
|
||||
1. `npm run test:all`
|
||||
2. `npm run test:e2e`
|
||||
|
||||
### Cosa succede se va tutto bene?
|
||||
## 5) Cosa testa ogni suite (spiegato semplice)
|
||||
|
||||
Il test impiegherà qualche secondo (è più lento degli unit test). Se tutto va bene, vedrai:
|
||||
### 5.1 Unit (`tests/unit`)
|
||||
|
||||
```
|
||||
Running 1 test using 1 worker
|
||||
✓ 1 [chromium] › tests/e2e/game-simulation.spec.js:3:1 › Game Simulation (5.0s)
|
||||
1 passed (5.5s)
|
||||
Cosa sono:
|
||||
- test piccoli e veloci sulla logica del gioco
|
||||
|
||||
A cosa servono:
|
||||
- trovano subito bug in regole punteggio/set/reset
|
||||
|
||||
Esempi reali nel progetto:
|
||||
- incremento/decremento punti
|
||||
- cambio palla
|
||||
- vittoria set con regola dei 2 punti di scarto
|
||||
- reset stato
|
||||
|
||||
Quando falliscono:
|
||||
- quasi sempre c'e un problema nella logica core
|
||||
|
||||
### 5.2 Integration (`tests/integration`)
|
||||
|
||||
Cosa sono:
|
||||
- test su pezzi che lavorano insieme (es. WebSocket + handler)
|
||||
|
||||
A cosa servono:
|
||||
- verificano che i messaggi si muovano nel modo corretto
|
||||
|
||||
Esempi reali nel progetto:
|
||||
- registrazione client `display`/`controller`
|
||||
- broadcast stato ai client
|
||||
- validazione input malformati
|
||||
- autorizzazioni (solo controller puo inviare certe azioni)
|
||||
|
||||
Quando falliscono:
|
||||
- spesso c'e problema nel protocollo messaggi o nei controlli di ruolo
|
||||
|
||||
### 5.3 Component (`tests/component`)
|
||||
|
||||
Cosa sono:
|
||||
- test dei componenti Vue senza browser completo
|
||||
|
||||
A cosa servono:
|
||||
- controllano rendering e comportamento UI locale
|
||||
|
||||
Esempi reali nel progetto:
|
||||
- punteggio mostrato correttamente
|
||||
- stato connessione
|
||||
- click bottoni controller
|
||||
- dialog reset/config/cambi
|
||||
|
||||
Quando falliscono:
|
||||
- spesso hai rotto template, computed, metodi o binding
|
||||
|
||||
### 5.4 Stress (`tests/stress`)
|
||||
|
||||
Cosa sono:
|
||||
- test per simulare carico elevato
|
||||
|
||||
A cosa servono:
|
||||
- verificano che il sistema regga molti client e molte azioni rapide
|
||||
|
||||
Esempi reali nel progetto:
|
||||
- tanti client display connessi insieme
|
||||
- burst di azioni consecutive
|
||||
|
||||
Quando falliscono:
|
||||
- possono emergere problemi di performance o consistenza stato
|
||||
|
||||
### 5.5 End-to-End (`tests/e2e`)
|
||||
|
||||
Cosa sono:
|
||||
- test realistici nel browser
|
||||
|
||||
A cosa servono:
|
||||
- verificano che Controller e Display funzionino davvero insieme
|
||||
|
||||
File principali:
|
||||
- `basic-flow.spec.cjs`: flusso base Controller <-> Display
|
||||
- `game-operations.spec.cjs`: reset, config, toggle, cambi
|
||||
- `game-simulation.spec.cjs`: simulazione partita
|
||||
- `full-match.spec.cjs`: scenari partita completi
|
||||
- `accessibility.spec.cjs`: controlli accessibilita con axe
|
||||
- `visual-regression.spec.cjs`: confronto screenshot con baseline
|
||||
|
||||
Nota importante:
|
||||
- gli E2E sono configurati in seriale (`workers: 1`) per evitare interferenze sullo stato partita condiviso.
|
||||
|
||||
## 6) Come leggere i risultati
|
||||
|
||||
### 6.1 Risultati Vitest
|
||||
|
||||
Caso OK (verde):
|
||||
|
||||
```text
|
||||
Test Files 6 passed (6)
|
||||
Tests 159 passed (159)
|
||||
```
|
||||
|
||||
Significa che il sito si apre correttamente e il flusso di gioco funziona dall'inizio alla fine!
|
||||
Significa:
|
||||
- tutti i test Vitest sono passati
|
||||
|
||||
### Cosa succede se c'è un errore?
|
||||
Caso KO (rosso):
|
||||
- guarda prima il nome del file test
|
||||
- poi il nome del test (`describe/test`)
|
||||
- poi la riga con `expected` e `received`
|
||||
- infine vai alla riga indicata nello stack trace
|
||||
|
||||
Se qualcosa non va (es. il server non parte, o il controller non aggiorna il display), il test fallirà.
|
||||
Playwright genererà un **Report HTML** molto dettagliato.
|
||||
Per vederlo, scrivi:
|
||||
### 6.2 Risultati Playwright
|
||||
|
||||
Caso OK:
|
||||
|
||||
```text
|
||||
72 passed
|
||||
```
|
||||
|
||||
Caso KO:
|
||||
- apri il report HTML
|
||||
|
||||
```bash
|
||||
npx playwright show-report
|
||||
```
|
||||
|
||||
Si aprirà una pagina web dove potrai vedere passo-passo cosa è successo, inclusi screenshot e video dell'errore.
|
||||
Nel report puoi vedere:
|
||||
- step del test
|
||||
- errori precisi
|
||||
- screenshot/diff
|
||||
- trace
|
||||
|
||||
---
|
||||
## 7) Visual Regression (screenshot)
|
||||
|
||||
## Domande Frequenti
|
||||
I test visual confrontano immagini attuali con immagini baseline.
|
||||
|
||||
**Q: I test E2E falliscono su WebKit (Safari)?**
|
||||
A: È normale su Linux se non hai installato tutte le librerie di sistema. Per ora testiamo solo su **Chromium** (Chrome) e **Firefox** che sono più facili da far girare.
|
||||
Cartella baseline:
|
||||
- `tests/e2e/visual-regression.spec.cjs-snapshots/`
|
||||
|
||||
**Q: Devo avviare il server prima dei test?**
|
||||
A: No! Il comando `npm run test:e2e` avvia automaticamente il tuo server (`npm run serve`) prima di iniziare i test.
|
||||
Se cambia la UI in modo intenzionale:
|
||||
- aggiorna snapshot
|
||||
|
||||
**Q: Come creo un nuovo test?**
|
||||
A:
|
||||
```bash
|
||||
npm run test:e2e -- --update-snapshots
|
||||
```
|
||||
|
||||
- **Unit**: Crea un file `.test.js` in `tests/unit/`. Copia l'esempio esistente.
|
||||
- **Integration**: Crea un file `.test.js` in `tests/integration/`.
|
||||
- **E2E**: Crea un file `.spec.js` in `tests/e2e/`. Copia l'esempio esistente.
|
||||
Poi rilancia controllo:
|
||||
|
||||
```bash
|
||||
npm run test:e2e
|
||||
```
|
||||
|
||||
Se la UI non doveva cambiare:
|
||||
- non aggiornare snapshot
|
||||
- correggi prima il codice UI/CSS
|
||||
|
||||
## 8) Errori comuni e soluzione veloce
|
||||
|
||||
- Errore Playwright `Executable doesn't exist`:
|
||||
- esegui `npx playwright install chromium firefox`
|
||||
|
||||
- E2E instabili con punteggi strani:
|
||||
- assicurati che i test restino seriali (`workers: 1`)
|
||||
- assicurati che ogni test parta da stato pulito (reset)
|
||||
|
||||
- Selettore ambiguo (esempio bottone `Cambi`):
|
||||
- usa selector piu specifici, ad esempio `getByRole(..., { exact: true })`
|
||||
|
||||
- Failure accessibilita:
|
||||
- controlla prima `alt` delle immagini e contrasto colori
|
||||
|
||||
## 9) Mini checklist prima di fare push
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
npm run test:all
|
||||
npm run test:e2e
|
||||
```
|
||||
|
||||
Se hai cambiato UI e i visual falliscono per differenze volute:
|
||||
|
||||
```bash
|
||||
npm run test:e2e -- --update-snapshots
|
||||
npm run test:e2e
|
||||
```
|
||||
|
||||
## 10) Come aggiungere un nuovo test (consigli pratici)
|
||||
|
||||
- metti i test nel posto giusto:
|
||||
- `tests/unit` per logica pura
|
||||
- `tests/integration` per moduli che dialogano
|
||||
- `tests/component` per Vue in isolamento
|
||||
- `tests/stress` per carico
|
||||
- `tests/e2e` per flussi reali
|
||||
|
||||
- mantieni nomi chiari:
|
||||
- il titolo del test deve spiegare cosa verifica
|
||||
|
||||
- evita test dipendenti da ordine:
|
||||
- ogni test deve potersi eseguire da solo
|
||||
|
||||
- negli E2E:
|
||||
- porta sempre il sistema in stato iniziale
|
||||
- usa selector robusti
|
||||
- limita `waitForTimeout` e preferisci attese su condizioni reali
|
||||
|
||||
Se segui questi punti, i test restano stabili e facili da capire anche per chi entra ora nel progetto.
|
||||
|
||||
255
tests/component/ControllerPage.test.js
Normal file
@@ -0,0 +1,255 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import ControllerPage from '../../src/components/ControllerPage.vue'
|
||||
|
||||
// Mock globale WebSocket per jsdom
|
||||
class MockWebSocket {
|
||||
static OPEN = 1
|
||||
static CONNECTING = 0
|
||||
readyState = 0
|
||||
onopen = null
|
||||
onclose = null
|
||||
onmessage = null
|
||||
onerror = null
|
||||
send = vi.fn()
|
||||
close = vi.fn()
|
||||
constructor() {
|
||||
// Simula connessione immediata
|
||||
setTimeout(() => {
|
||||
this.readyState = 1
|
||||
if (this.onopen) this.onopen()
|
||||
}, 0)
|
||||
}
|
||||
}
|
||||
|
||||
vi.stubGlobal('WebSocket', MockWebSocket)
|
||||
|
||||
// Helper per creare il componente con stato personalizzato
|
||||
function mountController(stateOverrides = {}) {
|
||||
const wrapper = mount(ControllerPage, {
|
||||
global: {
|
||||
stubs: { 'w-app': true, 'w-button': true }
|
||||
}
|
||||
})
|
||||
if (Object.keys(stateOverrides).length > 0) {
|
||||
wrapper.vm.state = { ...wrapper.vm.state, ...stateOverrides }
|
||||
}
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('ControllerPage.vue', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// RENDERING INIZIALE
|
||||
// =============================================
|
||||
describe('Rendering iniziale', () => {
|
||||
it('dovrebbe mostrare i nomi dei team', () => {
|
||||
const wrapper = mountController()
|
||||
const text = wrapper.text()
|
||||
expect(text).toContain('Antoniana')
|
||||
expect(text).toContain('Guest')
|
||||
})
|
||||
|
||||
it('dovrebbe mostrare punteggio 0-0', () => {
|
||||
const wrapper = mountController()
|
||||
const pts = wrapper.findAll('.team-pts')
|
||||
expect(pts[0].text()).toBe('0')
|
||||
expect(pts[1].text()).toBe('0')
|
||||
})
|
||||
|
||||
it('dovrebbe mostrare SET 0 per entrambi i team', () => {
|
||||
const wrapper = mountController()
|
||||
const sets = wrapper.findAll('.team-set')
|
||||
expect(sets[0].text()).toContain('SET 0')
|
||||
expect(sets[1].text()).toContain('SET 0')
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// CLICK PUNTEGGIO
|
||||
// =============================================
|
||||
describe('Click punteggio', () => {
|
||||
it('dovrebbe chiamare sendAction con incPunt home al click sul team home', async () => {
|
||||
const wrapper = mountController()
|
||||
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||
await wrapper.find('.team-score.home-bg').trigger('click')
|
||||
expect(spy).toHaveBeenCalledWith({ type: 'incPunt', team: 'home' })
|
||||
})
|
||||
|
||||
it('dovrebbe chiamare sendAction con incPunt guest al click sul team guest', async () => {
|
||||
const wrapper = mountController()
|
||||
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||
await wrapper.find('.team-score.guest-bg').trigger('click')
|
||||
expect(spy).toHaveBeenCalledWith({ type: 'incPunt', team: 'guest' })
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// BOTTONE CAMBIO PALLA
|
||||
// =============================================
|
||||
describe('Cambio Palla', () => {
|
||||
it('dovrebbe essere abilitato a 0-0', () => {
|
||||
const wrapper = mountController()
|
||||
const btn = wrapper.findAll('.btn-ctrl').find(b => b.text().includes('Cambio Palla'))
|
||||
expect(btn.attributes('disabled')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('dovrebbe essere disabilitato se il punteggio non è 0-0', async () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.state.sp.punt.home = 5
|
||||
await wrapper.vm.$nextTick()
|
||||
const btn = wrapper.findAll('.btn-ctrl').find(b => b.text().includes('Cambio Palla'))
|
||||
expect(btn.attributes('disabled')).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// DIALOG RESET
|
||||
// =============================================
|
||||
describe('Dialog Reset', () => {
|
||||
it('click Reset dovrebbe aprire la conferma', async () => {
|
||||
const wrapper = mountController()
|
||||
expect(wrapper.find('.overlay').exists()).toBe(false)
|
||||
await wrapper.find('.btn-danger').trigger('click')
|
||||
expect(wrapper.vm.confirmReset).toBe(true)
|
||||
expect(wrapper.find('.overlay').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('click NO dovrebbe chiudere la conferma', async () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.confirmReset = true
|
||||
await wrapper.vm.$nextTick()
|
||||
await wrapper.find('.btn-cancel').trigger('click')
|
||||
expect(wrapper.vm.confirmReset).toBe(false)
|
||||
})
|
||||
|
||||
it('click SI dovrebbe chiamare doReset', async () => {
|
||||
const wrapper = mountController()
|
||||
const spy = vi.spyOn(wrapper.vm, 'sendAction')
|
||||
wrapper.vm.confirmReset = true
|
||||
await wrapper.vm.$nextTick()
|
||||
await wrapper.find('.btn-confirm').trigger('click')
|
||||
expect(spy).toHaveBeenCalledWith({ type: 'resetta' })
|
||||
expect(wrapper.vm.confirmReset).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// COMPUTED cambiValid
|
||||
// =============================================
|
||||
describe('cambiValid', () => {
|
||||
it('dovrebbe essere false se tutti i campi sono vuoti', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.cambiData = [{ in: '', out: '' }, { in: '', out: '' }]
|
||||
expect(wrapper.vm.cambiValid).toBe(false)
|
||||
})
|
||||
|
||||
it('dovrebbe essere true con un cambio completo', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.cambiData = [{ in: '10', out: '1' }, { in: '', out: '' }]
|
||||
expect(wrapper.vm.cambiValid).toBe(true)
|
||||
})
|
||||
|
||||
it('dovrebbe essere false con un cambio parziale (solo IN)', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.cambiData = [{ in: '10', out: '' }, { in: '', out: '' }]
|
||||
expect(wrapper.vm.cambiValid).toBe(false)
|
||||
})
|
||||
|
||||
it('dovrebbe essere false con un cambio parziale (solo OUT)', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.cambiData = [{ in: '', out: '1' }, { in: '', out: '' }]
|
||||
expect(wrapper.vm.cambiValid).toBe(false)
|
||||
})
|
||||
|
||||
it('dovrebbe essere true con due cambi completi', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.cambiData = [{ in: '10', out: '1' }, { in: '11', out: '2' }]
|
||||
expect(wrapper.vm.cambiValid).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// SPEAK
|
||||
// =============================================
|
||||
describe('speak', () => {
|
||||
it('dovrebbe generare "zero a zero" a 0-0', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.wsConnected = true
|
||||
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
||||
wrapper.vm.speak()
|
||||
const sent = JSON.parse(wrapper.vm.ws.send.mock.calls[0][0])
|
||||
expect(sent.type).toBe('speak')
|
||||
expect(sent.text).toBe('zero a zero')
|
||||
})
|
||||
|
||||
it('dovrebbe generare "N pari" a punteggio uguale', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.state.sp.punt.home = 5
|
||||
wrapper.vm.state.sp.punt.guest = 5
|
||||
wrapper.vm.wsConnected = true
|
||||
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
||||
wrapper.vm.speak()
|
||||
const sent = JSON.parse(wrapper.vm.ws.send.mock.calls[0][0])
|
||||
expect(sent.text).toBe('5 pari')
|
||||
})
|
||||
|
||||
it('dovrebbe annunciare prima il punteggio di chi batte (home serve)', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.state.sp.punt.home = 15
|
||||
wrapper.vm.state.sp.punt.guest = 10
|
||||
wrapper.vm.state.sp.servHome = true
|
||||
wrapper.vm.wsConnected = true
|
||||
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
||||
wrapper.vm.speak()
|
||||
const sent = JSON.parse(wrapper.vm.ws.send.mock.calls[0][0])
|
||||
expect(sent.text).toBe('15 a 10')
|
||||
})
|
||||
|
||||
it('dovrebbe annunciare prima il punteggio di chi batte (guest serve)', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.state.sp.punt.home = 10
|
||||
wrapper.vm.state.sp.punt.guest = 15
|
||||
wrapper.vm.state.sp.servHome = false
|
||||
wrapper.vm.wsConnected = true
|
||||
wrapper.vm.ws = { readyState: 1, send: vi.fn() }
|
||||
wrapper.vm.speak()
|
||||
const sent = JSON.parse(wrapper.vm.ws.send.mock.calls[0][0])
|
||||
expect(sent.text).toBe('15 a 10')
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// BARRA CONNESSIONE
|
||||
// =============================================
|
||||
describe('Barra connessione', () => {
|
||||
it('dovrebbe avere classe "connected" quando connesso', async () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.wsConnected = true
|
||||
await wrapper.vm.$nextTick()
|
||||
expect(wrapper.find('.conn-bar').classes()).toContain('connected')
|
||||
})
|
||||
|
||||
it('non dovrebbe avere classe "connected" quando disconnesso', () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.wsConnected = false
|
||||
expect(wrapper.find('.conn-bar').classes()).not.toContain('connected')
|
||||
})
|
||||
|
||||
it('dovrebbe mostrare "Connesso" quando connesso', async () => {
|
||||
const wrapper = mountController()
|
||||
wrapper.vm.wsConnected = true
|
||||
await wrapper.vm.$nextTick()
|
||||
expect(wrapper.find('.conn-bar').text()).toContain('Connesso')
|
||||
})
|
||||
})
|
||||
})
|
||||
195
tests/component/DisplayPage.test.js
Normal file
@@ -0,0 +1,195 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import DisplayPage from '../../src/components/DisplayPage.vue'
|
||||
|
||||
// Mock globale WebSocket per jsdom
|
||||
class MockWebSocket {
|
||||
static OPEN = 1
|
||||
static CONNECTING = 0
|
||||
readyState = 0
|
||||
onopen = null
|
||||
onclose = null
|
||||
onmessage = null
|
||||
onerror = null
|
||||
send = vi.fn()
|
||||
close = vi.fn()
|
||||
constructor() {
|
||||
setTimeout(() => {
|
||||
this.readyState = 1
|
||||
if (this.onopen) this.onopen()
|
||||
}, 0)
|
||||
}
|
||||
}
|
||||
|
||||
vi.stubGlobal('WebSocket', MockWebSocket)
|
||||
|
||||
// Mock requestFullscreen e speechSynthesis
|
||||
vi.stubGlobal('speechSynthesis', {
|
||||
speak: vi.fn(),
|
||||
cancel: vi.fn(),
|
||||
getVoices: () => []
|
||||
})
|
||||
|
||||
function mountDisplay() {
|
||||
return mount(DisplayPage, {
|
||||
global: {
|
||||
stubs: { 'w-app': true }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
describe('DisplayPage.vue', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// RENDERING PUNTEGGIO
|
||||
// =============================================
|
||||
describe('Rendering punteggio', () => {
|
||||
it('dovrebbe mostrare i nomi dei team', () => {
|
||||
const wrapper = mountDisplay()
|
||||
const text = wrapper.text()
|
||||
expect(text).toContain('Antoniana')
|
||||
expect(text).toContain('Guest')
|
||||
})
|
||||
|
||||
it('dovrebbe mostrare punteggio iniziale 0-0', () => {
|
||||
const wrapper = mountDisplay()
|
||||
const punti = wrapper.findAll('.punt')
|
||||
expect(punti[0].text()).toBe('0')
|
||||
expect(punti[1].text()).toBe('0')
|
||||
})
|
||||
|
||||
it('dovrebbe mostrare i set corretti', () => {
|
||||
const wrapper = mountDisplay()
|
||||
const text = wrapper.text()
|
||||
expect(text).toContain('set 0')
|
||||
})
|
||||
|
||||
it('dovrebbe aggiornare il punteggio quando lo stato cambia', async () => {
|
||||
const wrapper = mountDisplay()
|
||||
wrapper.vm.state.sp.punt.home = 15
|
||||
wrapper.vm.state.sp.punt.guest = 12
|
||||
await wrapper.vm.$nextTick()
|
||||
const punti = wrapper.findAll('.punt')
|
||||
expect(punti[0].text()).toBe('15')
|
||||
expect(punti[1].text()).toBe('12')
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// ORDINE TEAM
|
||||
// =============================================
|
||||
describe('Ordine team', () => {
|
||||
it('order=true → Home prima di Guest', () => {
|
||||
const wrapper = mountDisplay()
|
||||
const headers = wrapper.findAll('.hea')
|
||||
expect(headers[0].classes()).toContain('home')
|
||||
expect(headers[1].classes()).toContain('guest')
|
||||
})
|
||||
|
||||
it('order=false → Guest prima di Home', async () => {
|
||||
const wrapper = mountDisplay()
|
||||
wrapper.vm.state.order = false
|
||||
await wrapper.vm.$nextTick()
|
||||
const headers = wrapper.findAll('.hea')
|
||||
expect(headers[0].classes()).toContain('guest')
|
||||
expect(headers[1].classes()).toContain('home')
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// FORMAZIONE vs PUNTEGGIO
|
||||
// =============================================
|
||||
describe('visuForm toggle', () => {
|
||||
it('visuForm=false → mostra punteggio grande', () => {
|
||||
const wrapper = mountDisplay()
|
||||
expect(wrapper.find('.punteggio-container').exists()).toBe(true)
|
||||
expect(wrapper.find('.form').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('visuForm=true → mostra formazione', async () => {
|
||||
const wrapper = mountDisplay()
|
||||
wrapper.vm.state.visuForm = true
|
||||
await wrapper.vm.$nextTick()
|
||||
expect(wrapper.findAll('.form').length).toBeGreaterThan(0)
|
||||
expect(wrapper.find('.punteggio-container').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('formazione mostra 6 giocatori per team', async () => {
|
||||
const wrapper = mountDisplay()
|
||||
wrapper.vm.state.visuForm = true
|
||||
await wrapper.vm.$nextTick()
|
||||
const formDivs = wrapper.findAll('.formdiv')
|
||||
// 6 per home + 6 per guest = 12
|
||||
expect(formDivs).toHaveLength(12)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// STRISCIA
|
||||
// =============================================
|
||||
describe('visuStriscia toggle', () => {
|
||||
it('visuStriscia=true → mostra la striscia', () => {
|
||||
const wrapper = mountDisplay()
|
||||
expect(wrapper.find('.striscia').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('visuStriscia=false → nasconde la striscia', async () => {
|
||||
const wrapper = mountDisplay()
|
||||
wrapper.vm.state.visuStriscia = false
|
||||
await wrapper.vm.$nextTick()
|
||||
expect(wrapper.find('.striscia').exists()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// INDICATORE CONNESSIONE
|
||||
// =============================================
|
||||
describe('Indicatore connessione', () => {
|
||||
it('dovrebbe avere classe "disconnected" quando non connesso', () => {
|
||||
const wrapper = mountDisplay()
|
||||
const status = wrapper.find('.connection-status')
|
||||
expect(status.classes()).toContain('disconnected')
|
||||
})
|
||||
|
||||
it('dovrebbe avere classe "connected" quando connesso', async () => {
|
||||
const wrapper = mountDisplay()
|
||||
wrapper.vm.wsConnected = true
|
||||
await wrapper.vm.$nextTick()
|
||||
const status = wrapper.find('.connection-status')
|
||||
expect(status.classes()).toContain('connected')
|
||||
})
|
||||
|
||||
it('dovrebbe mostrare "Disconnesso" quando non connesso', () => {
|
||||
const wrapper = mountDisplay()
|
||||
const status = wrapper.find('.connection-status')
|
||||
expect(status.text()).toContain('Disconnesso')
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// ICONA SERVIZIO
|
||||
// =============================================
|
||||
describe('Icona servizio', () => {
|
||||
it('dovrebbe mostrare l\'icona servizio sul team home quando servHome=true', () => {
|
||||
const wrapper = mountDisplay()
|
||||
// v-show imposta display:none. In happy-dom controlliamo lo style.
|
||||
const imgs = wrapper.findAll('.serv-slot img')
|
||||
// Con state.order=true e servHome=true:
|
||||
// - la prima img (home) è visibile (no display:none)
|
||||
// - la seconda img (guest) ha display:none
|
||||
const homeStyle = imgs[0].attributes('style') || ''
|
||||
const guestStyle = imgs[1].attributes('style') || ''
|
||||
expect(homeStyle).not.toContain('display: none')
|
||||
expect(guestStyle).toContain('display: none')
|
||||
})
|
||||
})
|
||||
})
|
||||
72
tests/e2e/accessibility.spec.cjs
Normal file
@@ -0,0 +1,72 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
const AxeBuilderImport = require('@axe-core/playwright');
|
||||
const AxeBuilder = AxeBuilderImport.default || AxeBuilderImport;
|
||||
|
||||
test.describe('Accessibility (a11y)', () => {
|
||||
|
||||
test('Display: non dovrebbe avere violazioni critiche a11y', async ({ page }) => {
|
||||
await page.goto('http://localhost:3000');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
const results = await new AxeBuilder({ page })
|
||||
.withTags(['wcag2a', 'wcag2aa'])
|
||||
.disableRules(['color-contrast']) // il display ha sfondo nero con testo grande, valutato separatamente
|
||||
.analyze();
|
||||
|
||||
expect(results.violations).toEqual([]);
|
||||
});
|
||||
|
||||
test('Controller: non dovrebbe avere violazioni critiche a11y', async ({ page }) => {
|
||||
await page.goto('http://localhost:3001');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
const results = await new AxeBuilder({ page })
|
||||
.withTags(['wcag2a', 'wcag2aa'])
|
||||
.analyze();
|
||||
|
||||
// Mostra i dettagli delle violazioni se ci sono
|
||||
if (results.violations.length > 0) {
|
||||
console.log('A11y violations:', JSON.stringify(results.violations.map(v => ({
|
||||
id: v.id,
|
||||
impact: v.impact,
|
||||
description: v.description,
|
||||
nodes: v.nodes.length
|
||||
})), null, 2));
|
||||
}
|
||||
|
||||
// Accettiamo solo violazioni minor (non critiche o serie)
|
||||
const serious = results.violations.filter(v =>
|
||||
v.impact === 'critical' || v.impact === 'serious'
|
||||
);
|
||||
expect(serious).toEqual([]);
|
||||
});
|
||||
|
||||
test('Controller: i touch target dovrebbero avere dimensione minima', async ({ page }) => {
|
||||
await page.goto('http://localhost:3001');
|
||||
await page.waitForSelector('.conn-bar.connected');
|
||||
|
||||
// Controlla che i bottoni principali abbiano dimensione minima 44x44px
|
||||
const buttons = page.locator('.btn-ctrl');
|
||||
const count = await buttons.count();
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const box = await buttons.nth(i).boundingBox();
|
||||
expect(box.width).toBeGreaterThanOrEqual(44);
|
||||
expect(box.height).toBeGreaterThanOrEqual(44);
|
||||
}
|
||||
});
|
||||
|
||||
test('Controller: i bottoni punteggio dovrebbero avere dimensione adeguata', async ({ page }) => {
|
||||
await page.goto('http://localhost:3001');
|
||||
await page.waitForSelector('.conn-bar.connected');
|
||||
|
||||
const scoreButtons = page.locator('.team-score');
|
||||
const count = await scoreButtons.count();
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const box = await scoreButtons.nth(i).boundingBox();
|
||||
expect(box.width).toBeGreaterThanOrEqual(100);
|
||||
expect(box.height).toBeGreaterThanOrEqual(100);
|
||||
}
|
||||
});
|
||||
});
|
||||
119
tests/e2e/basic-flow.spec.cjs
Normal file
@@ -0,0 +1,119 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
test.describe('Basic Flow: Controller ↔ Display', () => {
|
||||
|
||||
test('dovrebbe caricare Display e Controller con i titoli corretti', async ({ context }) => {
|
||||
const displayPage = await context.newPage();
|
||||
const controllerPage = await context.newPage();
|
||||
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
|
||||
await expect(displayPage).toHaveTitle(/Segnapunti/);
|
||||
await expect(controllerPage).toHaveTitle(/Controller/);
|
||||
});
|
||||
|
||||
test('il punteggio iniziale dovrebbe essere 0-0', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
|
||||
// Attende la connessione WebSocket
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
const homeScore = controllerPage.locator('.team-score.home-bg .team-pts');
|
||||
const guestScore = controllerPage.locator('.team-score.guest-bg .team-pts');
|
||||
await expect(homeScore).toHaveText('0');
|
||||
await expect(guestScore).toHaveText('0');
|
||||
});
|
||||
|
||||
test('click +1 Home sul Controller dovrebbe aggiornare il Display', async ({ context }) => {
|
||||
const displayPage = await context.newPage();
|
||||
const controllerPage = await context.newPage();
|
||||
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
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
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
await controllerPage.waitForTimeout(200);
|
||||
|
||||
// Verifica Controller mostra 1
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('1');
|
||||
|
||||
// Verifica Display mostra 1 (il punteggio grande)
|
||||
await expect(displayPage.locator('.punt.home')).toHaveText('1');
|
||||
});
|
||||
|
||||
test('click +1 Guest sul Controller dovrebbe aggiornare il Display', async ({ context }) => {
|
||||
const displayPage = await context.newPage();
|
||||
const controllerPage = await context.newPage();
|
||||
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
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
|
||||
await controllerPage.locator('.team-score.guest-bg').click();
|
||||
await controllerPage.waitForTimeout(200);
|
||||
|
||||
// Verifica Controller
|
||||
await expect(controllerPage.locator('.team-score.guest-bg .team-pts')).toHaveText('1');
|
||||
|
||||
// Verifica Display
|
||||
await expect(displayPage.locator('.punt.guest')).toHaveText('1');
|
||||
});
|
||||
|
||||
test('la sincronizzazione dovrebbe funzionare con punti alternati', async ({ context }) => {
|
||||
const displayPage = await context.newPage();
|
||||
const controllerPage = await context.newPage();
|
||||
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
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
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
await controllerPage.locator('.team-score.guest-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
await controllerPage.waitForTimeout(200);
|
||||
|
||||
// Controller: Home 2, Guest 1
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('2');
|
||||
await expect(controllerPage.locator('.team-score.guest-bg .team-pts')).toHaveText('1');
|
||||
|
||||
// Display: Home 2, Guest 1
|
||||
await expect(displayPage.locator('.punt.home')).toHaveText('2');
|
||||
await expect(displayPage.locator('.punt.guest')).toHaveText('1');
|
||||
});
|
||||
});
|
||||
@@ -1,28 +0,0 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test('Controller updates Display score', async ({ context }) => {
|
||||
// 1. Create two pages (Controller and Display)
|
||||
const displayPage = await context.newPage();
|
||||
const controllerPage = await context.newPage();
|
||||
|
||||
// 2. Open Display
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
await expect(displayPage).toHaveTitle(/Segnapunti/);
|
||||
|
||||
// 3. Open Controller
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await expect(controllerPage).toHaveTitle(/Controller/);
|
||||
|
||||
// 4. Check initial state (assuming reset)
|
||||
// Note: This depends on the specific IDs in your HTML.
|
||||
// You might need to adjust selectors based on your actual HTML structure.
|
||||
|
||||
// Example: waiting for score element
|
||||
// await expect(displayPage.locator('#score-home')).toHaveText('0');
|
||||
|
||||
// 5. Action on Controller
|
||||
// await controllerPage.click('#btn-add-home');
|
||||
|
||||
// 6. Verify on Display
|
||||
// await expect(displayPage.locator('#score-home')).toHaveText('1');
|
||||
});
|
||||
131
tests/e2e/full-match.spec.cjs
Normal file
@@ -0,0 +1,131 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
// 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('Partita 2/3: Home vince 2 set a 0', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Cambia modalità a 2/3
|
||||
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 vince 25-0 ===
|
||||
await addPoints(controllerPage, 'home', 25);
|
||||
|
||||
// Verifica punteggio 25
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('25');
|
||||
|
||||
// Incrementa set Home
|
||||
await controllerPage.locator('.btn-set.home-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
|
||||
// Verifica set 1 per Home
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-set')).toContainText('SET 1');
|
||||
});
|
||||
|
||||
test('Set decisivo 2/3: vittoria a 15 punti', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Cambia modalità a 2/3
|
||||
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);
|
||||
|
||||
// Imposta set 1-1 manualmente (simula set pareggiati)
|
||||
await controllerPage.locator('.btn-set.home-bg').click();
|
||||
await controllerPage.waitForTimeout(50);
|
||||
await controllerPage.locator('.btn-set.guest-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
|
||||
// Verifica set 1-1
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-set')).toContainText('SET 1');
|
||||
await expect(controllerPage.locator('.team-score.guest-bg .team-set')).toContainText('SET 1');
|
||||
|
||||
// === SET DECISIVO: Home porta a 15 ===
|
||||
await addPoints(controllerPage, 'home', 15);
|
||||
|
||||
// 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');
|
||||
|
||||
// Verifica che non si possono aggiungere altri punti (vittoria)
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
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 }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Porta a 24-24
|
||||
await addPoints(controllerPage, 'home', 24);
|
||||
await addPoints(controllerPage, 'guest', 24);
|
||||
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('24');
|
||||
await expect(controllerPage.locator('.team-score.guest-bg .team-pts')).toHaveText('24');
|
||||
|
||||
// Home va a 25 (non è vittoria perché serve scarto di 2)
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('25');
|
||||
|
||||
// Si possono ancora aggiungere punti (non è vittoria a 25-24)
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('26');
|
||||
|
||||
// 26-24 è vittoria → non si possono più aggiungere punti
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('26');
|
||||
});
|
||||
});
|
||||
182
tests/e2e/game-operations.spec.cjs
Normal file
@@ -0,0 +1,182 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
// 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('Undo: dovrebbe annullare l\'ultimo punto', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Incrementa Home a 1
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('1');
|
||||
|
||||
// Annulla
|
||||
await controllerPage.getByText('ANNULLA PUNTO').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('0');
|
||||
});
|
||||
|
||||
test('Reset: dovrebbe azzerare tutto dopo conferma', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
// Imposta qualche punto
|
||||
for (let i = 0; i < 5; i++) {
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
await controllerPage.waitForTimeout(50);
|
||||
}
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('5');
|
||||
|
||||
// Reset
|
||||
await resetGame(controllerPage);
|
||||
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('0');
|
||||
await expect(controllerPage.locator('.team-score.guest-bg .team-pts')).toHaveText('0');
|
||||
});
|
||||
|
||||
test('Config: dovrebbe cambiare i nomi dei team', async ({ context }) => {
|
||||
const displayPage = await context.newPage();
|
||||
const controllerPage = await context.newPage();
|
||||
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
// Apri config
|
||||
await controllerPage.getByText('Config').click();
|
||||
await controllerPage.waitForSelector('.dialog-config');
|
||||
|
||||
// Modifica nomi
|
||||
const inputs = controllerPage.locator('.dialog-config .input-field');
|
||||
await inputs.first().fill('Padova');
|
||||
await inputs.nth(1).fill('Milano');
|
||||
|
||||
// Salva
|
||||
await controllerPage.locator('.dialog-config .btn-confirm').click();
|
||||
await controllerPage.waitForTimeout(300);
|
||||
|
||||
// Verifica sul Controller
|
||||
await expect(controllerPage.locator('.team-score.home-bg .team-name')).toHaveText('Padova');
|
||||
await expect(controllerPage.locator('.team-score.guest-bg .team-name')).toHaveText('Milano');
|
||||
|
||||
// Verifica sul Display
|
||||
await expect(displayPage.locator('.hea.home')).toContainText('Padova');
|
||||
await expect(displayPage.locator('.hea.guest')).toContainText('Milano');
|
||||
});
|
||||
|
||||
test('Toggle Formazione: dovrebbe mostrare la formazione sul display', async ({ context }) => {
|
||||
const displayPage = await context.newPage();
|
||||
const controllerPage = await context.newPage();
|
||||
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
// Inizialmente mostra punteggio, non formazione
|
||||
await expect(displayPage.locator('.punteggio-container')).toBeVisible();
|
||||
|
||||
// Click Formazioni
|
||||
await controllerPage.getByText('Formazioni').click();
|
||||
await controllerPage.waitForTimeout(300);
|
||||
|
||||
// Il display mostra le formazioni
|
||||
await expect(displayPage.locator('.form').first()).toBeVisible();
|
||||
});
|
||||
|
||||
test('Toggle Striscia: dovrebbe nascondere/mostrare la striscia', async ({ context }) => {
|
||||
const displayPage = await context.newPage();
|
||||
const controllerPage = await context.newPage();
|
||||
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
// Inizialmente la striscia è visibile
|
||||
await expect(displayPage.locator('.striscia')).toBeVisible();
|
||||
|
||||
// Toggle off
|
||||
await controllerPage.getByText('Striscia').click();
|
||||
await controllerPage.waitForTimeout(300);
|
||||
await expect(displayPage.locator('.striscia')).not.toBeVisible();
|
||||
|
||||
// Toggle on
|
||||
await controllerPage.getByText('Striscia').click();
|
||||
await controllerPage.waitForTimeout(300);
|
||||
await expect(displayPage.locator('.striscia')).toBeVisible();
|
||||
});
|
||||
|
||||
test('Cambi: dovrebbe effettuare una sostituzione giocatore', async ({ context }) => {
|
||||
const displayPage = await context.newPage();
|
||||
const controllerPage = await context.newPage();
|
||||
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Attiva formazione sul display per verificare
|
||||
await controllerPage.getByText('Formazioni').click();
|
||||
await controllerPage.waitForTimeout(200);
|
||||
|
||||
// Apri cambi → scegli Home
|
||||
await controllerPage.getByRole('button', { name: 'Cambi', exact: true }).click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
await controllerPage.locator('.dialog .btn-set.home-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
|
||||
// Inserisci sostituzione: IN=10, OUT=1
|
||||
const inField = controllerPage.locator('.cambi-in-field').first();
|
||||
const outField = controllerPage.locator('.cambi-out-field').first();
|
||||
await inField.fill('10');
|
||||
await outField.fill('1');
|
||||
|
||||
// Conferma
|
||||
await controllerPage.locator('.dialog .btn-confirm').click();
|
||||
await controllerPage.waitForTimeout(300);
|
||||
|
||||
// Verifica formazione aggiornata sul display
|
||||
const formText = await displayPage.locator('.form.home').textContent();
|
||||
expect(formText).toContain('10');
|
||||
});
|
||||
|
||||
test('Cambi: dovrebbe mostrare errore per giocatore non in formazione', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Apri cambi → scegli Home
|
||||
await controllerPage.getByRole('button', { name: 'Cambi', exact: true }).click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
await controllerPage.locator('.dialog .btn-set.home-bg').click();
|
||||
await controllerPage.waitForTimeout(100);
|
||||
|
||||
// Inserisci sostituzione invalida: OUT=99 (non in formazione)
|
||||
await controllerPage.locator('.cambi-in-field').first().fill('10');
|
||||
await controllerPage.locator('.cambi-out-field').first().fill('99');
|
||||
|
||||
// Conferma
|
||||
await controllerPage.locator('.dialog .btn-confirm').click();
|
||||
await controllerPage.waitForTimeout(200);
|
||||
|
||||
// Dovrebbe mostrare errore
|
||||
await expect(controllerPage.locator('.cambi-error')).toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
test.describe('Game Simulation', () => {
|
||||
test('Simulazione Partita: Controller aggiunge punti finché non cambia il set', async ({ context }) => {
|
||||
86
tests/e2e/visual-regression.spec.cjs
Normal file
@@ -0,0 +1,86 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
// 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('Display: screenshot a 0-0', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
const displayPage = await context.newPage();
|
||||
|
||||
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);
|
||||
|
||||
// Attende che il display riceva lo stato
|
||||
await displayPage.waitForTimeout(500);
|
||||
|
||||
await expect(displayPage).toHaveScreenshot('display-0-0.png', {
|
||||
maxDiffPixelRatio: 0.05,
|
||||
});
|
||||
});
|
||||
|
||||
test('Display: screenshot durante partita (15-12)', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
const displayPage = await context.newPage();
|
||||
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await displayPage.goto('http://localhost:3000');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Porta il punteggio a 15-12
|
||||
for (let i = 0; i < 15; i++) {
|
||||
await controllerPage.locator('.team-score.home-bg').click();
|
||||
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 expect(displayPage).toHaveScreenshot('display-15-12.png', {
|
||||
maxDiffPixelRatio: 0.05,
|
||||
});
|
||||
});
|
||||
|
||||
test('Controller: screenshot stato iniziale', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
await expect(controllerPage).toHaveScreenshot('controller-initial.png', {
|
||||
maxDiffPixelRatio: 0.05,
|
||||
});
|
||||
});
|
||||
|
||||
test('Controller: screenshot con modal config aperta', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.goto('http://localhost:3001');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
|
||||
// Apri config
|
||||
await controllerPage.getByText('Config').click();
|
||||
await controllerPage.waitForSelector('.dialog-config');
|
||||
await controllerPage.waitForTimeout(300);
|
||||
|
||||
await expect(controllerPage).toHaveScreenshot('controller-config-modal.png', {
|
||||
maxDiffPixelRatio: 0.05,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 53 KiB |
@@ -16,68 +16,388 @@ class MockWebSocketServer extends EventEmitter {
|
||||
clients = new Set()
|
||||
}
|
||||
|
||||
// Helper: connette e registra un client
|
||||
function connectAndRegister(wss, role) {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
wss.clients.add(ws)
|
||||
ws.emit('message', JSON.stringify({ type: 'register', role }))
|
||||
ws.send.mockClear()
|
||||
return ws
|
||||
}
|
||||
|
||||
// Helper: ultimo messaggio inviato a un ws
|
||||
function lastSent(ws) {
|
||||
const calls = ws.send.mock.calls
|
||||
return JSON.parse(calls[calls.length - 1][0])
|
||||
}
|
||||
|
||||
describe('WebSocket Integration (websocket-handler.js)', () => {
|
||||
let wss
|
||||
let handler
|
||||
let ws
|
||||
|
||||
beforeEach(() => {
|
||||
wss = new MockWebSocketServer()
|
||||
handler = setupWebSocketHandler(wss)
|
||||
ws = new MockWebSocket()
|
||||
// Simuliamo la connessione
|
||||
wss.emit('connection', ws)
|
||||
// Aggiungiamo il client al set del server (come farebbe 'ws' realmente)
|
||||
wss.clients.add(ws)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('dovrebbe registrare un client come "display" e inviare lo stato', () => {
|
||||
ws.emit('message', JSON.stringify({ type: 'register', role: 'display' }))
|
||||
// =============================================
|
||||
// REGISTRAZIONE
|
||||
// =============================================
|
||||
describe('Registrazione', () => {
|
||||
it('dovrebbe registrare un client come "display" e inviare lo stato', () => {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
wss.clients.add(ws)
|
||||
ws.emit('message', JSON.stringify({ type: 'register', role: 'display' }))
|
||||
|
||||
// Verifica che abbia inviato lo stato iniziale
|
||||
expect(ws.send).toHaveBeenCalled()
|
||||
const sentMsg = JSON.parse(ws.send.mock.calls[0][0])
|
||||
expect(sentMsg.type).toBe('state')
|
||||
expect(sentMsg.state).toBeDefined()
|
||||
expect(ws.send).toHaveBeenCalled()
|
||||
const sentMsg = JSON.parse(ws.send.mock.calls[0][0])
|
||||
expect(sentMsg.type).toBe('state')
|
||||
expect(sentMsg.state).toBeDefined()
|
||||
})
|
||||
|
||||
it('dovrebbe registrare un client come "controller"', () => {
|
||||
connectAndRegister(wss, 'controller')
|
||||
expect(handler.getClients().size).toBe(1)
|
||||
})
|
||||
|
||||
it('dovrebbe rifiutare ruolo non valido', () => {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
wss.clients.add(ws)
|
||||
ws.emit('message', JSON.stringify({ type: 'register', role: 'hacker' }))
|
||||
|
||||
const sentMsg = JSON.parse(ws.send.mock.calls[0][0])
|
||||
expect(sentMsg.type).toBe('error')
|
||||
expect(sentMsg.message).toContain('Invalid role')
|
||||
})
|
||||
|
||||
it('dovrebbe usare "display" come ruolo default se mancante', () => {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
wss.clients.add(ws)
|
||||
ws.emit('message', JSON.stringify({ type: 'register' }))
|
||||
|
||||
const sentMsg = JSON.parse(ws.send.mock.calls[0][0])
|
||||
expect(sentMsg.type).toBe('state')
|
||||
})
|
||||
})
|
||||
|
||||
it('dovrebbe permettere al controller di cambiare il punteggio', () => {
|
||||
// 1. Registra Controller
|
||||
ws.emit('message', JSON.stringify({ type: 'register', role: 'controller' }))
|
||||
ws.send.mockClear() // pulisco chiamate precedenti
|
||||
// =============================================
|
||||
// AZIONI
|
||||
// =============================================
|
||||
describe('Azioni', () => {
|
||||
it('dovrebbe permettere al controller di cambiare il punteggio', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
|
||||
// 2. Invia Azione
|
||||
ws.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
|
||||
// 3. Verifica Broadcast del nuovo stato
|
||||
expect(ws.send).toHaveBeenCalled()
|
||||
const sentMsg = JSON.parse(ws.send.mock.calls[0][0])
|
||||
expect(sentMsg.type).toBe('state')
|
||||
expect(sentMsg.state.sp.punt.home).toBe(1)
|
||||
expect(controller.send).toHaveBeenCalled()
|
||||
const sentMsg = lastSent(controller)
|
||||
expect(sentMsg.type).toBe('state')
|
||||
expect(sentMsg.state.sp.punt.home).toBe(1)
|
||||
})
|
||||
|
||||
it('dovrebbe impedire al display di inviare azioni', () => {
|
||||
const display = connectAndRegister(wss, 'display')
|
||||
|
||||
display.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
|
||||
const sentMsg = lastSent(display)
|
||||
expect(sentMsg.type).toBe('error')
|
||||
expect(sentMsg.message).toContain('Only controllers')
|
||||
})
|
||||
|
||||
it('dovrebbe impedire azioni da client non registrati', () => {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
wss.clients.add(ws)
|
||||
|
||||
ws.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
|
||||
const sentMsg = JSON.parse(ws.send.mock.calls[0][0])
|
||||
expect(sentMsg.type).toBe('error')
|
||||
expect(sentMsg.message).toContain('Only controllers')
|
||||
})
|
||||
|
||||
it('dovrebbe rifiutare azione con formato invalido (missing action)', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'action'
|
||||
}))
|
||||
|
||||
const sentMsg = lastSent(controller)
|
||||
expect(sentMsg.type).toBe('error')
|
||||
expect(sentMsg.message).toContain('Invalid action format')
|
||||
})
|
||||
|
||||
it('dovrebbe rifiutare azione con formato invalido (missing action.type)', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { team: 'home' }
|
||||
}))
|
||||
|
||||
const sentMsg = lastSent(controller)
|
||||
expect(sentMsg.type).toBe('error')
|
||||
expect(sentMsg.message).toContain('Invalid action format')
|
||||
})
|
||||
})
|
||||
|
||||
it('dovrebbe impedire al display di inviare azioni', () => {
|
||||
// 1. Registra Display
|
||||
ws.emit('message', JSON.stringify({ type: 'register', role: 'display' }))
|
||||
ws.send.mockClear()
|
||||
// =============================================
|
||||
// BROADCAST MULTI-CLIENT
|
||||
// =============================================
|
||||
describe('Broadcast', () => {
|
||||
it('dovrebbe inviare lo stato a tutti i client dopo un\'azione', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
const display1 = connectAndRegister(wss, 'display')
|
||||
const display2 = connectAndRegister(wss, 'display')
|
||||
|
||||
// 2. Tenta Azione
|
||||
ws.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
|
||||
// 3. Verifica Errore
|
||||
expect(ws.send).toHaveBeenCalled()
|
||||
const sentMsg = JSON.parse(ws.send.mock.calls[0][0])
|
||||
expect(sentMsg.type).toBe('error')
|
||||
expect(sentMsg.message).toContain('Only controllers')
|
||||
// Tutti i client nel set dovrebbero aver ricevuto lo stato
|
||||
expect(controller.send).toHaveBeenCalled()
|
||||
expect(display1.send).toHaveBeenCalled()
|
||||
expect(display2.send).toHaveBeenCalled()
|
||||
|
||||
const msg1 = lastSent(display1)
|
||||
const msg2 = lastSent(display2)
|
||||
expect(msg1.type).toBe('state')
|
||||
expect(msg1.state.sp.punt.home).toBe(1)
|
||||
expect(msg2.state.sp.punt.home).toBe(1)
|
||||
})
|
||||
|
||||
it('non dovrebbe inviare a client con readyState != OPEN', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
const closedClient = connectAndRegister(wss, 'display')
|
||||
closedClient.readyState = 3 // CLOSED
|
||||
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
|
||||
// closedClient non dovrebbe aver ricevuto il broadcast
|
||||
expect(closedClient.send).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// SPEAK
|
||||
// =============================================
|
||||
describe('Speak', () => {
|
||||
it('dovrebbe inoltrare il messaggio speak solo ai display', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
const display = connectAndRegister(wss, 'display')
|
||||
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'speak',
|
||||
text: 'quindici a dieci'
|
||||
}))
|
||||
|
||||
// Il display riceve il messaggio speak
|
||||
expect(display.send).toHaveBeenCalled()
|
||||
const msg = lastSent(display)
|
||||
expect(msg.type).toBe('speak')
|
||||
expect(msg.text).toBe('quindici a dieci')
|
||||
})
|
||||
|
||||
it('non dovrebbe permettere al display di inviare speak', () => {
|
||||
const display = connectAndRegister(wss, 'display')
|
||||
|
||||
display.emit('message', JSON.stringify({
|
||||
type: 'speak',
|
||||
text: 'test'
|
||||
}))
|
||||
|
||||
const msg = lastSent(display)
|
||||
expect(msg.type).toBe('error')
|
||||
expect(msg.message).toContain('Only controllers')
|
||||
})
|
||||
|
||||
it('dovrebbe rifiutare speak con testo vuoto', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'speak',
|
||||
text: ' '
|
||||
}))
|
||||
|
||||
const msg = lastSent(controller)
|
||||
expect(msg.type).toBe('error')
|
||||
expect(msg.message).toContain('Invalid speak payload')
|
||||
})
|
||||
|
||||
it('dovrebbe rifiutare speak senza testo', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'speak'
|
||||
}))
|
||||
|
||||
const msg = lastSent(controller)
|
||||
expect(msg.type).toBe('error')
|
||||
})
|
||||
|
||||
it('dovrebbe fare trim del testo speak', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
const display = connectAndRegister(wss, 'display')
|
||||
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'speak',
|
||||
text: ' dieci a otto '
|
||||
}))
|
||||
|
||||
const msg = lastSent(display)
|
||||
expect(msg.text).toBe('dieci a otto')
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// MESSAGGI MALFORMATI
|
||||
// =============================================
|
||||
describe('Messaggi malformati', () => {
|
||||
it('dovrebbe gestire JSON non valido senza crash', () => {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
wss.clients.add(ws)
|
||||
|
||||
expect(() => {
|
||||
ws.emit('message', 'questo non è JSON {{{')
|
||||
}).not.toThrow()
|
||||
|
||||
const msg = lastSent(ws)
|
||||
expect(msg.type).toBe('error')
|
||||
expect(msg.message).toContain('Invalid message format')
|
||||
})
|
||||
|
||||
it('dovrebbe gestire Buffer come input', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
|
||||
const buf = Buffer.from(JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
|
||||
controller.emit('message', buf)
|
||||
|
||||
const msg = lastSent(controller)
|
||||
expect(msg.type).toBe('state')
|
||||
expect(msg.state.sp.punt.home).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// DISCONNESSIONE
|
||||
// =============================================
|
||||
describe('Disconnessione', () => {
|
||||
it('dovrebbe rimuovere il client dalla mappa alla disconnessione', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
expect(handler.getClients().size).toBe(1)
|
||||
|
||||
controller.emit('close')
|
||||
|
||||
expect(handler.getClients().size).toBe(0)
|
||||
})
|
||||
|
||||
it('i client rimanenti non dovrebbero essere affetti dalla disconnessione', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
const display = connectAndRegister(wss, 'display')
|
||||
expect(handler.getClients().size).toBe(2)
|
||||
|
||||
controller.emit('close')
|
||||
expect(handler.getClients().size).toBe(1)
|
||||
|
||||
expect(handler.getClients().has(display)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// ERRORI WEBSOCKET
|
||||
// =============================================
|
||||
describe('Errori WebSocket', () => {
|
||||
it('dovrebbe terminare la connessione per errore UTF8 invalido', () => {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
|
||||
const err = new Error('Invalid UTF8')
|
||||
err.code = 'WS_ERR_INVALID_UTF8'
|
||||
ws.emit('error', err)
|
||||
|
||||
expect(ws.terminate).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('dovrebbe terminare la connessione per close code invalido', () => {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
|
||||
const err = new Error('Invalid close code')
|
||||
err.code = 'WS_ERR_INVALID_CLOSE_CODE'
|
||||
ws.emit('error', err)
|
||||
|
||||
expect(ws.terminate).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('non dovrebbe terminare per altri errori', () => {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
|
||||
const err = new Error('Generic error')
|
||||
ws.emit('error', err)
|
||||
|
||||
expect(ws.terminate).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// API PUBBLICA
|
||||
// =============================================
|
||||
describe('API pubblica', () => {
|
||||
it('getState dovrebbe restituire lo stato corrente', () => {
|
||||
const state = handler.getState()
|
||||
expect(state.sp.punt.home).toBe(0)
|
||||
expect(state.sp.punt.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('setState dovrebbe sovrascrivere lo stato', () => {
|
||||
const newState = handler.getState()
|
||||
newState.sp.punt.home = 99
|
||||
handler.setState(newState)
|
||||
expect(handler.getState().sp.punt.home).toBe(99)
|
||||
})
|
||||
|
||||
it('broadcastState dovrebbe inviare a tutti i client', () => {
|
||||
const display = connectAndRegister(wss, 'display')
|
||||
handler.broadcastState()
|
||||
expect(display.send).toHaveBeenCalled()
|
||||
const msg = lastSent(display)
|
||||
expect(msg.type).toBe('state')
|
||||
})
|
||||
|
||||
it('getClients dovrebbe restituire la mappa dei client', () => {
|
||||
expect(handler.getClients()).toBeInstanceOf(Map)
|
||||
expect(handler.getClients().size).toBe(0)
|
||||
connectAndRegister(wss, 'display')
|
||||
expect(handler.getClients().size).toBe(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
118
tests/stress/websocket-load.test.js
Normal file
@@ -0,0 +1,118 @@
|
||||
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
|
||||
import { setupWebSocketHandler } from '../../src/websocket-handler.js'
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
class MockWebSocket extends EventEmitter {
|
||||
constructor() {
|
||||
super()
|
||||
this.readyState = 1
|
||||
}
|
||||
send = vi.fn()
|
||||
terminate = vi.fn()
|
||||
}
|
||||
|
||||
class MockWebSocketServer extends EventEmitter {
|
||||
clients = new Set()
|
||||
}
|
||||
|
||||
function connectAndRegister(wss, role) {
|
||||
const ws = new MockWebSocket()
|
||||
wss.emit('connection', ws)
|
||||
wss.clients.add(ws)
|
||||
ws.emit('message', JSON.stringify({ type: 'register', role }))
|
||||
ws.send.mockClear()
|
||||
return ws
|
||||
}
|
||||
|
||||
describe('Stress Test WebSocket', () => {
|
||||
let wss
|
||||
let handler
|
||||
|
||||
beforeEach(() => {
|
||||
wss = new MockWebSocketServer()
|
||||
handler = setupWebSocketHandler(wss)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('dovrebbe gestire 50 client display connessi simultaneamente', () => {
|
||||
const displays = []
|
||||
for (let i = 0; i < 50; i++) {
|
||||
displays.push(connectAndRegister(wss, 'display'))
|
||||
}
|
||||
|
||||
expect(handler.getClients().size).toBe(50)
|
||||
|
||||
// Un controller invia un'azione
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
|
||||
// Tutti i display devono aver ricevuto il broadcast
|
||||
for (const display of displays) {
|
||||
expect(display.send).toHaveBeenCalled()
|
||||
const msg = JSON.parse(display.send.mock.calls[display.send.mock.calls.length - 1][0])
|
||||
expect(msg.type).toBe('state')
|
||||
expect(msg.state.sp.punt.home).toBe(1)
|
||||
}
|
||||
})
|
||||
|
||||
it('dovrebbe gestire 100 azioni rapide in sequenza con stato finale corretto', () => {
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
|
||||
// 60 punti home, 40 punti guest
|
||||
for (let i = 0; i < 60; i++) {
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
}
|
||||
for (let i = 0; i < 40; i++) {
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'guest' }
|
||||
}))
|
||||
}
|
||||
|
||||
// Lo stato finale dipende da checkVittoria che blocca a 25+2
|
||||
// Home arriva a 25-0 → vittoria → blocca. Quindi punti home = 25
|
||||
const state = handler.getState()
|
||||
expect(state.sp.punt.home).toBe(25)
|
||||
// Guest: non può segnare dopo vittoria? No, checkVittoria blocca solo il team che ha vinto?
|
||||
// Controlliamo: checkVittoria controlla ENTRAMBI i team.
|
||||
// A 25-0 → vittoria=true → incPunt per guest è anche bloccato
|
||||
expect(state.sp.punt.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe garantire che tutti i display ricevano ogni update sotto carico', () => {
|
||||
const displays = []
|
||||
for (let i = 0; i < 10; i++) {
|
||||
displays.push(connectAndRegister(wss, 'display'))
|
||||
}
|
||||
|
||||
const controller = connectAndRegister(wss, 'controller')
|
||||
|
||||
// 5 azioni rapide
|
||||
for (let i = 0; i < 5; i++) {
|
||||
controller.emit('message', JSON.stringify({
|
||||
type: 'action',
|
||||
action: { type: 'incPunt', team: 'home' }
|
||||
}))
|
||||
}
|
||||
|
||||
// Ogni display deve aver ricevuto esattamente 5 broadcast
|
||||
for (const display of displays) {
|
||||
expect(display.send).toHaveBeenCalledTimes(5)
|
||||
}
|
||||
|
||||
// Verifica stato finale su tutti i display
|
||||
for (const display of displays) {
|
||||
const lastMsg = JSON.parse(display.send.mock.calls[4][0])
|
||||
expect(lastMsg.state.sp.punt.home).toBe(5)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -8,7 +8,10 @@ describe('Game Logic (gameState.js)', () => {
|
||||
state = createInitialState()
|
||||
})
|
||||
|
||||
describe('Initial State', () => {
|
||||
// =============================================
|
||||
// STATO INIZIALE
|
||||
// =============================================
|
||||
describe('Stato iniziale', () => {
|
||||
it('dovrebbe iniziare con 0-0', () => {
|
||||
expect(state.sp.punt.home).toBe(0)
|
||||
expect(state.sp.punt.guest).toBe(0)
|
||||
@@ -18,40 +21,451 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(state.sp.set.home).toBe(0)
|
||||
expect(state.sp.set.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe avere servizio Home', () => {
|
||||
expect(state.sp.servHome).toBe(true)
|
||||
})
|
||||
|
||||
it('dovrebbe avere formazione di default [1-6]', () => {
|
||||
expect(state.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
expect(state.sp.form.guest).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('dovrebbe avere la striscia iniziale a [0]', () => {
|
||||
expect(state.sp.striscia.home).toEqual([0])
|
||||
expect(state.sp.striscia.guest).toEqual([0])
|
||||
})
|
||||
|
||||
it('dovrebbe avere storico servizio vuoto', () => {
|
||||
expect(state.sp.storicoServizio).toEqual([])
|
||||
})
|
||||
|
||||
it('dovrebbe avere modalità 3/5 di default', () => {
|
||||
expect(state.modalitaPartita).toBe("3/5")
|
||||
})
|
||||
|
||||
it('dovrebbe avere visuForm false e visuStriscia true', () => {
|
||||
expect(state.visuForm).toBe(false)
|
||||
expect(state.visuStriscia).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Punteggio', () => {
|
||||
it('dovrebbe incrementare i punti (Home)', () => {
|
||||
// =============================================
|
||||
// IMMUTABILITÀ
|
||||
// =============================================
|
||||
describe('Immutabilità', () => {
|
||||
it('applyAction non dovrebbe mutare lo stato originale', () => {
|
||||
const original = JSON.stringify(state)
|
||||
applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(JSON.stringify(state)).toBe(original)
|
||||
})
|
||||
|
||||
it('dovrebbe restituire un nuovo oggetto', () => {
|
||||
const newState = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(newState).not.toBe(state)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// INCREMENTO PUNTI (incPunt)
|
||||
// =============================================
|
||||
describe('incPunt', () => {
|
||||
it('dovrebbe incrementare i punti Home', () => {
|
||||
const newState = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(newState.sp.punt.home).toBe(1)
|
||||
expect(newState.sp.punt.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe gestire il cambio palla', () => {
|
||||
// Home batte
|
||||
state.sp.servHome = true
|
||||
// Punto Guest -> Cambio palla
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
expect(s1.sp.servHome).toBe(false) // Ora batte Guest
|
||||
|
||||
// Punto Home -> Cambio palla
|
||||
const s2 = applyAction(s1, { type: 'incPunt', team: 'home' })
|
||||
expect(s2.sp.servHome).toBe(true) // Torna a battere Home
|
||||
it('dovrebbe incrementare i punti Guest', () => {
|
||||
const newState = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
expect(newState.sp.punt.guest).toBe(1)
|
||||
expect(newState.sp.punt.home).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe gestire la rotazione formazione al cambio palla', () => {
|
||||
state.sp.servHome = true // Batte Home
|
||||
it('dovrebbe gestire il cambio palla (Guest segna, batteva Home)', () => {
|
||||
state.sp.servHome = true
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
expect(s1.sp.servHome).toBe(false)
|
||||
})
|
||||
|
||||
it('dovrebbe gestire il cambio palla (Home segna, batteva Guest)', () => {
|
||||
state.sp.servHome = false
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(s1.sp.servHome).toBe(true)
|
||||
})
|
||||
|
||||
it('non dovrebbe cambiare palla se segna chi batte', () => {
|
||||
state.sp.servHome = true
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(s1.sp.servHome).toBe(true)
|
||||
})
|
||||
|
||||
it('dovrebbe ruotare la formazione al cambio palla', () => {
|
||||
state.sp.servHome = true
|
||||
state.sp.form.guest = ["1", "2", "3", "4", "5", "6"]
|
||||
|
||||
// Punto Guest -> Cambio palla e rotazione Guest
|
||||
const newState = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
|
||||
// Verifica che la formazione sia ruotata (il primo elemento diventa ultimo)
|
||||
expect(newState.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
|
||||
})
|
||||
|
||||
it('non dovrebbe ruotare la formazione se non c\'è cambio palla', () => {
|
||||
state.sp.servHome = true
|
||||
state.sp.form.home = ["1", "2", "3", "4", "5", "6"]
|
||||
const newState = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(newState.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('dovrebbe aggiornare la striscia per punto Home', () => {
|
||||
const s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(s.sp.striscia.home).toEqual([0, 1])
|
||||
expect(s.sp.striscia.guest).toEqual([0, " "])
|
||||
})
|
||||
|
||||
it('dovrebbe aggiornare la striscia per punto Guest', () => {
|
||||
const s = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
expect(s.sp.striscia.guest).toEqual([0, 1])
|
||||
expect(s.sp.striscia.home).toEqual([0, " "])
|
||||
})
|
||||
|
||||
it('dovrebbe registrare lo storico servizio', () => {
|
||||
const s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(s.sp.storicoServizio).toHaveLength(1)
|
||||
expect(s.sp.storicoServizio[0]).toHaveProperty('servHome')
|
||||
expect(s.sp.storicoServizio[0]).toHaveProperty('cambioPalla')
|
||||
})
|
||||
|
||||
it('non dovrebbe incrementare i punti dopo vittoria', () => {
|
||||
state.sp.punt.home = 25
|
||||
state.sp.punt.guest = 23
|
||||
const s = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
expect(s.sp.punt.home).toBe(25)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Vittoria Set', () => {
|
||||
// =============================================
|
||||
// DECREMENTO PUNTI (decPunt)
|
||||
// =============================================
|
||||
describe('decPunt', () => {
|
||||
it('dovrebbe annullare l\'ultimo punto Home', () => {
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||
expect(s2.sp.punt.home).toBe(0)
|
||||
expect(s2.sp.punt.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe annullare l\'ultimo punto Guest', () => {
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||
expect(s2.sp.punt.home).toBe(0)
|
||||
expect(s2.sp.punt.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('non dovrebbe fare nulla sullo stato iniziale', () => {
|
||||
const s = applyAction(state, { type: 'decPunt' })
|
||||
expect(s.sp.punt.home).toBe(0)
|
||||
expect(s.sp.punt.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe ripristinare il servizio dopo undo con cambio palla', () => {
|
||||
state.sp.servHome = true
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
expect(s1.sp.servHome).toBe(false)
|
||||
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||
expect(s2.sp.servHome).toBe(true)
|
||||
})
|
||||
|
||||
it('dovrebbe invertire la rotazione dopo undo con cambio palla', () => {
|
||||
state.sp.servHome = true
|
||||
state.sp.form.guest = ["1", "2", "3", "4", "5", "6"]
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'guest' })
|
||||
expect(s1.sp.form.guest).toEqual(["2", "3", "4", "5", "6", "1"])
|
||||
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||
expect(s2.sp.form.guest).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('dovrebbe ripristinare la striscia', () => {
|
||||
const s1 = applyAction(state, { type: 'incPunt', team: 'home' })
|
||||
const s2 = applyAction(s1, { type: 'decPunt' })
|
||||
expect(s2.sp.striscia.home).toEqual([0])
|
||||
})
|
||||
|
||||
it('dovrebbe gestire undo multipli in sequenza', () => {
|
||||
let s = state
|
||||
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||
s = applyAction(s, { type: 'incPunt', team: 'guest' })
|
||||
s = applyAction(s, { type: 'incPunt', team: 'home' })
|
||||
expect(s.sp.punt.home).toBe(2)
|
||||
expect(s.sp.punt.guest).toBe(1)
|
||||
s = applyAction(s, { type: 'decPunt' })
|
||||
expect(s.sp.punt.home).toBe(1)
|
||||
s = applyAction(s, { type: 'decPunt' })
|
||||
expect(s.sp.punt.guest).toBe(0)
|
||||
s = applyAction(s, { type: 'decPunt' })
|
||||
expect(s.sp.punt.home).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// INCREMENTO SET (incSet)
|
||||
// =============================================
|
||||
describe('incSet', () => {
|
||||
it('dovrebbe incrementare il set Home', () => {
|
||||
const s = applyAction(state, { type: 'incSet', team: 'home' })
|
||||
expect(s.sp.set.home).toBe(1)
|
||||
})
|
||||
|
||||
it('dovrebbe incrementare il set Guest', () => {
|
||||
const s = applyAction(state, { type: 'incSet', team: 'guest' })
|
||||
expect(s.sp.set.guest).toBe(1)
|
||||
})
|
||||
|
||||
it('dovrebbe fare wrap da 2 a 0', () => {
|
||||
state.sp.set.home = 2
|
||||
const s = applyAction(state, { type: 'incSet', team: 'home' })
|
||||
expect(s.sp.set.home).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe incrementare da 1 a 2', () => {
|
||||
state.sp.set.home = 1
|
||||
const s = applyAction(state, { type: 'incSet', team: 'home' })
|
||||
expect(s.sp.set.home).toBe(2)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// CAMBIO PALLA (cambiaPalla)
|
||||
// =============================================
|
||||
describe('cambiaPalla', () => {
|
||||
it('dovrebbe invertire il servizio a 0-0', () => {
|
||||
expect(state.sp.servHome).toBe(true)
|
||||
const s = applyAction(state, { type: 'cambiaPalla' })
|
||||
expect(s.sp.servHome).toBe(false)
|
||||
})
|
||||
|
||||
it('dovrebbe tornare a Home con doppio toggle', () => {
|
||||
let s = applyAction(state, { type: 'cambiaPalla' })
|
||||
s = applyAction(s, { type: 'cambiaPalla' })
|
||||
expect(s.sp.servHome).toBe(true)
|
||||
})
|
||||
|
||||
it('non dovrebbe cambiare palla se il punteggio non è 0-0', () => {
|
||||
state.sp.punt.home = 1
|
||||
const s = applyAction(state, { type: 'cambiaPalla' })
|
||||
expect(s.sp.servHome).toBe(true)
|
||||
})
|
||||
|
||||
it('non dovrebbe cambiare palla se Guest ha punti', () => {
|
||||
state.sp.punt.guest = 3
|
||||
const s = applyAction(state, { type: 'cambiaPalla' })
|
||||
expect(s.sp.servHome).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// TOGGLE (toggleFormazione, toggleStriscia, toggleOrder)
|
||||
// =============================================
|
||||
describe('Toggle', () => {
|
||||
it('toggleFormazione: false → true', () => {
|
||||
expect(state.visuForm).toBe(false)
|
||||
const s = applyAction(state, { type: 'toggleFormazione' })
|
||||
expect(s.visuForm).toBe(true)
|
||||
})
|
||||
|
||||
it('toggleFormazione: true → false', () => {
|
||||
state.visuForm = true
|
||||
const s = applyAction(state, { type: 'toggleFormazione' })
|
||||
expect(s.visuForm).toBe(false)
|
||||
})
|
||||
|
||||
it('toggleStriscia: true → false', () => {
|
||||
expect(state.visuStriscia).toBe(true)
|
||||
const s = applyAction(state, { type: 'toggleStriscia' })
|
||||
expect(s.visuStriscia).toBe(false)
|
||||
})
|
||||
|
||||
it('toggleOrder: true → false', () => {
|
||||
expect(state.order).toBe(true)
|
||||
const s = applyAction(state, { type: 'toggleOrder' })
|
||||
expect(s.order).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// NOMI (setNomi)
|
||||
// =============================================
|
||||
describe('setNomi', () => {
|
||||
it('dovrebbe aggiornare entrambi i nomi', () => {
|
||||
const s = applyAction(state, { type: 'setNomi', home: 'Volley A', guest: 'Volley B' })
|
||||
expect(s.sp.nomi.home).toBe('Volley A')
|
||||
expect(s.sp.nomi.guest).toBe('Volley B')
|
||||
})
|
||||
|
||||
it('dovrebbe aggiornare solo il nome Home se guest è undefined', () => {
|
||||
const s = applyAction(state, { type: 'setNomi', home: 'Volley A' })
|
||||
expect(s.sp.nomi.home).toBe('Volley A')
|
||||
expect(s.sp.nomi.guest).toBe('Guest')
|
||||
})
|
||||
|
||||
it('dovrebbe aggiornare solo il nome Guest se home è undefined', () => {
|
||||
const s = applyAction(state, { type: 'setNomi', guest: 'Volley B' })
|
||||
expect(s.sp.nomi.home).toBe('Antoniana')
|
||||
expect(s.sp.nomi.guest).toBe('Volley B')
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// MODALITÀ (setModalita)
|
||||
// =============================================
|
||||
describe('setModalita', () => {
|
||||
it('dovrebbe cambiare in 2/3', () => {
|
||||
const s = applyAction(state, { type: 'setModalita', modalita: '2/3' })
|
||||
expect(s.modalitaPartita).toBe('2/3')
|
||||
})
|
||||
|
||||
it('dovrebbe cambiare in 3/5', () => {
|
||||
state.modalitaPartita = '2/3'
|
||||
const s = applyAction(state, { type: 'setModalita', modalita: '3/5' })
|
||||
expect(s.modalitaPartita).toBe('3/5')
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// FORMAZIONE (setFormazione)
|
||||
// =============================================
|
||||
describe('setFormazione', () => {
|
||||
it('dovrebbe sostituire la formazione Home', () => {
|
||||
const nuova = ["10", "11", "12", "13", "14", "15"]
|
||||
const s = applyAction(state, { type: 'setFormazione', team: 'home', form: nuova })
|
||||
expect(s.sp.form.home).toEqual(nuova)
|
||||
})
|
||||
|
||||
it('dovrebbe sostituire la formazione Guest', () => {
|
||||
const nuova = ["7", "8", "9", "10", "11", "12"]
|
||||
const s = applyAction(state, { type: 'setFormazione', team: 'guest', form: nuova })
|
||||
expect(s.sp.form.guest).toEqual(nuova)
|
||||
})
|
||||
|
||||
it('non dovrebbe modificare se manca team', () => {
|
||||
const s = applyAction(state, { type: 'setFormazione', form: ["7", "8", "9", "10", "11", "12"] })
|
||||
expect(s.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('non dovrebbe modificare se manca form', () => {
|
||||
const s = applyAction(state, { type: 'setFormazione', team: 'home' })
|
||||
expect(s.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// CAMBI GIOCATORI (confermaCambi)
|
||||
// =============================================
|
||||
describe('confermaCambi', () => {
|
||||
it('dovrebbe effettuare una sostituzione valida', () => {
|
||||
state.sp.form.home = ["1", "2", "3", "4", "5", "6"]
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "10", out: "3" }]
|
||||
})
|
||||
expect(s.sp.form.home).toContain("10")
|
||||
expect(s.sp.form.home).not.toContain("3")
|
||||
})
|
||||
|
||||
it('dovrebbe gestire doppia sostituzione', () => {
|
||||
state.sp.form.home = ["1", "2", "3", "4", "5", "6"]
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [
|
||||
{ in: "10", out: "1" },
|
||||
{ in: "11", out: "2" }
|
||||
]
|
||||
})
|
||||
expect(s.sp.form.home).toContain("10")
|
||||
expect(s.sp.form.home).toContain("11")
|
||||
expect(s.sp.form.home).not.toContain("1")
|
||||
expect(s.sp.form.home).not.toContain("2")
|
||||
})
|
||||
|
||||
it('non dovrebbe accettare input non numerico', () => {
|
||||
state.sp.form.home = ["1", "2", "3", "4", "5", "6"]
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "abc", out: "1" }]
|
||||
})
|
||||
expect(s.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('non dovrebbe accettare in == out', () => {
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "1", out: "1" }]
|
||||
})
|
||||
expect(s.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('non dovrebbe accettare giocatore IN già in formazione', () => {
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "2", out: "1" }]
|
||||
})
|
||||
expect(s.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('non dovrebbe accettare giocatore OUT non in formazione', () => {
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "10", out: "99" }]
|
||||
})
|
||||
expect(s.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('dovrebbe saltare cambi con campo vuoto', () => {
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [
|
||||
{ in: "", out: "" },
|
||||
{ in: "10", out: "1" }
|
||||
]
|
||||
})
|
||||
expect(s.sp.form.home).toContain("10")
|
||||
})
|
||||
|
||||
it('dovrebbe mantenere la posizione del giocatore sostituito', () => {
|
||||
state.sp.form.home = ["1", "2", "3", "4", "5", "6"]
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [{ in: "10", out: "3" }]
|
||||
})
|
||||
expect(s.sp.form.home[2]).toBe("10")
|
||||
})
|
||||
|
||||
it('dovrebbe gestire cambi sequenziali che dipendono l\'uno dall\'altro', () => {
|
||||
// Sostituisci 1→10, poi 10→20 (il secondo dipende dal risultato del primo)
|
||||
state.sp.form.home = ["1", "2", "3", "4", "5", "6"]
|
||||
const s = applyAction(state, {
|
||||
type: 'confermaCambi',
|
||||
team: 'home',
|
||||
cambi: [
|
||||
{ in: "10", out: "1" },
|
||||
{ in: "20", out: "10" }
|
||||
]
|
||||
})
|
||||
expect(s.sp.form.home).toContain("20")
|
||||
expect(s.sp.form.home).not.toContain("1")
|
||||
expect(s.sp.form.home).not.toContain("10")
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// VITTORIA SET (checkVittoria)
|
||||
// =============================================
|
||||
describe('checkVittoria', () => {
|
||||
it('non dovrebbe dare vittoria a 24-24', () => {
|
||||
state.sp.punt.home = 24
|
||||
state.sp.punt.guest = 24
|
||||
@@ -64,28 +478,182 @@ describe('Game Logic (gameState.js)', () => {
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('dovrebbe richiedere 2 punti di scarto (26-24)', () => {
|
||||
it('non dovrebbe dare vittoria a 25-24 (serve 2 punti di scarto)', () => {
|
||||
state.sp.punt.home = 25
|
||||
state.sp.punt.guest = 24
|
||||
expect(checkVittoria(state)).toBe(false)
|
||||
})
|
||||
|
||||
it('dovrebbe dare vittoria a 26-24', () => {
|
||||
state.sp.punt.home = 26
|
||||
state.sp.punt.guest = 24
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('dovrebbe dare vittoria Guest a 25-20', () => {
|
||||
state.sp.punt.home = 20
|
||||
state.sp.punt.guest = 25
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('dovrebbe dare vittoria ai vantaggi (30-28)', () => {
|
||||
state.sp.punt.home = 30
|
||||
state.sp.punt.guest = 28
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('non dovrebbe dare vittoria ai vantaggi senza scarto (28-27)', () => {
|
||||
state.sp.punt.home = 28
|
||||
state.sp.punt.guest = 27
|
||||
expect(checkVittoria(state)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Reset', () => {
|
||||
it('dovrebbe resettare tutto a zero', () => {
|
||||
state.sp.punt.home = 10
|
||||
// =============================================
|
||||
// SET DECISIVO (15 punti)
|
||||
// =============================================
|
||||
describe('Set decisivo', () => {
|
||||
it('modalità 3/5: set decisivo dopo 4 set totali → vittoria a 15', () => {
|
||||
state.modalitaPartita = "3/5"
|
||||
state.sp.set.home = 2
|
||||
state.sp.set.guest = 2
|
||||
state.sp.punt.home = 15
|
||||
state.sp.punt.guest = 10
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('modalità 3/5: non vittoria a 14-10 nel set decisivo', () => {
|
||||
state.modalitaPartita = "3/5"
|
||||
state.sp.set.home = 2
|
||||
state.sp.set.guest = 2
|
||||
state.sp.punt.home = 14
|
||||
state.sp.punt.guest = 10
|
||||
expect(checkVittoria(state)).toBe(false)
|
||||
})
|
||||
|
||||
it('modalità 3/5: vittoria a 15-13 nel set decisivo', () => {
|
||||
state.modalitaPartita = "3/5"
|
||||
state.sp.set.home = 2
|
||||
state.sp.set.guest = 2
|
||||
state.sp.punt.home = 15
|
||||
state.sp.punt.guest = 13
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('modalità 3/5: non vittoria a 15-14 nel set decisivo (serve scarto)', () => {
|
||||
state.modalitaPartita = "3/5"
|
||||
state.sp.set.home = 2
|
||||
state.sp.set.guest = 2
|
||||
state.sp.punt.home = 15
|
||||
state.sp.punt.guest = 14
|
||||
expect(checkVittoria(state)).toBe(false)
|
||||
})
|
||||
|
||||
it('modalità 3/5: vittoria a 16-14 nel set decisivo', () => {
|
||||
state.modalitaPartita = "3/5"
|
||||
state.sp.set.home = 2
|
||||
state.sp.set.guest = 2
|
||||
state.sp.punt.home = 16
|
||||
state.sp.punt.guest = 14
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('modalità 2/3: set decisivo dopo 2 set totali → vittoria a 15', () => {
|
||||
state.modalitaPartita = "2/3"
|
||||
state.sp.set.home = 1
|
||||
state.sp.set.guest = 1
|
||||
state.sp.punt.home = 15
|
||||
state.sp.punt.guest = 10
|
||||
expect(checkVittoria(state)).toBe(true)
|
||||
})
|
||||
|
||||
const newState = applyAction(state, { type: 'resetta' })
|
||||
it('modalità 2/3: non vittoria a 24-20 nel set decisivo (soglia 15)', () => {
|
||||
state.modalitaPartita = "2/3"
|
||||
state.sp.set.home = 1
|
||||
state.sp.set.guest = 1
|
||||
state.sp.punt.home = 14
|
||||
state.sp.punt.guest = 10
|
||||
expect(checkVittoria(state)).toBe(false)
|
||||
})
|
||||
|
||||
expect(newState.sp.punt.home).toBe(0)
|
||||
expect(newState.sp.set.home).toBe(0) // Nota: il reset attuale resetta solo i punti o tutto?
|
||||
// Controllo il codice: "s.sp.punt.home = 0... s.sp.storicoServizio = []"
|
||||
// Attenzione: nel codice originale `resetta` NON sembra resettare i set!
|
||||
// Verifichiamo il comportamento attuale del codice.
|
||||
it('modalità 2/3: set non decisivo (1-0) → soglia 25', () => {
|
||||
state.modalitaPartita = "2/3"
|
||||
state.sp.set.home = 1
|
||||
state.sp.set.guest = 0
|
||||
state.sp.punt.home = 15
|
||||
state.sp.punt.guest = 10
|
||||
expect(checkVittoria(state)).toBe(false)
|
||||
})
|
||||
|
||||
it('modalità 3/5: set non decisivo (2-1) → soglia 25', () => {
|
||||
state.modalitaPartita = "3/5"
|
||||
state.sp.set.home = 2
|
||||
state.sp.set.guest = 1
|
||||
state.sp.punt.home = 15
|
||||
state.sp.punt.guest = 10
|
||||
expect(checkVittoria(state)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// RESET
|
||||
// =============================================
|
||||
describe('Reset', () => {
|
||||
it('dovrebbe resettare punti e set a zero', () => {
|
||||
state.sp.punt.home = 10
|
||||
state.sp.punt.guest = 8
|
||||
state.sp.set.home = 1
|
||||
state.sp.set.guest = 1
|
||||
const s = applyAction(state, { type: 'resetta' })
|
||||
expect(s.sp.punt.home).toBe(0)
|
||||
expect(s.sp.punt.guest).toBe(0)
|
||||
expect(s.sp.set.home).toBe(0)
|
||||
expect(s.sp.set.guest).toBe(0)
|
||||
})
|
||||
|
||||
it('dovrebbe resettare formazioni a default', () => {
|
||||
state.sp.form.home = ["10", "11", "12", "13", "14", "15"]
|
||||
const s = applyAction(state, { type: 'resetta' })
|
||||
expect(s.sp.form.home).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
expect(s.sp.form.guest).toEqual(["1", "2", "3", "4", "5", "6"])
|
||||
})
|
||||
|
||||
it('dovrebbe resettare la striscia', () => {
|
||||
state.sp.striscia = { home: [0, 1, 2, 3], guest: [0, " ", " ", 1] }
|
||||
const s = applyAction(state, { type: 'resetta' })
|
||||
expect(s.sp.striscia.home).toEqual([0])
|
||||
expect(s.sp.striscia.guest).toEqual([0])
|
||||
})
|
||||
|
||||
it('dovrebbe resettare lo storico servizio', () => {
|
||||
state.sp.storicoServizio = [{ servHome: true, cambioPalla: false }]
|
||||
const s = applyAction(state, { type: 'resetta' })
|
||||
expect(s.sp.storicoServizio).toEqual([])
|
||||
})
|
||||
|
||||
it('dovrebbe impostare visuForm a false', () => {
|
||||
state.visuForm = true
|
||||
const s = applyAction(state, { type: 'resetta' })
|
||||
expect(s.visuForm).toBe(false)
|
||||
})
|
||||
|
||||
it('dovrebbe mantenere nomi e modalità', () => {
|
||||
state.sp.nomi.home = "Squadra A"
|
||||
state.modalitaPartita = "2/3"
|
||||
const s = applyAction(state, { type: 'resetta' })
|
||||
expect(s.sp.nomi.home).toBe("Squadra A")
|
||||
expect(s.modalitaPartita).toBe("2/3")
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// AZIONE SCONOSCIUTA
|
||||
// =============================================
|
||||
describe('Azione sconosciuta', () => {
|
||||
it('dovrebbe restituire lo stato invariato con azione non riconosciuta', () => {
|
||||
const s = applyAction(state, { type: 'azioneInesistente' })
|
||||
expect(s.sp.punt.home).toBe(0)
|
||||
expect(s.sp.punt.guest).toBe(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,22 +1,148 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { printServerInfo } from '../../src/server-utils.js'
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest'
|
||||
import * as os from 'os'
|
||||
|
||||
// Mocking console.log per evitare output sporchi durante i test
|
||||
import { vi } from 'vitest'
|
||||
vi.mock('os', async (importOriginal) => {
|
||||
return {
|
||||
...await importOriginal(),
|
||||
networkInterfaces: vi.fn(() => ({}))
|
||||
}
|
||||
})
|
||||
|
||||
import { getNetworkIPs, printServerInfo } from '../../src/server-utils.js'
|
||||
|
||||
describe('Server Utils', () => {
|
||||
it('printServerInfo dovrebbe stampare le porte corrette', () => {
|
||||
const consoleSpy = vi.spyOn(console, 'log')
|
||||
printServerInfo(3000, 3001)
|
||||
|
||||
expect(consoleSpy).toHaveBeenCalled()
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
// Unisce tutti i messaggi loggati in un'unica stringa per facilitare la ricerca
|
||||
const allLogs = consoleSpy.mock.calls.map(args => args[0]).join('\n')
|
||||
// =============================================
|
||||
// getNetworkIPs
|
||||
// =============================================
|
||||
describe('getNetworkIPs', () => {
|
||||
it('dovrebbe restituire indirizzi IPv4 non-loopback', () => {
|
||||
os.networkInterfaces.mockReturnValue({
|
||||
eth0: [
|
||||
{ family: 'IPv4', internal: false, address: '192.168.1.100' }
|
||||
]
|
||||
})
|
||||
expect(getNetworkIPs()).toEqual(['192.168.1.100'])
|
||||
})
|
||||
|
||||
expect(allLogs).toContain('3000')
|
||||
expect(allLogs).toContain('3001')
|
||||
it('dovrebbe escludere indirizzi loopback (internal)', () => {
|
||||
os.networkInterfaces.mockReturnValue({
|
||||
lo: [
|
||||
{ family: 'IPv4', internal: true, address: '127.0.0.1' }
|
||||
],
|
||||
eth0: [
|
||||
{ family: 'IPv4', internal: false, address: '192.168.1.100' }
|
||||
]
|
||||
})
|
||||
const ips = getNetworkIPs()
|
||||
expect(ips).not.toContain('127.0.0.1')
|
||||
expect(ips).toContain('192.168.1.100')
|
||||
})
|
||||
|
||||
consoleSpy.mockRestore()
|
||||
it('dovrebbe escludere indirizzi IPv6', () => {
|
||||
os.networkInterfaces.mockReturnValue({
|
||||
eth0: [
|
||||
{ family: 'IPv6', internal: false, address: 'fe80::1' },
|
||||
{ family: 'IPv4', internal: false, address: '192.168.1.100' }
|
||||
]
|
||||
})
|
||||
const ips = getNetworkIPs()
|
||||
expect(ips).toEqual(['192.168.1.100'])
|
||||
})
|
||||
|
||||
it('dovrebbe escludere bridge Docker 172.17.x.x', () => {
|
||||
os.networkInterfaces.mockReturnValue({
|
||||
docker0: [
|
||||
{ family: 'IPv4', internal: false, address: '172.17.0.1' }
|
||||
],
|
||||
eth0: [
|
||||
{ family: 'IPv4', internal: false, address: '10.0.0.5' }
|
||||
]
|
||||
})
|
||||
const ips = getNetworkIPs()
|
||||
expect(ips).not.toContain('172.17.0.1')
|
||||
expect(ips).toContain('10.0.0.5')
|
||||
})
|
||||
|
||||
it('dovrebbe escludere bridge Docker 172.18.x.x', () => {
|
||||
os.networkInterfaces.mockReturnValue({
|
||||
br0: [
|
||||
{ family: 'IPv4', internal: false, address: '172.18.0.1' }
|
||||
]
|
||||
})
|
||||
expect(getNetworkIPs()).toEqual([])
|
||||
})
|
||||
|
||||
it('dovrebbe restituire array vuoto se nessuna interfaccia disponibile', () => {
|
||||
os.networkInterfaces.mockReturnValue({})
|
||||
expect(getNetworkIPs()).toEqual([])
|
||||
})
|
||||
|
||||
it('dovrebbe restituire più indirizzi da interfacce diverse', () => {
|
||||
os.networkInterfaces.mockReturnValue({
|
||||
eth0: [
|
||||
{ family: 'IPv4', internal: false, address: '192.168.1.100' }
|
||||
],
|
||||
wlan0: [
|
||||
{ family: 'IPv4', internal: false, address: '192.168.1.101' }
|
||||
]
|
||||
})
|
||||
const ips = getNetworkIPs()
|
||||
expect(ips).toHaveLength(2)
|
||||
expect(ips).toContain('192.168.1.100')
|
||||
expect(ips).toContain('192.168.1.101')
|
||||
})
|
||||
})
|
||||
|
||||
// =============================================
|
||||
// printServerInfo
|
||||
// =============================================
|
||||
describe('printServerInfo', () => {
|
||||
it('dovrebbe stampare le porte corrette (default)', () => {
|
||||
os.networkInterfaces.mockReturnValue({})
|
||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
printServerInfo()
|
||||
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
||||
expect(allLogs).toContain('5173')
|
||||
expect(allLogs).toContain('3001')
|
||||
consoleSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('dovrebbe stampare le porte personalizzate', () => {
|
||||
os.networkInterfaces.mockReturnValue({})
|
||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
printServerInfo(3000, 4000)
|
||||
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
||||
expect(allLogs).toContain('3000')
|
||||
expect(allLogs).toContain('4000')
|
||||
consoleSpy.mockRestore()
|
||||
})
|
||||
|
||||
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(() => {})
|
||||
printServerInfo(3000, 3001)
|
||||
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
||||
expect(allLogs).toContain('192.168.1.50')
|
||||
expect(allLogs).toContain('remoti')
|
||||
consoleSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('non dovrebbe mostrare sezione remoti se nessun IP di rete', () => {
|
||||
os.networkInterfaces.mockReturnValue({})
|
||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
printServerInfo(3000, 3001)
|
||||
const allLogs = consoleSpy.mock.calls.map(c => c[0]).join('\n')
|
||||
expect(allLogs).not.toContain('remoti')
|
||||
consoleSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
test: {
|
||||
include: ['tests/unit/**/*.{test,spec}.js', 'tests/integration/**/*.{test,spec}.js'],
|
||||
globals: true, // permette di usare describe/it/expect senza import
|
||||
environment: 'node', // per backend tests. Se testi componenti Vue, usa 'jsdom'
|
||||
include: [
|
||||
'tests/unit/**/*.{test,spec}.js',
|
||||
'tests/integration/**/*.{test,spec}.js',
|
||||
'tests/component/**/*.{test,spec}.js',
|
||||
'tests/stress/**/*.{test,spec}.js',
|
||||
],
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
environmentMatchGlobs: [
|
||||
['tests/component/**', 'happy-dom'],
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||