const { test, expect } = require('@playwright/test'); const { openController, resetGame, addPoints } = require('./helpers.cjs'); test.describe('Full Match Simulation', () => { test('Partita 2/3: Home vince il primo set', async ({ context }) => { const controllerPage = await openController(context); 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'); // A 25-0 compare automaticamente il dialog "SET VINTO": vai al set successivo await controllerPage.waitForSelector('.dialog-winner'); await controllerPage.getByText('VAI AL SET SUCCESSIVO').click(); // doNuovoSet riapre il dialog di configurazione: chiudilo await controllerPage.locator('.dialog-config .btn-cancel').click(); await controllerPage.waitForTimeout(200); // Verifica set 1 per Home 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 openController(context); 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'); // A 15 nel set decisivo scatta la vittoria: compare il dialog (PARTITA FINITA) await expect(controllerPage.locator('.dialog-winner')).toBeVisible(); }); test('Set normale: punti oltre 25 fino ai vantaggi', async ({ context }) => { const controllerPage = await openController(context); 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 → compare automaticamente il dialog SET VINTO await expect(controllerPage.locator('.dialog-winner')).toBeVisible(); }); });