import { test, expect, type Page } from "@playwright/test"; const BASE = "http://localhost:3000"; /** * Dev console transport: request a magic link, then complete it in the browser * context so the Auth.js session cookie is set for the navigation under test. */ async function signInAs(page: Page, email: string) { const res = await page.request.post(`${BASE}/api/dev/magic-link`, { data: { email }, }); expect(res.ok(), "magic-link request should succeed").toBe(true); const body = (await res.json()) as { url?: string }; expect(body.url, "magic-link should return a sign-in url").toBeTruthy(); await page.goto(body.url!); await expect(page).toHaveURL(/complete/); } /** * Unit D7 — read-only scheduling grid. Done when: renders a seeded week; no * console errors. Captures console + page errors and fails the test if any are * logged while the grid is mounted. */ test.describe("schedule grid", () => { test("renders a seeded week with no console errors", async ({ page }) => { const errors: string[] = []; page.on("console", (msg) => { if (msg.type() === "error") errors.push(msg.text()); }); page.on("pageerror", (err) => errors.push(`page error: ${err.message}`)); await page.setViewportSize({ width: 1024, height: 768 }); await signInAs(page, `e2e-grid-${Date.now()}@example.com`); await page.goto(`${BASE}/schedule`); await expect(page).toHaveURL(`${BASE}/schedule`); // Grid header: one column per active position. await expect(page.getByRole("columnheader", { name: "Audio", exact: true })).toBeVisible(); await expect(page.getByRole("columnheader", { name: "Livestream", exact: true })).toBeVisible(); await expect(page.getByRole("columnheader", { name: "Slides", exact: true })).toBeVisible(); // At least one seeded instance row renders. The row label is // " · ", so match the service name as a substring. await expect(page.getByText("Sunday 9:00 AM", { exact: false })).toBeVisible(); // Week navigation controls are present. await expect(page.getByRole("link", { name: /Prev/ })).toBeVisible(); await expect(page.getByRole("link", { name: /Next/ })).toBeVisible(); // No console or page errors while the grid is mounted. expect(errors, `unexpected console/page errors: ${errors.join("; ")}`).toEqual([]); }); test("week navigation changes the URL and the rendered week", async ({ page }) => { await page.setViewportSize({ width: 1024, height: 768 }); await signInAs(page, `e2e-grid-nav-${Date.now()}@example.com`); await page.goto(`${BASE}/schedule`); await expect(page.getByText("Sunday 9:00 AM", { exact: false })).toBeVisible(); const before = page.url(); await page.getByRole("link", { name: /Next/ }).click(); await expect(page).toHaveURL(/week=/); // The URL carries the target week; the grid re-renders server-side. expect(page.url()).not.toBe(before); await expect(page.getByText("Sunday 9:00 AM")).toBeVisible(); }); });