import { test, expect } from "./fixtures"; test.describe("formulaire de contact", () => { test("affiche les erreurs associées aux champs", async ({ page }) => { await page.goto("/nous-joindre"); await page.getByRole("button", { name: /Envoyer le message/ }).click(); const alerts = page.getByRole("alert"); await expect(alerts.first()).toBeVisible(); const name = page.getByLabel(/^Nom/); await expect(name).toHaveAttribute("aria-invalid", "true"); const described = await name.getAttribute("aria-describedby"); expect(described).toBeTruthy(); await expect(page.locator(`#${described}`)).toBeVisible(); }); test("soumission valide → état de confirmation (transport log, aucun courriel réel)", async ({ page, }) => { await page.goto("/nous-joindre"); await page.getByLabel(/^Nom/).fill("Test Playwright"); await page.getByLabel(/^Courriel/).fill("test@exemple.com"); await page.getByLabel(/^Sujet/).selectOption({ index: 1 }); await page .getByLabel(/^Message/) .fill("Ceci est un message de test automatisé d’au moins vingt caractères."); await page.getByLabel(/J’accepte|J'accepte/).check(); await page.waitForTimeout(2600); // délai anti-robot minimal await page.getByRole("button", { name: /Envoyer le message/ }).click(); const status = page.getByRole("status"); await expect(status).toContainText("Message envoyé"); await expect(status).toContainText("pas encore configuré"); // honnêteté : transport log }); test("l'API refuse une requête malformée", async ({ request }) => { const res = await request.post("/api/contact", { data: { name: "" } }); expect(res.status()).toBe(400); const body = await res.json(); expect(body.ok).toBe(false); }); });