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'); }); });