A4: app shell (layout, nav, tokens, error/empty states, /api/health)
Fixes the A4 blocker: /api/dev/complete now establishes the Auth.js session. Root cause was UntrustedHost (trustHost defaulted false in pnpm start / production because setEnvDefaults derives it from AUTH_URL, not NEXTAUTH_URL, and assertConfig checks it before that default applies). Added trustHost: true to the auth config; rebuilt. Complete response now sets authjs.session-token, /schedule returns 200, and all 4 e2e shell tests pass. Also ignores test-results/ artifacts.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
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",
|
||||
);
|
||||
|
||||
// Empty state renders inside the shell.
|
||||
await expect(page.getByText("Nothing scheduled yet")).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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user