Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
91 lines
5.0 KiB
TypeScript
91 lines
5.0 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
import { test, expect, loginAs } from "./fixtures";
|
|
|
|
// Dashboard pages the palette leaves out on purpose: role home pages it reaches through
|
|
// "Dashboard", pages that only redirect or reuse another, and an older form nothing links to.
|
|
const NOT_IN_PALETTE = new Set([
|
|
"/dashboard/admin", "/dashboard/staff", "/dashboard/supervisor", // role homes ("Dashboard")
|
|
"/dashboard/admin/settings", // its tabs are listed one by one
|
|
"/dashboard/admin/whatsapp", "/dashboard/supervisor/sections", "/dashboard/admin/forms", // redirects / the same page
|
|
"/dashboard/admin/cashup/[id]", // one event's cashup, from Cashup
|
|
"/dashboard/supervisor/manual-registration", // the older manual form
|
|
"/dashboard/user/reset-password", // from My profile & security
|
|
]);
|
|
|
|
// Dashboard "Today" and "Waiting for you", and the Ctrl+K command palette (1.49.0).
|
|
test.describe("dashboard and command palette", () => {
|
|
test("the admin dashboard shows what's on today and what's waiting", async ({ page }) => {
|
|
await loginAs(page, "admin");
|
|
await page.goto("/dashboard/admin");
|
|
const today = page.getByTestId("today-panel");
|
|
await expect(today).toBeVisible();
|
|
// Seeded on today: the hidden kids church and serving Sunday.
|
|
await expect(today.getByTestId("today-events")).toContainText("E2E Serving Sunday");
|
|
await expect(today.getByText("Waiting for you")).toBeVisible();
|
|
});
|
|
|
|
test("Ctrl+K finds an event and opens it", async ({ page }) => {
|
|
await loginAs(page, "supervisor");
|
|
await page.goto("/dashboard/supervisor");
|
|
await expect(page.getByTestId("today-panel")).toBeVisible();
|
|
await page.keyboard.press("Control+k");
|
|
const dialog = page.getByRole("dialog", { name: "Go to or search" });
|
|
await expect(dialog).toBeVisible();
|
|
await dialog.getByRole("combobox", { name: "Search" }).fill("Paid Conference");
|
|
await expect(dialog.getByRole("option", { name: /E2E Paid Conference/ })).toBeVisible();
|
|
await page.keyboard.press("Enter");
|
|
await expect(page).toHaveURL(/\/dashboard\/supervisor\/events/);
|
|
await expect(page.getByRole("heading", { name: "Edit Event" })).toBeVisible();
|
|
await expect(page.getByPlaceholder("Event title")).toHaveValue("E2E Paid Conference");
|
|
});
|
|
|
|
test("the palette's actions and pages follow the role", async ({ page }) => {
|
|
await loginAs(page, "supervisor");
|
|
await page.goto("/dashboard/supervisor");
|
|
await page.getByRole("button", { name: /Search or jump to/ }).click();
|
|
const dialog = page.getByRole("dialog", { name: "Go to or search" });
|
|
await dialog.getByRole("combobox", { name: "Search" }).fill("new event");
|
|
await dialog.getByRole("option", { name: "New event" }).click();
|
|
await expect(page.getByRole("heading", { name: "New Event" })).toBeVisible();
|
|
|
|
// Staff don't get admin pages.
|
|
await loginAs(page, "staff");
|
|
await page.goto("/dashboard/staff");
|
|
// The shortcut listens once the signed-in user has loaded (the search button shows then).
|
|
await expect(page.getByRole("button", { name: /Search or jump to/ })).toBeVisible();
|
|
await page.keyboard.press("Control+k");
|
|
const staffDialog = page.getByRole("dialog", { name: "Go to or search" });
|
|
await staffDialog.getByRole("combobox", { name: "Search" }).fill("users");
|
|
await expect(staffDialog.getByRole("option", { name: "Users" })).toHaveCount(0);
|
|
await staffDialog.getByRole("combobox", { name: "Search" }).fill("scan");
|
|
await expect(staffDialog.getByRole("option", { name: "Scan tickets" })).toBeVisible();
|
|
});
|
|
|
|
test("the palette lists every report and every dashboard page", async ({ page }) => {
|
|
const root = path.join(__dirname, "..", "frontend", "src");
|
|
const palette = fs.readFileSync(path.join(root, "lib", "commandPages.ts"), "utf8");
|
|
const pages: string[] = [];
|
|
const walk = (dir: string) => {
|
|
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
if (e.isDirectory()) walk(path.join(dir, e.name));
|
|
else if (e.name === "page.tsx") pages.push("/" + path.relative(path.join(root, "app"), dir).split(path.sep).join("/"));
|
|
}
|
|
};
|
|
walk(path.join(root, "app", "dashboard"));
|
|
const missing = pages.filter(p => !NOT_IN_PALETTE.has(p) && !palette.includes(`href: "${p}"`) && !palette.includes(`href: "${p}?`));
|
|
expect(missing).toEqual([]);
|
|
|
|
// Reports come from the catalogue: one the old hand-made list didn't have.
|
|
await loginAs(page, "supervisor");
|
|
await page.goto("/dashboard/supervisor");
|
|
await expect(page.getByRole("button", { name: /Search or jump to/ })).toBeVisible();
|
|
await page.keyboard.press("Control+k");
|
|
const dialog = page.getByRole("dialog", { name: "Go to or search" });
|
|
await dialog.getByRole("combobox", { name: "Search" }).fill("medical");
|
|
await expect(dialog.getByRole("option", { name: /Report: Medical & emergency list/ })).toBeVisible();
|
|
await dialog.getByRole("combobox", { name: "Search" }).fill("profit");
|
|
await expect(dialog.getByRole("option", { name: /Report: Profit report/ })).toBeVisible();
|
|
});
|
|
});
|