/**
* Smoke test di tutte le pagine (brief §11.4): risposta 200, un solo
, lang="it",
* titolo e descrizione presenti e unici, canonical corretto, nessun errore in console.
*/
import { expect, test } from '@playwright/test';
import { ALL_PAGES, SITE, collectConsoleErrors } from '../helpers/site';
for (const path of ALL_PAGES) {
test(`pagina ${path}: struttura e metadati`, async ({ page }) => {
const errors = collectConsoleErrors(page);
const response = await page.goto(path);
expect(response?.status(), `stato HTTP della pagina ${path}`).toBe(200);
await expect(page.locator('html'), `lang della pagina ${path}`).toHaveAttribute('lang', 'it');
await expect(page.locator('h1'), `numero di nella pagina ${path}`).toHaveCount(1);
await expect(page.locator('h1'), ` visibile nella pagina ${path}`).toBeVisible();
const title = await page.title();
expect(title.length, `titolo della pagina ${path}`).toBeGreaterThan(10);
const description = await page.locator('meta[name="description"]').getAttribute('content');
expect(
description?.length ?? 0,
`meta description della pagina ${path}`,
).toBeGreaterThanOrEqual(120);
if (path !== '/404.html') {
await expect(
page.locator('link[rel="canonical"]'),
`canonical della pagina ${path}`,
).toHaveAttribute('href', `${SITE}${path}`);
}
await expect(page.locator('footer'), `P.IVA nel footer della pagina ${path}`).toContainText(
'P.IVA 01597790052',
);
expect(errors, `errori nella console della pagina ${path}`).toEqual([]);
});
}
test('titoli e descrizioni sono unici su tutto il sito', async ({ page }) => {
const titles = new Map();
const descriptions = new Map();
for (const path of ALL_PAGES) {
await page.goto(path);
const title = await page.title();
const description =
(await page.locator('meta[name="description"]').getAttribute('content')) ?? '';
expect(titles.get(title), `titolo «${title}» di ${path} già usato`).toBeUndefined();
expect(descriptions.get(description), `descrizione di ${path} già usata`).toBeUndefined();
titles.set(title, path);
descriptions.set(description, path);
}
});
test('un indirizzo inesistente mostra la pagina 404 personalizzata', async ({ page }) => {
const response = await page.goto('/pagina-che-non-esiste/');
expect(response?.status(), 'stato HTTP di un indirizzo inesistente').toBe(404);
await expect(page.locator('h1')).toHaveText('Pagina non trovata');
const main = page.locator('main');
for (const href of ['/', '/servizi/', '/contatti/']) {
await expect(main.locator(`a[href="${href}"]`), `link a ${href} nella 404`).toHaveCount(1);
}
await expect(page.locator('meta[name="robots"]')).toHaveAttribute('content', /noindex/);
});
test('la pagina di conferma del modulo è noindex', async ({ page }) => {
await page.goto('/contatti/grazie/');
await expect(page.locator('h1')).toHaveText('Richiesta inviata');
await expect(page.locator('meta[name="robots"]')).toHaveAttribute('content', /noindex/);
});