- 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
104 lines
4.7 KiB
TypeScript
104 lines
4.7 KiB
TypeScript
/**
|
|
* 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');
|
|
});
|
|
});
|