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,28 +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);
|
||||
}
|
||||
const { openController, openDisplay, resetGame } = require('./helpers.cjs');
|
||||
|
||||
test.describe('Game Operations', () => {
|
||||
|
||||
test('Undo: dovrebbe annullare l\'ultimo punto', 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);
|
||||
|
||||
// Incrementa Home a 1
|
||||
@@ -37,10 +19,8 @@ test.describe('Game Operations', () => {
|
||||
});
|
||||
|
||||
test('Reset: dovrebbe azzerare tutto dopo conferma', 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);
|
||||
|
||||
// Imposta qualche punto
|
||||
for (let i = 0; i < 5; i++) {
|
||||
@@ -57,13 +37,9 @@ test.describe('Game Operations', () => {
|
||||
});
|
||||
|
||||
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.setViewportSize({ width: 390, height: 844 });
|
||||
await controllerPage.goto('http://localhost:3000/controller');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
const displayPage = await openDisplay(context);
|
||||
const controllerPage = await openController(context);
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Apri config
|
||||
await controllerPage.getByText('Config').click();
|
||||
@@ -88,13 +64,9 @@ test.describe('Game Operations', () => {
|
||||
});
|
||||
|
||||
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.setViewportSize({ width: 390, height: 844 });
|
||||
await controllerPage.goto('http://localhost:3000/controller');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
const displayPage = await openDisplay(context);
|
||||
const controllerPage = await openController(context);
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Inizialmente mostra punteggio, non formazione
|
||||
await expect(displayPage.locator('.punteggio-container')).toBeVisible();
|
||||
@@ -108,13 +80,9 @@ test.describe('Game Operations', () => {
|
||||
});
|
||||
|
||||
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.setViewportSize({ width: 390, height: 844 });
|
||||
await controllerPage.goto('http://localhost:3000/controller');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
const displayPage = await openDisplay(context);
|
||||
const controllerPage = await openController(context);
|
||||
await resetGame(controllerPage);
|
||||
|
||||
// Inizialmente la striscia è visibile
|
||||
await expect(displayPage.locator('.striscia')).toBeVisible();
|
||||
@@ -131,13 +99,8 @@ test.describe('Game Operations', () => {
|
||||
});
|
||||
|
||||
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.setViewportSize({ width: 390, height: 844 });
|
||||
await controllerPage.goto('http://localhost:3000/controller');
|
||||
await controllerPage.waitForSelector('.conn-bar.connected');
|
||||
const displayPage = await openDisplay(context);
|
||||
const controllerPage = await openController(context);
|
||||
|
||||
await resetGame(controllerPage);
|
||||
|
||||
@@ -167,10 +130,7 @@ test.describe('Game Operations', () => {
|
||||
});
|
||||
|
||||
test('Cambi: dovrebbe mostrare errore per giocatore non in formazione', 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user