6982a8040d
Server-component schedule page backed by a pure data layer (src/db/grid.ts): gridForWeek() returns positions + instances (->slots->assignments), and defaultWeekStart() defaults to the earliest upcoming published instance so a seeded DB shows data on first load. Week nav via ?week=YYYY-MM-DD (server rendered, no client state). Fixes two latent bugs that kept the grid empty/incorrect: - tz: weekdayInTz()/nextSundaysInTz() built Date.UTC(y,mo-1,d) from a LOCAL date string and read its weekday; for America/New_York (UTC-5) UTC midnight lands the previous evening, so the seed materialized instances on Mondays and the default week was off by one. weekdayInTz now builds the local-midnight instant via utcOffsetMs; nextSundaysInTz uses weekdayInTz + addDaysISO. - grid: occursOn (date mode) was run through dateInTimezone(), reinterpreting the UTC instant as wall-clock and shifting a day early; now extracts the UTC calendar date directly (occursOnISO). - schedule-grid: <table className=... collapse ...> set visibility: collapse (Tailwind 'collapse'), hiding the whole grid server-rendered-but-invisible; changed to border-collapse. E2E: new schedule-grid.spec.ts + shell.spec.ts grid assertion. Full suite green: tsc, eslint, 178 unit tests, next build, 6/6 Playwright.
79 lines
2.9 KiB
TypeScript
79 lines
2.9 KiB
TypeScript
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");
|
|
});
|
|
});
|