test(e2e): helper condivisi e refactor degli spec di gioco
- nuovo tests/e2e/helpers.cjs: openController (viewport portrait per il layout mobile), openDisplay, resetGame, addPoints - resetGame gestisce il dialog di vittoria persistente e reimposta i nomi di default (lo stato è condiviso e persistente: serve per il determinismo) - full-match/game-simulation: gestito il dialog SET VINTO automatico a 25/15 - basic-flow/game-operations: migrati agli helper condivisi
This commit is contained in:
@@ -1,49 +1,10 @@
|
||||
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();
|
||||
}
|
||||
// doReset apre automaticamente il dialog di configurazione: chiudilo
|
||||
const cfgCancel = controllerPage.locator('.dialog-config .btn-cancel');
|
||||
if (await cfgCancel.isVisible()) {
|
||||
await cfgCancel.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)
|
||||
}
|
||||
const { openController, resetGame, addPoints } = require('./helpers.cjs');
|
||||
|
||||
test.describe('Full Match Simulation', () => {
|
||||
|
||||
test('Partita 2/3: Home vince 2 set a 0', async ({ context }) => {
|
||||
const controllerPage = await context.newPage();
|
||||
await controllerPage.setViewportSize({ width: 390, height: 844 });
|
||||
await controllerPage.goto('http://localhost:3000/controller');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
test('Partita 2/3: Home vince il primo set', async ({ context }) => {
|
||||
const controllerPage = await openController(context);
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
@@ -60,19 +21,19 @@ test.describe('Full Match Simulation', () => {
|
||||
// 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);
|
||||
// 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 context.newPage();
|
||||
await controllerPage.setViewportSize({ width: 390, height: 844 });
|
||||
await controllerPage.goto('http://localhost:3000/controller');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
const controllerPage = await openController(context);
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
@@ -99,18 +60,12 @@ test.describe('Full Match Simulation', () => {
|
||||
// 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');
|
||||
// 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 context.newPage();
|
||||
await controllerPage.setViewportSize({ width: 390, height: 844 });
|
||||
await controllerPage.goto('http://localhost:3000/controller');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
const controllerPage = await openController(context);
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
@@ -131,9 +86,7 @@ test.describe('Full Match Simulation', () => {
|
||||
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');
|
||||
// 26-24 è vittoria → compare automaticamente il dialog SET VINTO
|
||||
await expect(controllerPage.locator('.dialog-winner')).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user