D7: read-only schedule grid UI (rows=instances, cols=positions, week nav)
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.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
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
|
||||
// "<weekday> · <service name>", 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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user