diff --git a/components/frontend/tests/e2e/hackathons.ts b/components/frontend/tests/e2e/hackathons.ts new file mode 100644 index 00000000..31f30870 --- /dev/null +++ b/components/frontend/tests/e2e/hackathons.ts @@ -0,0 +1,58 @@ +import { test as base } from "@playwright/test" +import { storageState } from "./paths" + +export { expect } from "@playwright/test" + +/** + * The seeded hackathons the tests visit, under the labels the seed's README + * gives them — see "Hackathons at a glance" in + * components/backend/cmd/seed/README.md. + */ +export const seeded = { + H1: "AI Innovation Challenge 2026", + H3: "Internal Product Sprint", + H6: "Open Science Hackathon 2026", +} as const +export type Seeded = keyof typeof seeded + +/** + * `test`, plus `hackathonId`, which turns a seeded hackathon into its id. + * + * The ids are new on every seed, so they are looked up by name, once per + * worker. The lookup reads the admin's list of every hackathon, the one page + * that shows private ones to someone who takes part in none. + */ +export const test = base.extend< + object, + { hackathonId: (hackathon: Seeded) => string } +>({ + hackathonId: [ + async ({ browser }, use) => { + const context = await browser.newContext({ + storageState: storageState("hackagon-admin"), + }) + const page = await context.newPage() + await page.goto("/manage/hackathons") + + const ids = {} as Record + for (const [key, name] of Object.entries(seeded) as [Seeded, string][]) { + const href = await page + .getByRole("link", { name, exact: true }) + .first() + .getAttribute("href") + // Relative (`./my/hackathon/…`) as served, absolute once hydrated. + const id = href?.match(/\/my\/hackathon\/([^/]+)\//)?.[1] + if (!id) { + throw new Error( + `No hackathon named "${name}" on /manage/hackathons. Seed the stack: just db::seed`, + ) + } + ids[key] = id + } + await context.close() + + await use((hackathon) => ids[hackathon]) + }, + { scope: "worker" }, + ], +}) diff --git a/components/frontend/tests/e2e/paths.ts b/components/frontend/tests/e2e/paths.ts index ee2a94e4..66c45816 100644 --- a/components/frontend/tests/e2e/paths.ts +++ b/components/frontend/tests/e2e/paths.ts @@ -10,7 +10,7 @@ export const outDir = path.resolve( * The logins from the dev Keycloak realm that the tests sign in as. What each * one can see is set by the seed — see components/backend/cmd/seed/README.md. */ -export const users = ["alice", "bob"] as const +export const users = ["alice", "bob", "hackagon-admin"] as const export type User = (typeof users)[number] export const password = "aliceandbob" diff --git a/components/frontend/tests/e2e/visibility.spec.ts b/components/frontend/tests/e2e/visibility.spec.ts new file mode 100644 index 00000000..c19f5140 --- /dev/null +++ b/components/frontend/tests/e2e/visibility.spec.ts @@ -0,0 +1,152 @@ +import { expect, test } from "./hackathons" +import { storageState } from "./paths" + +// Who may open what: a private hackathon, a hackathon's organizer pages, the +// platform's admin pages. The backend decides every one of these; the tests +// check that the browser ends up where that decision says. +// +// Read-only, like smoke.spec.ts, and on facts a clicked-through local stack +// keeps: nobody can join H3 (private, past, no invitation), and bob, alice and +// hackagon-admin keep their roles in H1 and H6. + +test.describe("signed out", () => { + test("a private hackathon has no public page", async ({ + page, + hackathonId, + }) => { + const response = await page.goto(`/hackathon/${hackathonId("H3")}`) + + expect(response?.status()).toBe(404) + await expect(page.getByText("Hackathon not found")).toBeVisible() + }) + + test("a public hackathon's page counts its participants but does not name them", async ({ + page, + hackathonId, + }) => { + await page.goto(`/hackathon/${hackathonId("H1")}`) + + await expect(page.getByText(/\d+ participants?\b/)).toBeVisible() + // bob and alice both take part in H1. + await expect(page.getByText("Bob Henderson")).toHaveCount(0) + await expect(page.getByText("Alice Wonderland")).toHaveCount(0) + }) +}) + +test.describe("bob, a participant", () => { + test.use({ storageState: storageState("bob") }) + + test("is refused a private hackathon he is not in, by its address", async ({ + page, + hackathonId, + }) => { + const response = await page.goto( + `/my/hackathon/${hackathonId("H3")}/overview`, + ) + + expect(response?.status()).toBe(403) + await expect( + page.getByText("You are not a confirmed member of this hackathon"), + ).toBeVisible() + }) + + test("is offered the participant pages but no organizer pages", async ({ + page, + hackathonId, + }) => { + await page.goto(`/my/hackathon/${hackathonId("H1")}/overview`) + + const sidebar = page.locator("aside") + await expect( + sidebar.getByRole("link", { name: "Projects", exact: true }), + ).toBeVisible() + await expect(sidebar.getByRole("link", { name: /^Manage / })).toHaveCount(0) + await expect(sidebar.getByRole("link", { name: "Settings" })).toHaveCount(0) + }) + + test("is refused an organizer page, by its address", async ({ + page, + hackathonId, + }) => { + const response = await page.goto( + `/my/hackathon/${hackathonId("H1")}/participants/manage`, + ) + + expect(response?.status()).toBe(403) + await expect( + page.getByText("Only the hackathon organizer can manage participants"), + ).toBeVisible() + }) + + test("is refused the platform's user list", async ({ page }) => { + const response = await page.goto("/manage/users") + + expect(response?.status()).toBe(403) + }) +}) + +test.describe("alice, an organizer", () => { + test.use({ storageState: storageState("alice") }) + + test("is offered the organizer pages of a hackathon she runs", async ({ + page, + hackathonId, + }) => { + await page.goto(`/my/hackathon/${hackathonId("H1")}/overview`) + + const sidebar = page.locator("aside") + for (const name of [ + "Settings", + "Manage Participants", + "Manage Projects", + "Manage Teams", + "Manage Voting", + ]) { + await expect(sidebar.getByRole("link", { name })).toBeVisible() + } + }) + + // Organizer is a role in a hackathon, not on the platform. + test("is refused the platform's user list", async ({ page }) => { + const response = await page.goto("/manage/users") + + expect(response?.status()).toBe(403) + }) +}) + +test.describe("hackagon-admin, the global admin", () => { + test.use({ storageState: storageState("hackagon-admin") }) + + test("sees every hackathon, the private ones included", async ({ page }) => { + await page.goto("/manage/hackathons") + + await expect( + page.getByRole("link", { name: "Internal Product Sprint", exact: true }), + ).toBeVisible() + await expect( + page.getByRole("link", { name: "Partner Data Sprint 2026", exact: true }), + ).toBeVisible() + }) + + // He takes part in no seeded hackathon he did not create, so this is the + // admin role at work, not membership. + test("opens a hackathon he does not take part in, with its organizer pages", async ({ + page, + hackathonId, + }) => { + const response = await page.goto( + `/my/hackathon/${hackathonId("H6")}/overview`, + ) + + expect(response?.status()).toBe(200) + await expect( + page.locator("aside").getByRole("link", { name: "Manage Participants" }), + ).toBeVisible() + }) + + test("opens the platform's user list", async ({ page }) => { + const response = await page.goto("/manage/users") + + expect(response?.status()).toBe(200) + }) +})