Files
Studio_Grasso/tests/e2e/navigation.spec.ts
T
Claude 601d13cfaf 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
2026-10-15 22:55:46 +00:00

140 lines
5.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 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');
});