diff --git a/tests/e2e/visual-regression.spec.cjs b/tests/e2e/visual-regression.spec.cjs index be2f68a..756630a 100644 --- a/tests/e2e/visual-regression.spec.cjs +++ b/tests/e2e/visual-regression.spec.cjs @@ -1,32 +1,12 @@ 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, addPoints } = require('./helpers.cjs'); test.describe('Visual Regression', () => { test('Display: screenshot a 0-0', async ({ context }) => { - const controllerPage = await context.newPage(); - const displayPage = await context.newPage(); + const controllerPage = await openController(context); + const displayPage = await openDisplay(context); - await controllerPage.setViewportSize({ width: 390, height: 844 }); - await controllerPage.goto('http://localhost:3000/controller'); - await displayPage.goto('http://localhost:3000'); - await controllerPage.waitForSelector('.conn-bar.connected'); - - // Reset per stato pulito await resetGame(controllerPage); // Attende che il display riceva lo stato @@ -34,42 +14,31 @@ test.describe('Visual Regression', () => { await expect(displayPage).toHaveScreenshot('display-0-0.png', { maxDiffPixelRatio: 0.05, + animations: 'disabled', + mask: [displayPage.locator('.connection-status')], }); }); test('Display: screenshot durante partita (15-12)', async ({ context }) => { - const controllerPage = await context.newPage(); - const displayPage = await context.newPage(); - - await controllerPage.setViewportSize({ width: 390, height: 844 }); - await controllerPage.goto('http://localhost:3000/controller'); - await displayPage.goto('http://localhost:3000'); - await controllerPage.waitForSelector('.conn-bar.connected'); + const controllerPage = await openController(context); + const displayPage = await openDisplay(context); await resetGame(controllerPage); // Porta il punteggio a 15-12 - for (let i = 0; i < 15; i++) { - await controllerPage.locator('.team-score.home-bg').click(); - await controllerPage.waitForTimeout(20); - } - for (let i = 0; i < 12; i++) { - await controllerPage.locator('.team-score.guest-bg').click(); - await controllerPage.waitForTimeout(20); - } + await addPoints(controllerPage, 'home', 15); + await addPoints(controllerPage, 'guest', 12); await displayPage.waitForTimeout(500); await expect(displayPage).toHaveScreenshot('display-15-12.png', { maxDiffPixelRatio: 0.05, + animations: 'disabled', + mask: [displayPage.locator('.connection-status')], }); }); test('Controller: screenshot stato iniziale', 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); await expect(controllerPage).toHaveScreenshot('controller-initial.png', { @@ -78,10 +47,8 @@ test.describe('Visual Regression', () => { }); test('Controller: screenshot con modal config aperta', 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); // Apri config await controllerPage.getByText('Config').click(); diff --git a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-Mobile-Chrome-linux.png b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-Mobile-Chrome-linux.png index 5674919..a515376 100644 Binary files a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-Mobile-Chrome-linux.png and b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-Mobile-Chrome-linux.png differ diff --git a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-chromium-linux.png b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-chromium-linux.png index a5134b9..df5887a 100644 Binary files a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-chromium-linux.png and b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-chromium-linux.png differ diff --git a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-firefox-linux.png b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-firefox-linux.png index 4a33d2e..8e1b375 100644 Binary files a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-firefox-linux.png and b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-config-modal-firefox-linux.png differ diff --git a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-Mobile-Chrome-linux.png b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-Mobile-Chrome-linux.png index 3da8e0b..d46d6d7 100644 Binary files a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-Mobile-Chrome-linux.png and b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-Mobile-Chrome-linux.png differ diff --git a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-chromium-linux.png b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-chromium-linux.png index a5c1026..581db23 100644 Binary files a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-chromium-linux.png and b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-chromium-linux.png differ diff --git a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-firefox-linux.png b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-firefox-linux.png index 30e4a56..ab9124a 100644 Binary files a/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-firefox-linux.png and b/tests/e2e/visual-regression.spec.cjs-snapshots/controller-initial-firefox-linux.png differ diff --git a/tests/e2e/visual-regression.spec.cjs-snapshots/display-0-0-Mobile-Chrome-linux.png b/tests/e2e/visual-regression.spec.cjs-snapshots/display-0-0-Mobile-Chrome-linux.png index 3abb907..5d5be66 100644 Binary files a/tests/e2e/visual-regression.spec.cjs-snapshots/display-0-0-Mobile-Chrome-linux.png and b/tests/e2e/visual-regression.spec.cjs-snapshots/display-0-0-Mobile-Chrome-linux.png differ diff --git a/tests/e2e/visual-regression.spec.cjs-snapshots/display-15-12-Mobile-Chrome-linux.png b/tests/e2e/visual-regression.spec.cjs-snapshots/display-15-12-Mobile-Chrome-linux.png index 857383a..be00c66 100644 Binary files a/tests/e2e/visual-regression.spec.cjs-snapshots/display-15-12-Mobile-Chrome-linux.png and b/tests/e2e/visual-regression.spec.cjs-snapshots/display-15-12-Mobile-Chrome-linux.png differ diff --git a/tests/e2e/visual-regression.spec.cjs-snapshots/display-15-12-firefox-linux.png b/tests/e2e/visual-regression.spec.cjs-snapshots/display-15-12-firefox-linux.png index fe664ee..cf5c422 100644 Binary files a/tests/e2e/visual-regression.spec.cjs-snapshots/display-15-12-firefox-linux.png and b/tests/e2e/visual-regression.spec.cjs-snapshots/display-15-12-firefox-linux.png differ