SPB Git

spb/phi-conseil

Public
1.8 KB · 41 lines typescript
1import { test, expect } from "@playwright/test";23test.describe("formulaire de contact", () => {4  test("affiche les erreurs associées aux champs", async ({ page }) => {5    await page.goto("/nous-joindre");6    await page.getByRole("button", { name: /Envoyer le message/ }).click();7    const alerts = page.getByRole("alert");8    await expect(alerts.first()).toBeVisible();9    const name = page.getByLabel(/^Nom/);10    await expect(name).toHaveAttribute("aria-invalid", "true");11    const described = await name.getAttribute("aria-describedby");12    expect(described).toBeTruthy();13    await expect(page.locator(`#${described}`)).toBeVisible();14  });1516  test("soumission valide → état de confirmation (transport log, aucun courriel réel)", async ({17    page,18  }) => {19    await page.goto("/nous-joindre");20    await page.getByLabel(/^Nom/).fill("Test Playwright");21    await page.getByLabel(/^Courriel/).fill("test@exemple.com");22    await page.getByLabel(/^Sujet/).selectOption({ index: 1 });23    await page24      .getByLabel(/^Message/)25      .fill("Ceci est un message de test automatisé d’au moins vingt caractères.");26    await page.getByLabel(/J’accepte|J'accepte/).check();27    await page.waitForTimeout(2600); // délai anti-robot minimal28    await page.getByRole("button", { name: /Envoyer le message/ }).click();29    const status = page.getByRole("status");30    await expect(status).toContainText("Message envoyé");31    await expect(status).toContainText("pas encore configuré"); // honnêteté : transport log32  });3334  test("l'API refuse une requête malformée", async ({ request }) => {35    const res = await request.post("/api/contact", { data: { name: "" } });36    expect(res.status()).toBe(400);37    const body = await res.json();38    expect(body.ok).toBe(false);39  });40});41
Files · 18a9e1379a7e4662b184e2c070c92578c5de3ea8
Menu

Theme