import { test, expect, seed, loginAs, pickEvent } from "./fixtures"; // Kids check-in (1.45.0): a supervisor sets it up, a parent adds a child, the desk checks the child // in (pickup code + sticker panel), the parent sees the code, and a wrong code is refused before // the real one checks the child out. "E2E Kids Church" is seeded hidden and on today. test.describe.serial("kids check-in", () => { test("a supervisor sets up the kids ticket, a room and switches it on", async ({ page }) => { await loginAs(page, "supervisor"); await page.goto("/dashboard/supervisor/kids"); await pickEvent(page, "E2E Kids Church"); await page.getByRole("button", { name: /Add a free "Kids check-in" ticket/ }).click(); await expect(page.getByLabel("Kids ticket")).not.toHaveValue(""); await page.getByRole("button", { name: /Add "Kids rooms"/ }).click(); await page.getByLabel("Room name").last().fill("Little Lambs"); await page.getByLabel("Youngest age").last().fill("0"); await page.getByLabel("Oldest age").last().fill("5"); await page.getByLabel("Children per leader").last().fill("4"); await page.getByRole("button", { name: "Add", exact: true }).click(); await expect(page.getByLabel("Room name").first()).toHaveValue("Little Lambs"); await page.getByRole("button", { name: "Switch on" }).click(); await expect(page.getByText("Kids check-in is on")).toBeVisible(); }); test("a parent adds their family and a child", async ({ page }) => { await loginAs(page, "user"); await page.goto("/dashboard/user/kids"); await page.getByRole("button", { name: "Add family" }).click(); await page.getByRole("button", { name: "Add a child" }).click(); await page.getByLabel("First name *").fill("Lulu"); const dob = new Date(); dob.setFullYear(dob.getFullYear() - 3); await page.getByLabel("Date of birth").fill(dob.toISOString().slice(0, 10)); await page.getByLabel("Allergies").fill("Peanuts"); await page.getByRole("button", { name: "Add child" }).click(); await expect(page.getByText("Allergies: Peanuts")).toBeVisible(); await expect(page.getByAltText("Family QR code")).toBeVisible(); }); test("the desk checks the child in, the parent sees the code, and only the right code checks out", async ({ page, browser }) => { await loginAs(page, "staff"); await page.goto("/dashboard/staff/kids"); await page.getByLabel("Event").selectOption(seed().events.kids); await page.getByLabel("Find a family").fill("Lulu"); await page.getByRole("button", { name: "Search" }).click(); await page.getByRole("button", { name: /Lulu/ }).click(); // The room is suggested from her age. await expect(page.getByLabel("Room for Lulu")).toHaveValue(/.+/); await page.getByRole("button", { name: "Check in", exact: true }).last().click(); const code = (await page.getByTestId("desk-code").textContent())!.trim(); expect(code).toMatch(/^[A-HJ-NP-Z2-9]{4}$/); const sticker = page.getByTestId("sticker"); await expect(sticker).toContainText("Lulu"); await expect(sticker).toContainText("Little Lambs"); await expect(sticker).toContainText("ALLERGY: PEANUTS"); // The parent's phone shows the same code. const parent = await browser.newPage(); await parent.addInitScript(() => localStorage.setItem("hope_events_cookie_consent", "declined")); await loginAs(parent, "user"); await parent.goto("/dashboard/user/kids"); await expect(parent.getByTestId("pickup-code")).toHaveText(code); await parent.close(); // A wrong code is refused. await page.getByRole("button", { name: "Check out" }).first().click(); const wrong = code === "ZZZZ" ? "YYYY" : "ZZZZ"; await page.getByLabel("Pickup code").fill(wrong); await page.getByRole("button", { name: "Find" }).click(); await expect(page.getByRole("alert").filter({ hasText: "doesn't match any child" })).toBeVisible(); // The real one checks her out. await page.getByLabel("Pickup code").fill(code.toLowerCase()); await page.getByRole("button", { name: "Find" }).click(); await expect(page.getByText("Lulu", { exact: false }).first()).toBeVisible(); await page.getByRole("button", { name: "Check out" }).last().click(); await expect(page.getByRole("status")).toContainText("Collected: Lulu"); }); test("the room screen shows the wrong-code alert", async ({ page }) => { await loginAs(page, "staff"); await page.goto("/dashboard/staff/kids/rooms"); await expect(page.getByRole("alert").filter({ hasText: "Wrong pickup code" }).first()).toBeVisible(); await page.getByRole("button", { name: "Dealt with" }).first().click(); await expect(page.getByRole("status")).toContainText("Alert cleared"); }); });