|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +import { deleteReferents, seedReferents } from "./helpers/db"; |
| 4 | + |
| 5 | +// Fixed UUIDs so detail-page URLs (`/referents/[id]`) pass the |
| 6 | +// `z.string().uuid()` check in `publicReferents.getById`. |
| 7 | +const TEST_REFERENTS = [ |
| 8 | + { |
| 9 | + id: "11111111-1111-4111-8111-111111111111", |
| 10 | + region: "11", |
| 11 | + county: "75", |
| 12 | + name: "E2E Référent Paris", |
| 13 | + type: "email" as const, |
| 14 | + value: "e2e-paris@dreets.test", |
| 15 | + principal: true, |
| 16 | + substituteName: "Suppléant Paris", |
| 17 | + substituteEmail: "e2e-paris-sub@dreets.test", |
| 18 | + }, |
| 19 | + { |
| 20 | + id: "22222222-2222-4222-8222-222222222222", |
| 21 | + region: "11", |
| 22 | + county: "92", |
| 23 | + name: "E2E Référent Hauts-de-Seine", |
| 24 | + type: "url" as const, |
| 25 | + value: "https://dreets.test/contact-92", |
| 26 | + principal: false, |
| 27 | + substituteName: null, |
| 28 | + substituteEmail: null, |
| 29 | + }, |
| 30 | + { |
| 31 | + id: "33333333-3333-4333-8333-333333333333", |
| 32 | + region: "53", |
| 33 | + county: "35", |
| 34 | + name: "E2E Référent Rennes", |
| 35 | + type: "email" as const, |
| 36 | + value: "e2e-rennes@dreets.test", |
| 37 | + principal: true, |
| 38 | + substituteName: null, |
| 39 | + substituteEmail: null, |
| 40 | + }, |
| 41 | +]; |
| 42 | + |
| 43 | +test.beforeAll(async () => { |
| 44 | + await seedReferents(TEST_REFERENTS); |
| 45 | +}); |
| 46 | + |
| 47 | +test.afterAll(async () => { |
| 48 | + await deleteReferents(TEST_REFERENTS.map((r) => r.id)); |
| 49 | +}); |
| 50 | + |
| 51 | +test.describe("public referents search", () => { |
| 52 | + test("anonymous user can access /referents without authentication", async ({ |
| 53 | + browser, |
| 54 | + }) => { |
| 55 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 56 | + try { |
| 57 | + const page = await anonCtx.newPage(); |
| 58 | + await page.goto("/referents"); |
| 59 | + await expect( |
| 60 | + page.getByRole("heading", { |
| 61 | + name: /référents égalité professionnelle/i, |
| 62 | + level: 1, |
| 63 | + }), |
| 64 | + ).toBeVisible(); |
| 65 | + expect(page.url()).toContain("/referents"); |
| 66 | + } finally { |
| 67 | + await anonCtx.close(); |
| 68 | + } |
| 69 | + }); |
| 70 | + |
| 71 | + test("search by region filters the results", async ({ browser }) => { |
| 72 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 73 | + try { |
| 74 | + const page = await anonCtx.newPage(); |
| 75 | + await page.goto("/referents"); |
| 76 | + await page.getByLabel("Région").selectOption("11"); |
| 77 | + await page.getByRole("button", { name: /^rechercher$/i }).click(); |
| 78 | + |
| 79 | + await expect(page.getByText("E2E Référent Paris")).toBeVisible(); |
| 80 | + await expect(page.getByText("E2E Référent Hauts-de-Seine")).toBeVisible(); |
| 81 | + await expect(page.getByText("E2E Référent Rennes")).not.toBeVisible(); |
| 82 | + } finally { |
| 83 | + await anonCtx.close(); |
| 84 | + } |
| 85 | + }); |
| 86 | + |
| 87 | + test("search by name filters the results", async ({ browser }) => { |
| 88 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 89 | + try { |
| 90 | + const page = await anonCtx.newPage(); |
| 91 | + await page.goto("/referents"); |
| 92 | + await page.getByLabel("Nom du référent").fill("Rennes"); |
| 93 | + await page.getByRole("button", { name: /^rechercher$/i }).click(); |
| 94 | + |
| 95 | + await expect(page.getByText("E2E Référent Rennes")).toBeVisible(); |
| 96 | + await expect(page.getByText("E2E Référent Paris")).not.toBeVisible(); |
| 97 | + } finally { |
| 98 | + await anonCtx.close(); |
| 99 | + } |
| 100 | + }); |
| 101 | + |
| 102 | + test("search with no matches shows the empty state", async ({ browser }) => { |
| 103 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 104 | + try { |
| 105 | + const page = await anonCtx.newPage(); |
| 106 | + await page.goto("/referents"); |
| 107 | + await page |
| 108 | + .getByLabel("Nom du référent") |
| 109 | + .fill("ZZZZ-nonexistent-name-XXX"); |
| 110 | + await page.getByRole("button", { name: /^rechercher$/i }).click(); |
| 111 | + |
| 112 | + await expect(page.getByText(/aucun référent/i)).toBeVisible(); |
| 113 | + } finally { |
| 114 | + await anonCtx.close(); |
| 115 | + } |
| 116 | + }); |
| 117 | + |
| 118 | + test("list page does not show contact details", async ({ browser }) => { |
| 119 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 120 | + try { |
| 121 | + const page = await anonCtx.newPage(); |
| 122 | + await page.goto("/referents"); |
| 123 | + await expect(page.getByText("E2E Référent Paris")).toBeVisible(); |
| 124 | + await expect(page.getByText("e2e-paris@dreets.test")).not.toBeVisible(); |
| 125 | + await expect( |
| 126 | + page.getByText("e2e-paris-sub@dreets.test"), |
| 127 | + ).not.toBeVisible(); |
| 128 | + } finally { |
| 129 | + await anonCtx.close(); |
| 130 | + } |
| 131 | + }); |
| 132 | + |
| 133 | + test("click-through to detail page reveals contact info", async ({ |
| 134 | + browser, |
| 135 | + }) => { |
| 136 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 137 | + try { |
| 138 | + const page = await anonCtx.newPage(); |
| 139 | + await page.goto("/referents"); |
| 140 | + |
| 141 | + const row = page.locator("li", { hasText: "E2E Référent Paris" }); |
| 142 | + await row.getByRole("link", { name: /voir le contact/i }).click(); |
| 143 | + |
| 144 | + await expect( |
| 145 | + page.getByRole("heading", { |
| 146 | + level: 1, |
| 147 | + name: /E2E Référent Paris/, |
| 148 | + }), |
| 149 | + ).toBeVisible(); |
| 150 | + await expect(page.getByText("e2e-paris@dreets.test")).toBeVisible(); |
| 151 | + await expect(page.getByText("Suppléant Paris")).toBeVisible(); |
| 152 | + await expect(page.getByText("e2e-paris-sub@dreets.test")).toBeVisible(); |
| 153 | + } finally { |
| 154 | + await anonCtx.close(); |
| 155 | + } |
| 156 | + }); |
| 157 | + |
| 158 | + test("URL-type referent is rendered as an external link", async ({ |
| 159 | + browser, |
| 160 | + }) => { |
| 161 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 162 | + try { |
| 163 | + const page = await anonCtx.newPage(); |
| 164 | + await page.goto("/referents/22222222-2222-4222-8222-222222222222"); |
| 165 | + |
| 166 | + const externalLink = page.getByRole("link", { |
| 167 | + name: /dreets\.test\/contact-92/i, |
| 168 | + }); |
| 169 | + await expect(externalLink).toBeVisible(); |
| 170 | + await expect(externalLink).toHaveAttribute("target", "_blank"); |
| 171 | + } finally { |
| 172 | + await anonCtx.close(); |
| 173 | + } |
| 174 | + }); |
| 175 | + |
| 176 | + test("detail page returns 404 for unknown id", async ({ browser }) => { |
| 177 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 178 | + try { |
| 179 | + const page = await anonCtx.newPage(); |
| 180 | + const response = await page.goto( |
| 181 | + "/referents/00000000-0000-4000-8000-000000000000", |
| 182 | + ); |
| 183 | + expect(response?.status()).toBe(404); |
| 184 | + } finally { |
| 185 | + await anonCtx.close(); |
| 186 | + } |
| 187 | + }); |
| 188 | +}); |
| 189 | + |
| 190 | +test("link from /aide/nous-contacter points to /referents", async ({ |
| 191 | + browser, |
| 192 | +}) => { |
| 193 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 194 | + try { |
| 195 | + const page = await anonCtx.newPage(); |
| 196 | + await page.goto("/aide/nous-contacter"); |
| 197 | + const searchLink = page.getByRole("link", { |
| 198 | + name: /rechercher un référent par région ou département/i, |
| 199 | + }); |
| 200 | + await expect(searchLink).toBeVisible(); |
| 201 | + await expect(searchLink).toHaveAttribute("href", "/referents"); |
| 202 | + } finally { |
| 203 | + await anonCtx.close(); |
| 204 | + } |
| 205 | +}); |
0 commit comments