import { test, expect } from "@playwright/test"; import { signInAs, resetDb, BASE } from "./dev"; /** * 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", () => { // Establish a clean seeded state before the read-only suite runs. The grid // is read-only, but it shares the DB with the mutating assign-mutations // suite; resetting here keeps this suite independent of run order. test.beforeAll(async ({ browser }) => { const context = await browser.newContext(); const page = await context.newPage(); await resetDb(page); await context.close(); }); 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(); }); });