import { test, expect, type Page } from "@playwright/test"; const BASE = "http://localhost:3000"; const TAB_LABELS = ["Schedule", "Roster", "Training", "Announcements", "Settings"]; /** * 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/); } test.describe("app shell", () => { test("renders the shell with 5 nav tabs at a 360px viewport", async ({ page }) => { await page.setViewportSize({ width: 360, height: 780 }); await signInAs(page, `e2e-mobile-${Date.now()}@example.com`); await page.goto(`${BASE}/schedule`); await expect(page).toHaveURL(`${BASE}/schedule`); // Header + page title. await expect(page.getByRole("heading", { name: "Schedule", level: 1 })).toBeVisible(); // Five nav tabs, one per label. for (const label of TAB_LABELS) { await expect(page.getByRole("link", { name: label, exact: true })).toBeVisible(); } // The current tab is marked active. await expect(page.getByRole("link", { name: "Schedule" })).toHaveAttribute( "aria-current", "page", ); // The schedule grid renders (unit D7): role columns and an instance row. await expect(page.getByText("Audio")).toBeVisible(); await expect(page.getByText("Livestream")).toBeVisible(); await expect(page.getByText("Slides")).toBeVisible(); }); test("shows the desktop rail inside the shell at desktop width", async ({ page }) => { await page.setViewportSize({ width: 1024, height: 768 }); await signInAs(page, `e2e-desktop-${Date.now()}@example.com`); await page.goto(`${BASE}/roster`); for (const label of TAB_LABELS) { await expect(page.getByRole("link", { name: label, exact: true })).toBeVisible(); } // Active tab follows the route. await expect(page.getByRole("link", { name: "Roster" })).toHaveAttribute( "aria-current", "page", ); }); test("redirects unauthenticated users away from the shell", async ({ page }) => { await page.setViewportSize({ width: 360, height: 780 }); await page.goto(`${BASE}/schedule`); await expect(page).toHaveURL(`${BASE}/login`); }); }); test.describe("health", () => { test("/api/health returns ok", async ({ request }) => { const res = await request.get(`${BASE}/api/health`); expect(res.ok()).toBe(true); const body = (await res.json()) as { status: string }; expect(body.status).toBe("ok"); }); });