d67f3669d6
- 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
155 lines
6.4 KiB
JavaScript
155 lines
6.4 KiB
JavaScript
const { test, expect } = require('@playwright/test');
|
|
const { openController, openDisplay, resetGame } = require('./helpers.cjs');
|
|
|
|
test.describe('Game Operations', () => {
|
|
|
|
test('Undo: dovrebbe annullare l\'ultimo punto', async ({ context }) => {
|
|
const controllerPage = await openController(context);
|
|
await resetGame(controllerPage);
|
|
|
|
// Incrementa Home a 1
|
|
await controllerPage.locator('.team-score.home-bg').click();
|
|
await controllerPage.waitForTimeout(100);
|
|
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('1');
|
|
|
|
// Annulla
|
|
await controllerPage.getByText('ANNULLA PUNTO').click();
|
|
await controllerPage.waitForTimeout(100);
|
|
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('0');
|
|
});
|
|
|
|
test('Reset: dovrebbe azzerare tutto dopo conferma', async ({ context }) => {
|
|
const controllerPage = await openController(context);
|
|
await resetGame(controllerPage);
|
|
|
|
// Imposta qualche punto
|
|
for (let i = 0; i < 5; i++) {
|
|
await controllerPage.locator('.team-score.home-bg').click();
|
|
await controllerPage.waitForTimeout(50);
|
|
}
|
|
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('5');
|
|
|
|
// Reset
|
|
await resetGame(controllerPage);
|
|
|
|
await expect(controllerPage.locator('.team-score.home-bg .team-pts')).toHaveText('0');
|
|
await expect(controllerPage.locator('.team-score.guest-bg .team-pts')).toHaveText('0');
|
|
});
|
|
|
|
test('Config: dovrebbe cambiare i nomi dei team', async ({ context }) => {
|
|
const displayPage = await openDisplay(context);
|
|
const controllerPage = await openController(context);
|
|
await resetGame(controllerPage);
|
|
|
|
// Apri config
|
|
await controllerPage.getByText('Config').click();
|
|
await controllerPage.waitForSelector('.dialog-config');
|
|
|
|
// Modifica nomi
|
|
const inputs = controllerPage.locator('.dialog-config .input-field');
|
|
await inputs.first().fill('Padova');
|
|
await inputs.nth(1).fill('Milano');
|
|
|
|
// Salva
|
|
await controllerPage.locator('.dialog-config .btn-confirm').click();
|
|
await controllerPage.waitForTimeout(300);
|
|
|
|
// Verifica sul Controller
|
|
await expect(controllerPage.locator('.team-score.home-bg .team-name')).toHaveText('Padova');
|
|
await expect(controllerPage.locator('.team-score.guest-bg .team-name')).toHaveText('Milano');
|
|
|
|
// Verifica sul Display
|
|
await expect(displayPage.locator('.hea.home')).toContainText('Padova');
|
|
await expect(displayPage.locator('.hea.guest')).toContainText('Milano');
|
|
});
|
|
|
|
test('Toggle Formazione: dovrebbe mostrare la formazione sul display', async ({ context }) => {
|
|
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();
|
|
|
|
// Click Formazioni
|
|
await controllerPage.getByText('Formazioni').click();
|
|
await controllerPage.waitForTimeout(300);
|
|
|
|
// Il display mostra le formazioni
|
|
await expect(displayPage.locator('.form').first()).toBeVisible();
|
|
});
|
|
|
|
test('Toggle Striscia: dovrebbe nascondere/mostrare la striscia', async ({ context }) => {
|
|
const displayPage = await openDisplay(context);
|
|
const controllerPage = await openController(context);
|
|
await resetGame(controllerPage);
|
|
|
|
// Inizialmente la striscia è visibile
|
|
await expect(displayPage.locator('.striscia')).toBeVisible();
|
|
|
|
// Toggle off
|
|
await controllerPage.getByText('Striscia').click();
|
|
await controllerPage.waitForTimeout(300);
|
|
await expect(displayPage.locator('.striscia')).not.toBeVisible();
|
|
|
|
// Toggle on
|
|
await controllerPage.getByText('Striscia').click();
|
|
await controllerPage.waitForTimeout(300);
|
|
await expect(displayPage.locator('.striscia')).toBeVisible();
|
|
});
|
|
|
|
test('Cambi: dovrebbe effettuare una sostituzione giocatore', async ({ context }) => {
|
|
const displayPage = await openDisplay(context);
|
|
const controllerPage = await openController(context);
|
|
|
|
await resetGame(controllerPage);
|
|
|
|
// Attiva formazione sul display per verificare
|
|
await controllerPage.getByText('Formazioni').click();
|
|
await controllerPage.waitForTimeout(200);
|
|
|
|
// Apri cambi → scegli Home
|
|
await controllerPage.getByRole('button', { name: 'Cambi', exact: true }).click();
|
|
await controllerPage.waitForTimeout(100);
|
|
await controllerPage.locator('.dialog .btn-set.home-bg').click();
|
|
await controllerPage.waitForTimeout(100);
|
|
|
|
// Inserisci sostituzione: IN=10, OUT=1
|
|
const inField = controllerPage.locator('.cambi-in-field').first();
|
|
const outField = controllerPage.locator('.cambi-out-field').first();
|
|
await inField.fill('10');
|
|
await outField.fill('1');
|
|
|
|
// Conferma
|
|
await controllerPage.locator('.dialog .btn-confirm').click();
|
|
await controllerPage.waitForTimeout(300);
|
|
|
|
// Verifica formazione aggiornata sul display
|
|
const formText = await displayPage.locator('.form.home').textContent();
|
|
expect(formText).toContain('10');
|
|
});
|
|
|
|
test('Cambi: dovrebbe mostrare errore per giocatore non in formazione', async ({ context }) => {
|
|
const controllerPage = await openController(context);
|
|
|
|
await resetGame(controllerPage);
|
|
|
|
// Apri cambi → scegli Home
|
|
await controllerPage.getByRole('button', { name: 'Cambi', exact: true }).click();
|
|
await controllerPage.waitForTimeout(100);
|
|
await controllerPage.locator('.dialog .btn-set.home-bg').click();
|
|
await controllerPage.waitForTimeout(100);
|
|
|
|
// Inserisci sostituzione invalida: OUT=99 (non in formazione)
|
|
await controllerPage.locator('.cambi-in-field').first().fill('10');
|
|
await controllerPage.locator('.cambi-out-field').first().fill('99');
|
|
|
|
// Conferma
|
|
await controllerPage.locator('.dialog .btn-confirm').click();
|
|
await controllerPage.waitForTimeout(200);
|
|
|
|
// Dovrebbe mostrare errore
|
|
await expect(controllerPage.locator('.cambi-error')).toBeVisible();
|
|
});
|
|
});
|