- aggiunge configurazione playwright.config.cjs per compatibilita runtime - aggiorna playwright.config.ts con progetto Mobile Chrome - migra i test E2E da .js a .spec.cjs - rimuove i vecchi file E2E non piu usati - allinea i test visual con snapshot baseline aggiornate
183 lines
7.5 KiB
JavaScript
183 lines
7.5 KiB
JavaScript
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);
|
|
}
|
|
|
|
test.describe('Game Operations', () => {
|
|
|
|
test('Undo: dovrebbe annullare l\'ultimo punto', async ({ context }) => {
|
|
const controllerPage = await context.newPage();
|
|
await controllerPage.goto('http://localhost:3001');
|
|
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
|
|
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 context.newPage();
|
|
await controllerPage.goto('http://localhost:3001');
|
|
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
|
|
// 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 context.newPage();
|
|
const controllerPage = await context.newPage();
|
|
|
|
await displayPage.goto('http://localhost:3000');
|
|
await controllerPage.goto('http://localhost:3001');
|
|
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
|
|
// 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 context.newPage();
|
|
const controllerPage = await context.newPage();
|
|
|
|
await displayPage.goto('http://localhost:3000');
|
|
await controllerPage.goto('http://localhost:3001');
|
|
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
|
|
// 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 context.newPage();
|
|
const controllerPage = await context.newPage();
|
|
|
|
await displayPage.goto('http://localhost:3000');
|
|
await controllerPage.goto('http://localhost:3001');
|
|
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
|
|
// 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 context.newPage();
|
|
const controllerPage = await context.newPage();
|
|
|
|
await displayPage.goto('http://localhost:3000');
|
|
await controllerPage.goto('http://localhost:3001');
|
|
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
|
|
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 context.newPage();
|
|
await controllerPage.goto('http://localhost:3001');
|
|
await controllerPage.waitForSelector('.conn-bar.connected');
|
|
|
|
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();
|
|
});
|
|
});
|