test: suite completa di §11 e npm run verify verde
- html-validate su tutte le pagine; linkinator su astro preview (link, asset, CSS e ancore), con modalità --external per i siti esterni - e2e Playwright: struttura e metadati di ogni pagina, 404, navigazione, sottomenu, menu mobile, ancore del vecchio sito, nessuna richiesta esterna, nessun cookie, localStorage vuoto, mappa solo dopo il clic, funzionamento senza JavaScript, modulo di contatto - a11y: axe su tutte le pagine a 1440 e 390 px e negli stati interattivi, tastiera (skip link, sottomenu, menu mobile), focus visibile, testo al 200 %, reflow a 320 px, movimento ridotto - check-compliance.mjs: P.IVA, link legali, risorse sicure, segnaposto, JSON-LD, sitemap, robots, .htaccess, badge e servizi, uso di «commercialista», riferimento L. 4/2013, budget - fix: punti di interruzione in em, focus ciclico nel menu mobile, rel="noopener" sui link esterni del Markdown, numeri di telefono non spezzabili Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016zJ9ZWGKvoKoxYwbmnRKdJ
This commit is contained in:
40 files changed
+1798
-114
No files matched your search
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Modulo di contatto (brief §10.1, §11.4). Con `contactForm.mode = 'off'` (predefinito) si
|
||||
* verifica la card «Scrivici una e-mail»; con il modulo attivo (CONTACT_FORM_MODE=php o
|
||||
* endpoint nella build) si verificano validazione, honeypot, tempo minimo e pagina di conferma.
|
||||
*/
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test('contatti: modulo oppure card e-mail, a seconda della configurazione', async ({ page }) => {
|
||||
await page.goto('/contatti/');
|
||||
const forms = await page.locator('form[data-contact-form]').count();
|
||||
if (forms === 0) {
|
||||
const card = page.locator('[data-contact-mode="off"]');
|
||||
await expect(card).toBeVisible();
|
||||
await expect(card.getByRole('heading', { name: 'Scrivici una e-mail' })).toBeVisible();
|
||||
const href = await card.locator('a[href^="mailto:"]').getAttribute('href');
|
||||
expect(href).toBe(
|
||||
`mailto:info@studiograssoezio.it?subject=${encodeURIComponent('Richiesta di informazioni dal sito')}`,
|
||||
);
|
||||
} else {
|
||||
await expect(page.locator('form[data-contact-form]')).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test.describe('modulo attivo', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/contatti/');
|
||||
const forms = await page.locator('form[data-contact-form]').count();
|
||||
test.skip(forms === 0, 'modulo disattivato (contactForm.mode = "off")');
|
||||
});
|
||||
|
||||
test('campi obbligatori, etichette e informativa', async ({ page }) => {
|
||||
const form = page.locator('form[data-contact-form]');
|
||||
for (const label of [
|
||||
'Nome e cognome',
|
||||
'E-mail',
|
||||
'Telefono / Cellulare',
|
||||
'Oggetto',
|
||||
'Messaggio',
|
||||
]) {
|
||||
const field = form.getByLabel(label);
|
||||
await expect(field, `campo «${label}»`).toBeVisible();
|
||||
await expect(field, `campo «${label}» obbligatorio`).toHaveAttribute('required', '');
|
||||
}
|
||||
const consent = form.locator('input[name="privacy"]');
|
||||
await expect(consent).toHaveAttribute('required', '');
|
||||
await expect(form.locator('label[for="cf-privacy"] a')).toHaveAttribute(
|
||||
'href',
|
||||
'/privacy-policy/',
|
||||
);
|
||||
await expect(form).toContainText('* campo obbligatorio');
|
||||
});
|
||||
|
||||
test('honeypot nascosto e campo ts valorizzato', async ({ page }) => {
|
||||
const trap = page.locator('input[name="sito_web"]');
|
||||
await expect(trap).toHaveAttribute('tabindex', '-1');
|
||||
await expect(trap).not.toBeInViewport();
|
||||
await expect(page.locator('.contact-form__trap')).toHaveAttribute('aria-hidden', 'true');
|
||||
const ts = await page.locator('input[name="ts"]').inputValue();
|
||||
expect(Number(ts), 'timestamp di apertura della pagina').toBeGreaterThan(1_600_000_000_000);
|
||||
});
|
||||
|
||||
test('invio vuoto: errori in italiano accanto ai campi e riepilogo', async ({ page }) => {
|
||||
await page.getByRole('button', { name: /Invia la richiesta/ }).click();
|
||||
const summary = page.locator('[data-form-summary]');
|
||||
await expect(summary).toBeVisible();
|
||||
await expect(summary).toBeFocused();
|
||||
await expect(summary).toContainText('Controlla i campi evidenziati');
|
||||
await expect(page.locator('#cf-nome')).toHaveAttribute('aria-invalid', 'true');
|
||||
await expect(page.locator('#cf-nome-err')).toHaveText('Compila questo campo.');
|
||||
await expect(page.locator('#cf-privacy-err')).toContainText('informativa sulla privacy');
|
||||
await expect(page).toHaveURL('/contatti/');
|
||||
});
|
||||
|
||||
test('e-mail non valida', async ({ page }) => {
|
||||
await page.locator('#cf-email').fill('non-valida');
|
||||
await page.locator('#cf-email').blur();
|
||||
await expect(page.locator('#cf-email-err')).toContainText('indirizzo e-mail valido');
|
||||
});
|
||||
|
||||
test('invio troppo rapido bloccato, poi invio e pagina di conferma', async ({ page }) => {
|
||||
await page.route('**/contact.php', (route) =>
|
||||
route.fulfill({ status: 303, headers: { Location: '/contatti/grazie/' } }),
|
||||
);
|
||||
await page.locator('#cf-nome').fill('Mario Rossi');
|
||||
await page.locator('#cf-email').fill('mario.rossi@example.com');
|
||||
await page.locator('#cf-telefono').fill('+39 0141 000000');
|
||||
await page.locator('#cf-oggetto').fill('Richiesta di preventivo');
|
||||
await page
|
||||
.locator('#cf-messaggio')
|
||||
.fill('Vorrei un preventivo per la tenuta della contabilità.');
|
||||
await page.locator('#cf-privacy').check();
|
||||
|
||||
// primo invio entro 3 secondi dall'apertura della pagina: bloccato dall'anti-spam
|
||||
await page.getByRole('button', { name: /Invia la richiesta/ }).click();
|
||||
await expect(page.locator('[data-form-status]')).toHaveText(/Attendi qualche secondo/);
|
||||
await expect(page).toHaveURL('/contatti/');
|
||||
|
||||
await page.waitForTimeout(3_200);
|
||||
await page.getByRole('button', { name: /Invia la richiesta/ }).click();
|
||||
await expect(page).toHaveURL('/contatti/grazie/');
|
||||
await expect(page.locator('h1')).toHaveText('Richiesta inviata');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Menu mobile a 390 px (brief §5.2): apertura e chiusura, aria-expanded, Esc, focus, sottomenu.
|
||||
*/
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { SERVICE_PAGES } from '../helpers/site';
|
||||
|
||||
test.use({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
|
||||
|
||||
test('il menu mobile si apre e si chiude', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
const toggle = page.locator('[data-menu-open]');
|
||||
const menu = page.locator('#menu-mobile');
|
||||
|
||||
await expect(page.getByRole('navigation', { name: 'Principale' })).toBeHidden();
|
||||
await expect(toggle).toBeVisible();
|
||||
await expect(toggle).toHaveAttribute('aria-controls', 'menu-mobile');
|
||||
await expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
||||
await expect(menu).toBeHidden();
|
||||
|
||||
await toggle.click();
|
||||
await expect(menu).toBeVisible();
|
||||
await expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
||||
await expect(page.locator('[data-menu-close]')).toBeFocused();
|
||||
for (const label of ['Lo studio', 'Servizi', 'Contatti', 'Dove siamo', 'Link utili']) {
|
||||
await expect(menu.getByRole('link', { name: label, exact: true })).toBeVisible();
|
||||
}
|
||||
await expect(menu.locator('a[href^="tel:"]')).toBeVisible();
|
||||
|
||||
await page.locator('[data-menu-close]').click();
|
||||
await expect(menu).toBeHidden();
|
||||
await expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
||||
await expect(toggle).toBeFocused();
|
||||
});
|
||||
|
||||
test('il menu mobile si chiude con Esc', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
const toggle = page.locator('[data-menu-open]');
|
||||
await toggle.click();
|
||||
await expect(page.locator('#menu-mobile')).toBeVisible();
|
||||
await page.keyboard.press('Escape');
|
||||
await expect(page.locator('#menu-mobile')).toBeHidden();
|
||||
await expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
||||
await expect(toggle).toBeFocused();
|
||||
});
|
||||
|
||||
test('il sottomenu dei servizi nel menu mobile', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await page.locator('[data-menu-open]').click();
|
||||
const subToggle = page.locator('#menu-mobile [data-submenu-toggle]');
|
||||
const sub = page.locator('#menu-mobile-servizi');
|
||||
await expect(sub).toBeHidden();
|
||||
await subToggle.click();
|
||||
await expect(subToggle).toHaveAttribute('aria-expanded', 'true');
|
||||
await expect(sub).toBeVisible();
|
||||
await expect(sub.getByRole('link')).toHaveCount(SERVICE_PAGES.length);
|
||||
await sub.getByRole('link').nth(2).click();
|
||||
await expect(page).toHaveURL(/\/servizi\/[a-z-]+\/$/);
|
||||
await expect(page.locator('#menu-mobile')).toBeHidden();
|
||||
});
|
||||
|
||||
test('a 390 px non c’è scorrimento orizzontale', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
const overflow = await page.evaluate(
|
||||
() => document.documentElement.scrollWidth - document.documentElement.clientWidth,
|
||||
);
|
||||
expect(overflow, 'larghezza in eccesso della home a 390 px').toBeLessThanOrEqual(0);
|
||||
});
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* Navigazione (brief §5.2, §5.3, §11.4): intestazione, sottomenu dei servizi, footer,
|
||||
* breadcrumb, precedente/successivo e redirect delle ancore del vecchio sito.
|
||||
*/
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { SERVICE_PAGES } from '../helpers/site';
|
||||
|
||||
const MAIN_NAV = [
|
||||
{ label: 'Lo studio', path: '/studio/' },
|
||||
{ label: 'Servizi', path: '/servizi/' },
|
||||
{ label: 'Contatti', path: '/contatti/' },
|
||||
{ label: 'Dove siamo', path: '/dove-siamo/' },
|
||||
{ label: 'Link utili', path: '/link-utili/' },
|
||||
];
|
||||
|
||||
test('le voci dell’intestazione portano alle pagine giuste', async ({ page }) => {
|
||||
for (const item of MAIN_NAV) {
|
||||
await page.goto('/');
|
||||
const nav = page.getByRole('navigation', { name: 'Principale' });
|
||||
await nav.getByRole('link', { name: item.label, exact: true }).click();
|
||||
await expect(page, `la voce «${item.label}» porta a ${item.path}`).toHaveURL(item.path);
|
||||
await expect(
|
||||
page.getByRole('navigation', { name: 'Principale' }).getByRole('link', {
|
||||
name: item.label,
|
||||
exact: true,
|
||||
}),
|
||||
`la voce «${item.label}» è evidenziata come pagina corrente`,
|
||||
).toHaveAttribute('aria-current', 'page');
|
||||
}
|
||||
});
|
||||
|
||||
test('logo e pulsante «Richiedi un preventivo»', async ({ page }) => {
|
||||
await page.goto('/studio/');
|
||||
await page.locator('header .brand').first().click();
|
||||
await expect(page).toHaveURL('/');
|
||||
await page
|
||||
.getByRole('navigation', { name: 'Principale' })
|
||||
.getByRole('link', { name: 'Richiedi un preventivo' })
|
||||
.click();
|
||||
await expect(page).toHaveURL('/contatti/');
|
||||
});
|
||||
|
||||
test('il sottomenu «Servizi» elenca i 6 servizi e si apre con il pulsante', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
const toggle = page.locator('.nav [data-submenu-toggle]');
|
||||
const submenu = page.locator('#sottomenu-servizi');
|
||||
await expect(submenu).toBeHidden();
|
||||
await toggle.click();
|
||||
await expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
||||
await expect(submenu).toBeVisible();
|
||||
await expect(submenu.getByRole('link')).toHaveCount(SERVICE_PAGES.length);
|
||||
await submenu.getByRole('link').first().click();
|
||||
await expect(page).toHaveURL(/\/servizi\/[a-z-]+\/$/);
|
||||
await expect(
|
||||
page.getByRole('navigation', { name: 'Principale' }).getByRole('link', {
|
||||
name: 'Servizi',
|
||||
exact: true,
|
||||
}),
|
||||
).toHaveAttribute('aria-current', 'true');
|
||||
});
|
||||
|
||||
test('il sottomenu si apre anche al passaggio del mouse e si chiude con un clic fuori', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto('/');
|
||||
const submenu = page.locator('#sottomenu-servizi');
|
||||
await page.locator('.nav__item--has-sub').hover();
|
||||
await expect(submenu).toBeVisible();
|
||||
await page.mouse.move(10, 600);
|
||||
await expect(submenu).toBeHidden();
|
||||
await page.locator('.nav [data-submenu-toggle]').click();
|
||||
await expect(submenu).toBeVisible();
|
||||
await page.mouse.move(10, 600);
|
||||
await page.locator('main h1').click();
|
||||
await expect(submenu).toBeHidden();
|
||||
});
|
||||
|
||||
test('tutti i link del footer funzionano', async ({ page, request }) => {
|
||||
await page.goto('/');
|
||||
const hrefs = await page
|
||||
.locator('footer a[href^="/"]')
|
||||
.evaluateAll((links) => links.map((a) => a.getAttribute('href') ?? ''));
|
||||
expect(hrefs.length, 'link interni nel footer').toBeGreaterThanOrEqual(11);
|
||||
for (const href of new Set(hrefs)) {
|
||||
const response = await request.get(href);
|
||||
expect(response.status(), `link del footer ${href}`).toBe(200);
|
||||
}
|
||||
for (const label of ['Privacy policy', 'Cookie policy', 'Note legali', 'Accessibilità']) {
|
||||
await expect(
|
||||
page.getByRole('navigation', { name: 'Informazioni legali' }).getByRole('link', {
|
||||
name: label,
|
||||
}),
|
||||
).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test('breadcrumb, barra laterale e precedente/successivo nelle pagine dei servizi', async ({
|
||||
page,
|
||||
}) => {
|
||||
for (const path of SERVICE_PAGES) {
|
||||
await page.goto(path);
|
||||
const breadcrumb = page.getByRole('navigation', { name: 'Percorso' });
|
||||
await expect(breadcrumb.getByRole('link', { name: 'Home' })).toHaveAttribute('href', '/');
|
||||
await expect(breadcrumb.getByRole('link', { name: 'Servizi' })).toHaveAttribute(
|
||||
'href',
|
||||
'/servizi/',
|
||||
);
|
||||
await expect(
|
||||
page.locator('.sidenav a[aria-current="page"]'),
|
||||
`servizio corrente evidenziato in ${path}`,
|
||||
).toHaveAttribute('href', path);
|
||||
}
|
||||
await page.goto(SERVICE_PAGES[0]);
|
||||
const pager = page.getByRole('navigation', { name: 'Servizio precedente e successivo' });
|
||||
const next = await pager.locator('a[rel="next"]').getAttribute('href');
|
||||
await pager.locator('a[rel="next"]').click();
|
||||
await expect(page).toHaveURL(next ?? '');
|
||||
await page
|
||||
.getByRole('navigation', { name: 'Servizio precedente e successivo' })
|
||||
.locator('a[rel="prev"]')
|
||||
.click();
|
||||
await expect(page).toHaveURL(SERVICE_PAGES[0]);
|
||||
});
|
||||
|
||||
test('le ancore del vecchio sito portano al servizio corrispondente', async ({ page }) => {
|
||||
await page.goto('/servizi/');
|
||||
const cards = await page
|
||||
.locator('[data-legacy-href]')
|
||||
.evaluateAll((els) =>
|
||||
els.map((el) => ({ id: el.id, href: el.getAttribute('data-legacy-href') })),
|
||||
);
|
||||
expect(cards.length, 'card con ancora del vecchio sito').toBe(6);
|
||||
for (const { id, href } of cards) {
|
||||
await page.goto(`/servizi/#${id}`);
|
||||
await expect(page, `l'ancora #${id} porta a ${href}`).toHaveURL(href ?? '');
|
||||
}
|
||||
await page.goto('/servizi/#ancora-sconosciuta');
|
||||
await expect(page).toHaveURL('/servizi/#ancora-sconosciuta');
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Privacy (brief §8.2, §11.4): nessuna richiesta verso host esterni al caricamento delle pagine,
|
||||
* nessun cookie, localStorage vuoto, mappa Google caricata solo dopo il clic.
|
||||
*/
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { ALL_PAGES, isLocalRequest, stubGoogle } from '../helpers/site';
|
||||
|
||||
test('nessuna richiesta verso host esterni, nessun cookie e localStorage vuoto', async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const external: string[] = [];
|
||||
page.on('request', (req) => {
|
||||
if (!isLocalRequest(req.url())) external.push(`${req.url()} (pagina ${page.url()})`);
|
||||
});
|
||||
|
||||
for (const path of ALL_PAGES) {
|
||||
await page.goto(path, { waitUntil: 'networkidle' });
|
||||
// scorrimento fino in fondo: eventuali contenuti caricati in modo differito partono ora
|
||||
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
||||
await page.waitForLoadState('networkidle');
|
||||
const storage = await page.evaluate(() => window.localStorage.length);
|
||||
expect(storage, `voci in localStorage dopo ${path}`).toBe(0);
|
||||
}
|
||||
|
||||
expect(external, 'richieste verso host diversi da localhost').toEqual([]);
|
||||
expect(await context.cookies(), 'cookie impostati durante la navigazione').toEqual([]);
|
||||
});
|
||||
|
||||
for (const path of ['/', '/contatti/', '/dove-siamo/']) {
|
||||
test(`mappa click-to-load in ${path}`, async ({ page, context }) => {
|
||||
const google = await stubGoogle(page);
|
||||
await page.goto(path, { waitUntil: 'networkidle' });
|
||||
|
||||
await expect(page.locator('iframe'), 'iframe presenti prima del clic').toHaveCount(0);
|
||||
expect(google, 'richieste a Google prima del clic').toEqual([]);
|
||||
|
||||
const blocks = page.locator('[data-map-consent]');
|
||||
const count = await blocks.count();
|
||||
expect(count, 'blocchi mappa nella pagina').toBeGreaterThan(0);
|
||||
const first = blocks.first();
|
||||
await expect(first).toContainText('Google Maps');
|
||||
await expect(first.locator('a[href="/cookie-policy/"]')).toHaveCount(1);
|
||||
await expect(first.locator('a[href^="https://www.google.com/maps/search/"]')).toHaveCount(1);
|
||||
await expect(first.locator('a[href^="https://www.openstreetmap.org/search"]')).toHaveCount(1);
|
||||
|
||||
await first.locator('[data-map-load]').click();
|
||||
const iframe = first.locator('iframe');
|
||||
await expect(iframe).toHaveCount(1);
|
||||
await expect(iframe).toHaveAttribute('src', /^https:\/\/www\.google\.com\/maps\/embed\?pb=/);
|
||||
await expect(iframe).toHaveAttribute('title', /Mappa/);
|
||||
await expect(iframe).toHaveAttribute('loading', 'lazy');
|
||||
await expect
|
||||
.poll(() => google.length, { message: 'richiesta a Google dopo il clic' })
|
||||
.toBeGreaterThan(0);
|
||||
|
||||
const remembered = await page.evaluate(() => sessionStorage.getItem('mappa-consentita'));
|
||||
expect(remembered, 'scelta ricordata in sessionStorage').toBe('1');
|
||||
|
||||
// la scelta vale per la sessione: ricaricando, le mappe compaiono senza un nuovo clic
|
||||
await page.reload({ waitUntil: 'networkidle' });
|
||||
await expect(page.locator('[data-map-consent] iframe')).toHaveCount(count);
|
||||
|
||||
const ours = (await context.cookies()).filter((c) => !c.domain.includes('google'));
|
||||
expect(ours, 'cookie del sito dopo il caricamento della mappa').toEqual([]);
|
||||
});
|
||||
}
|
||||
|
||||
test('senza JavaScript restano i link esterni della mappa e la navigazione', async ({
|
||||
browser,
|
||||
}) => {
|
||||
const context = await browser.newContext({ javaScriptEnabled: false });
|
||||
const page = await context.newPage();
|
||||
await page.goto('/dove-siamo/');
|
||||
await expect(page.locator('[data-map-load]').first()).toBeHidden();
|
||||
await expect(
|
||||
page.locator('a[href^="https://www.google.com/maps/search/"]').first(),
|
||||
).toBeVisible();
|
||||
await expect(page.locator('iframe')).toHaveCount(0);
|
||||
await page.goto('/');
|
||||
await expect(
|
||||
page.getByRole('navigation', { name: 'Principale' }).getByRole('link', { name: 'Lo studio' }),
|
||||
).toBeVisible();
|
||||
await context.close();
|
||||
});
|
||||
|
||||
test('senza JavaScript il menu è navigabile anche su mobile', async ({ browser }) => {
|
||||
const context = await browser.newContext({
|
||||
javaScriptEnabled: false,
|
||||
viewport: { width: 390, height: 844 },
|
||||
});
|
||||
const page = await context.newPage();
|
||||
await page.goto('/');
|
||||
await expect(page.locator('[data-menu-open]')).toBeHidden();
|
||||
const menu = page.getByRole('navigation', { name: 'Menu mobile' });
|
||||
await expect(menu.getByRole('link', { name: 'Contatti', exact: true })).toBeVisible();
|
||||
await expect(menu.locator('#menu-mobile-servizi a').first()).toBeVisible();
|
||||
await context.close();
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Smoke test di tutte le pagine (brief §11.4): risposta 200, un solo <h1>, 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 <h1> nella pagina ${path}`).toHaveCount(1);
|
||||
await expect(page.locator('h1'), `<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<string, string>();
|
||||
const descriptions = new Map<string, string>();
|
||||
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/);
|
||||
});
|
||||
Reference in new issue
Block a user