|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +import { |
| 4 | + deleteSeededCampaignDeclarations, |
| 5 | + seedSubmittedDeclarationsForStats, |
| 6 | +} from "./helpers/db"; |
| 7 | + |
| 8 | +// 9-digit SIRENs reserved for this test only — chosen outside any legitimate |
| 9 | +// range so we don't collide with real data. |
| 10 | +const SIRENS = { |
| 11 | + smallA: "999300001", |
| 12 | + smallB: "999300002", |
| 13 | + largeA: "999300003", |
| 14 | +} as const; |
| 15 | + |
| 16 | +test.describe("admin campaign progression stats", () => { |
| 17 | + test.beforeAll(async () => { |
| 18 | + await seedSubmittedDeclarationsForStats([ |
| 19 | + { |
| 20 | + siren: SIRENS.smallA, |
| 21 | + year: 2024, |
| 22 | + submittedAt: "2024-01-15T10:00:00Z", |
| 23 | + workforce: 30, |
| 24 | + }, |
| 25 | + { |
| 26 | + siren: SIRENS.smallB, |
| 27 | + year: 2025, |
| 28 | + submittedAt: "2025-01-20T10:00:00Z", |
| 29 | + workforce: 30, |
| 30 | + }, |
| 31 | + { |
| 32 | + siren: SIRENS.largeA, |
| 33 | + year: 2026, |
| 34 | + submittedAt: "2026-01-10T10:00:00Z", |
| 35 | + workforce: 250, |
| 36 | + }, |
| 37 | + ]); |
| 38 | + }); |
| 39 | + |
| 40 | + test.afterAll(async () => { |
| 41 | + await deleteSeededCampaignDeclarations(Object.values(SIRENS)); |
| 42 | + }); |
| 43 | + |
| 44 | + test("admin can open the campaign stats page and sees the chart", async ({ |
| 45 | + page, |
| 46 | + }) => { |
| 47 | + await page.goto("/admin/stats/campagne"); |
| 48 | + |
| 49 | + await expect( |
| 50 | + page.getByRole("heading", { name: "Statistiques campagne", level: 1 }), |
| 51 | + ).toBeVisible(); |
| 52 | + await expect( |
| 53 | + page.getByRole("heading", { |
| 54 | + name: "Progression dans le temps", |
| 55 | + level: 2, |
| 56 | + }), |
| 57 | + ).toBeVisible(); |
| 58 | + await expect( |
| 59 | + page.getByRole("figure", { |
| 60 | + name: /courbe de progression cumulative/i, |
| 61 | + }), |
| 62 | + ).toBeVisible(); |
| 63 | + }); |
| 64 | + |
| 65 | + test("accessible alternative table lists the same data", async ({ page }) => { |
| 66 | + await page.goto("/admin/stats/campagne"); |
| 67 | + |
| 68 | + // Wait for the chart to be rendered — the table renders next to it only |
| 69 | + // once the tRPC query resolves. |
| 70 | + await expect( |
| 71 | + page.getByRole("figure", { name: /courbe de progression cumulative/i }), |
| 72 | + ).toBeVisible(); |
| 73 | + |
| 74 | + // The table lives inside a <details> disclosure — use the summary text |
| 75 | + // directly rather than a role match (varies across browsers). |
| 76 | + await page |
| 77 | + .locator("summary", { |
| 78 | + hasText: /consulter les données du graphique sous forme de tableau/i, |
| 79 | + }) |
| 80 | + .click(); |
| 81 | + |
| 82 | + await expect( |
| 83 | + page.getByRole("columnheader", { name: "2024" }), |
| 84 | + ).toBeVisible(); |
| 85 | + }); |
| 86 | + |
| 87 | + test("filtering by size range keeps only matching companies", async ({ |
| 88 | + page, |
| 89 | + }) => { |
| 90 | + await page.goto("/admin/stats/campagne"); |
| 91 | + await page.getByLabel("Tranche d'effectif").selectOption("250+"); |
| 92 | + |
| 93 | + // The small-company seeds should disappear; the large one (workforce=250) |
| 94 | + // still contributes to the 2026 curve. |
| 95 | + await expect( |
| 96 | + page.getByRole("figure", { name: /courbe de progression cumulative/i }), |
| 97 | + ).toBeVisible(); |
| 98 | + }); |
| 99 | +}); |
| 100 | + |
| 101 | +test("non-admin users are redirected away from the stats page", async ({ |
| 102 | + browser, |
| 103 | +}) => { |
| 104 | + const anonCtx = await browser.newContext({ storageState: undefined }); |
| 105 | + try { |
| 106 | + const page = await anonCtx.newPage(); |
| 107 | + await page.goto("/admin/stats/campagne"); |
| 108 | + // Redirected to /login (anonymous). |
| 109 | + await expect(page).toHaveURL(/\/login/); |
| 110 | + } finally { |
| 111 | + await anonCtx.close(); |
| 112 | + } |
| 113 | +}); |
0 commit comments