2026-02-12 19:33:54 +01:00
|
|
|
const { test, expect } = require('@playwright/test');
|
2026-02-12 15:13:04 +01:00
|
|
|
|
|
|
|
|
test.describe('Game Simulation', () => {
|
|
|
|
|
test('Simulazione Partita: Controller aggiunge punti finché non cambia il set', async ({ context }) => {
|
|
|
|
|
// 1. Setup Pagine
|
|
|
|
|
const displayPage = await context.newPage();
|
|
|
|
|
const controllerPage = await context.newPage();
|
|
|
|
|
|
|
|
|
|
await displayPage.goto('http://localhost:3000');
|
|
|
|
|
await controllerPage.goto('http://localhost:3001');
|
|
|
|
|
|
|
|
|
|
// Selettori (basati su ID ipotetici o classi, adattali al tuo HTML reale)
|
|
|
|
|
// Assumo che nel DOM ci siano elementi con ID o classi riconoscibili
|
|
|
|
|
// E che i punteggi siano visibili.
|
|
|
|
|
|
|
|
|
|
// Pulisco lo stato iniziale (reset)
|
|
|
|
|
const btnReset = controllerPage.getByText(/Reset/i).first();
|
|
|
|
|
if (await btnReset.isVisible()) {
|
|
|
|
|
await btnReset.click();
|
|
|
|
|
// La modale di conferma ha un bottone "SI" con classe .btn-confirm
|
|
|
|
|
const btnConfirmReset = controllerPage.locator('.dialog .btn-confirm').getByText('SI');
|
|
|
|
|
if (await btnConfirmReset.isVisible()) {
|
|
|
|
|
await btnConfirmReset.click();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Loop per vincere il primo set (25 punti)
|
|
|
|
|
// In ControllerPage.vue, il click su .team-score.home-bg incrementa i punti home
|
|
|
|
|
const btnHomeScore = controllerPage.locator('.team-score.home-bg');
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 25; i++) {
|
|
|
|
|
await btnHomeScore.click();
|
|
|
|
|
// Piccola pausa per lasciare tempo al server di processare e broadcastare
|
|
|
|
|
//await displayPage.waitForTimeout(10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. Verifica Vittoria Set
|
|
|
|
|
// I punti dovrebbero essere tornati a 0 (o mostrare 25 prima del reset manuale?)
|
|
|
|
|
// Il codice gameState dice: checkVittoria -> resetta solo se qualcuno chiama resetta?
|
|
|
|
|
// No, checkVittoria è boolean. applyAction('incPunt') incrementa.
|
|
|
|
|
// Se vince, il set incrementa? 'incPunt' non incrementa i set in automatico nel codice gameState checkato prima!
|
|
|
|
|
// Controllo applyAction:
|
|
|
|
|
// "s.sp.punt[team]++" ... POI "checkVittoria(s)" all'inizio del prossimo incPunt?
|
|
|
|
|
// NO: "if (checkVittoria(s)) break" all'inizio di incPunt impedisce di andare oltre 25 se già vinto.
|
|
|
|
|
// MA 'incSet' è un'azione separata!
|
|
|
|
|
|
|
|
|
|
// Aspetta, la logica standard è: arrivo a 25 -> vinco set?
|
|
|
|
|
// In questo codice `gameState.js` NON c'è automatismo "arrivo a 25 -> set++ e palla al centro".
|
|
|
|
|
// L'utente deve cliccare "SET Antoniana" manualmente?
|
|
|
|
|
// Guardiamo ControllerPage.vue:
|
|
|
|
|
// C'è un bottone "SET {{ state.sp.nomi.home }}" che manda { type: 'incSet', team: 'home' }
|
|
|
|
|
|
|
|
|
|
// QUINDI: Il test deve:
|
|
|
|
|
// 1. Arrivare a 25 pt.
|
|
|
|
|
// 2. Cliccare "SET HOME".
|
|
|
|
|
// 3. Verificare che Set Home = 1.
|
|
|
|
|
|
|
|
|
|
// Verifica che siamo a 25
|
|
|
|
|
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('25');
|
|
|
|
|
|
|
|
|
|
// Clicca bottone SET
|
|
|
|
|
const btnSetHome = controllerPage.locator('.btn-set.home-bg');
|
|
|
|
|
await btnSetHome.click();
|
|
|
|
|
|
|
|
|
|
// Verifica che il set sia incrementato
|
|
|
|
|
// Nota: display potrebbe chiamarsi diversamente, controlliamo Controller per coerenza
|
|
|
|
|
await expect(controllerPage.locator('.team-score.home-bg .team-set')).toContainText('SET 1');
|
|
|
|
|
});
|
|
|
|
|
});
|