Files
Studio_Grasso/tests/a11y/axe.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

78 lines
3.0 KiB
TypeScript

/**
* Accessibilità automatica con axe-core (brief §11.3): tutte le pagine (lette dalla sitemap)
* a 1440 e 390 px, più gli stati interattivi (menu mobile e sottomenu aperti, mappa caricata).
* Criterio: zero violazioni «serious» o «critical» (WCAG 2.0/2.1 A e AA e buone pratiche);
* le violazioni minori sono comunque riportate nel messaggio d'errore e nelle annotazioni.
*/
import AxeBuilder from '@axe-core/playwright';
import { expect, test, type Page } from '@playwright/test';
import { ALL_PAGES, stubGoogle } from '../helpers/site';
const VIEWPORTS = [
{ name: 'desktop', width: 1440, height: 900 },
{ name: 'mobile', width: 390, height: 844 },
];
const TAGS = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'best-practice'];
async function audit(page: Page, where: string, include?: string, exclude?: string) {
let builder = new AxeBuilder({ page }).withTags(TAGS);
if (include) builder = builder.include(include);
if (exclude) builder = builder.exclude(exclude);
const results = await builder.analyze();
const blocking = results.violations.filter(
(v) => v.impact === 'serious' || v.impact === 'critical',
);
const report = results.violations.map(
(v) =>
`[${v.impact}] ${v.id}: ${v.help} — ${v.nodes
.slice(0, 5)
.map((n) => n.target.join(' '))
.join(' | ')}`,
);
if (report.length > 0) {
test.info().annotations.push({ type: 'axe', description: `${where}\n${report.join('\n')}` });
}
expect(blocking, `violazioni gravi di accessibilità in ${where}:\n${report.join('\n')}`).toEqual(
[],
);
}
for (const vp of VIEWPORTS) {
test.describe(`${vp.name} ${vp.width}px`, () => {
test.use({ viewport: { width: vp.width, height: vp.height } });
for (const path of ALL_PAGES) {
test(`axe: ${path}`, async ({ page }) => {
await page.goto(path, { waitUntil: 'networkidle' });
await audit(page, `${path} a ${vp.width}px`);
});
}
});
}
test.describe('stati interattivi', () => {
test('menu mobile aperto con sottomenu', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await page.goto('/');
await page.locator('[data-menu-open]').click();
await page.locator('#menu-mobile [data-submenu-toggle]').click();
await audit(page, 'menu mobile aperto', '#menu-mobile');
});
test('sottomenu desktop aperto', async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
await page.goto('/');
await page.locator('.nav [data-submenu-toggle]').click();
await audit(page, 'sottomenu desktop aperto', 'header');
});
test('mappa caricata', async ({ page }) => {
await stubGoogle(page);
await page.goto('/contatti/');
await page.locator('[data-map-load]').first().click();
await expect(page.locator('[data-map-consent] iframe')).toHaveCount(1);
// il contenuto dell'iframe è di Google (terze parti): si verifica solo il nostro markup
await audit(page, 'mappa caricata', '[data-map-consent]', '[data-map-consent] iframe');
});
});