Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions e2e/smoke/bookings-touch.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect, test } from "@playwright/test";

/** Bookings on a coarse pointer (spec 002, quality bar): its tags stay pills, one line high. Owned by bookings. */
test.describe("pills on a coarse pointer", () => {
test.use({ hasTouch: true, isMobile: true });

test("booking tags stay on one line in the list", async ({ page, context, baseURL }) => {
await context.addCookies([{ name: "locale", value: "en", url: baseURL }]);
await page.goto("/dashboard/bookings");
// The room loads lazily (a WebGL engine in its own chunk): a table plate on screen means the page is hydrated, so
// the List radio answers. The wait is generous because a loaded CI machine renders the scene in software.
await expect(page.getByRole("button", { name: /^S3, \d+ seats/ })).toBeVisible({ timeout: 30_000 });
const list = page.getByRole("radiogroup", { name: "Reservations view" }).getByRole("radio", { name: "List" });
await list.click();
await expect(list).toBeChecked();
const tags = page.getByRole("list", { name: "Notes" }).locator('[data-slot="badge"]');
await expect(tags.first()).toBeVisible();
const heights = await tags.evaluateAll((badges) => badges.map((badge) => badge.getBoundingClientRect().height));
expect(Math.max(...heights)).toBeLessThanOrEqual(24);
});
});
9 changes: 6 additions & 3 deletions e2e/smoke/dead-clicks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, type Page, test } from "@playwright/test";

import { PAGE_ROUTES } from "./routes";
import { mkdirSync, readdirSync, readFileSync, renameSync, rmdirSync, writeFileSync } from "node:fs";
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmdirSync, writeFileSync } from "node:fs";
import path from "node:path";

/**
Expand Down Expand Up @@ -718,9 +718,10 @@ for (const route of PAGE_ROUTES) {

/**
* The only controls the sweep may skip, each with the reason it cannot be observed (plan 003, G1). A new
* `data-inert-reason` fails here until it is reviewed and listed.
* `data-inert-reason` fails here until it is reviewed and listed. An exception whose file is gone, because its
* module is not installed, is not expected in the source.
*/
const INERT_EXCEPTIONS = [
const LISTED_EXCEPTIONS = [
[
"src/app/(main)/dashboard/(examples)/patient-monitoring/_components/monitoring-provider.tsx",
"A tooltip target: the status opens on hover and focus, not on press.",
Expand All @@ -739,6 +740,8 @@ const INERT_EXCEPTIONS = [
],
] as const;

const INERT_EXCEPTIONS = LISTED_EXCEPTIONS.filter(([file]) => existsSync(path.join(process.cwd(), file)));

const sourceFiles = (dir: string): string[] =>
readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const full = path.join(dir, entry.name);
Expand Down
8 changes: 7 additions & 1 deletion e2e/smoke/hydration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { expect, test } from "@playwright/test";

import { PAGE_ROUTES } from "./routes";

/**
* Window rule: nothing modal before hydration. With JavaScript off the browser shows exactly the server HTML, which
* must hold no open dialog, sheet or drawer.
*/

test.use({ javaScriptEnabled: false });

for (const route of ["/", "/dashboard/default", "/dashboard/bookings", "/dashboard/kit"]) {
const ROUTES = ["/", "/dashboard/default", "/dashboard/bookings", "/dashboard/kit"].filter((route) =>
PAGE_ROUTES.includes(route),
);

for (const route of ROUTES) {
test(`the server HTML of ${route} holds no open overlay`, async ({ page }) => {
await page.goto(route);

Expand Down
3 changes: 2 additions & 1 deletion e2e/smoke/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ test.describe("business settings", () => {
});

test("open from the account menu", async ({ page }) => {
await page.goto("/dashboard/customers");
// From a page no module owns, so the walk never removes it and the menu really navigates.
await page.goto("/dashboard/default");
await page.getByRole("button", { name: /Account: / }).click();
await page.getByRole("menuitem", { name: "Business settings" }).click();

Expand Down
35 changes: 13 additions & 22 deletions e2e/smoke/touch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect, type Page, test } from "@playwright/test";

import { PAGE_ROUTES } from "./routes";

/**
* Touch-target bar (spec 002, quality bar): on a coarse pointer every visible interactive primitive offers at least
* 44 × 44 px, either by its own box or, for glyph controls and the segments of a glass capsule, by its invisible
Expand All @@ -26,15 +28,23 @@ const GLASS_SEGMENT = '.liquid-glass[data-slot="toggle-group"] > [data-slot="tog
/** The rail's trigger buttons keep their drawn size on touch, as on the desktop, and offer the hit area instead. */
const RAIL_TRIGGER =
'[data-slot="app-rail"] > :is([data-slot="tooltip-trigger"], [data-slot="popover-trigger"], [data-slot="dropdown-menu-trigger"])';
const ROUTES = ["/", "/dashboard/default", "/dashboard/invoice", "/dashboard/bookings", "/dashboard/customers"];
const CAPSULE_ROUTES = [
/** The routes the sweeps visit, less those of a module that is not installed (ADR 0017). */
const installed = (routes: readonly string[]) => routes.filter((route) => PAGE_ROUTES.includes(route));
const ROUTES = installed([
"/",
"/dashboard/default",
"/dashboard/invoice",
"/dashboard/bookings",
"/dashboard/customers",
]);
const CAPSULE_ROUTES = installed([
"/dashboard/default",
"/dashboard/bookings",
"/dashboard/customers",
"/dashboard/crm",
"/dashboard/analytics",
"/dashboard/calendar",
];
]);

/** Smallest target among visible elements: own box for rows, ::after box for glyphs and glass segments. */
const smallestTarget = (page: Page, rows: string[], glyphs: string[]) =>
Expand Down Expand Up @@ -130,25 +140,6 @@ test.describe("the rail on a coarse pointer", () => {
});
});

test.describe("pills on a coarse pointer", () => {
test.use({ hasTouch: true, isMobile: true });

test("booking tags stay on one line in the list", async ({ page, context, baseURL }) => {
await context.addCookies([{ name: "locale", value: "en", url: baseURL }]);
await page.goto("/dashboard/bookings");
// The room loads lazily (a WebGL engine in its own chunk): a table plate on screen means the page is hydrated, so
// the List radio answers. The wait is generous because a loaded CI machine renders the scene in software.
await expect(page.getByRole("button", { name: /^S3, \d+ seats/ })).toBeVisible({ timeout: 30_000 });
const list = page.getByRole("radiogroup", { name: "Reservations view" }).getByRole("radio", { name: "List" });
await list.click();
await expect(list).toBeChecked();
const tags = page.getByRole("list", { name: "Notes" }).locator('[data-slot="badge"]');
await expect(tags.first()).toBeVisible();
const heights = await tags.evaluateAll((badges) => badges.map((badge) => badge.getBoundingClientRect().height));
expect(Math.max(...heights)).toBeLessThanOrEqual(24);
});
});

test.describe("compact controls on a fine pointer", () => {
test("keeps the desktop icon buttons at their drawn size", async ({ page }) => {
await page.goto("/dashboard/default");
Expand Down
69 changes: 48 additions & 21 deletions scripts/generate-modules.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeAll, describe, expect, it } from "vitest";

import { VIEW_RENDERERS } from "@/config/modules.client.generated";
import { MODULES } from "@/config/modules.generated";
import { MODULE_GRAPH, MODULES } from "@/config/modules.generated";
import { MODULE_SERVERS } from "@/config/modules.server.generated";
import { compositionProblems, type ModuleServer } from "@/core/module";

Expand All @@ -20,6 +20,39 @@ import { join } from "node:path";

let generated: Generated;

/**
* Census C0 (ADR 0017): what each of the first six modules required when the import graph was first counted. A module
* that is not installed has no row, and a target that is not installed is dropped from the rows that name it, so the
* census still holds after a removal.
*/
const C0: Readonly<Record<string, readonly string[]>> = {
bookings: ["customers", "resources"],
catalog: [],
customers: [],
notifications: ["bookings"],
resources: [],
staff: [],
};

const c0Of = (installed: readonly string[]) =>
Object.fromEntries(
Object.entries(C0)
.filter(([id]) => installed.includes(id))
.map(([id, targets]) => [id, targets.filter((target) => installed.includes(target))]),
);

/** The graph's rows for the modules the census knows. */
const censusOf = (graph: Readonly<Record<string, readonly string[]>>) =>
Object.fromEntries(Object.entries(graph).filter(([id]) => id in C0));

/** Each installed module, with the refusal that removing it must cause: one line per module that imports it. */
const removals = Object.keys(MODULE_GRAPH).map((removed) => ({
removed,
refusals: Object.entries(MODULE_GRAPH)
.filter(([, targets]) => (targets as readonly string[]).includes(removed))
.map(([id]) => `${id} requires ${removed}; restore src/modules/${removed} or remove ${id}`),
}));

beforeAll(async () => {
generated = await generate(ROOT);
}, 20_000);
Expand Down Expand Up @@ -48,24 +81,14 @@ describe("the generated module list (ADR 0017 §5)", () => {
});

it("requires what the import graph shows (ADR 0017's first test, against census C0)", () => {
expect(generated.graph).toEqual({
bookings: ["customers", "resources"],
catalog: [],
customers: [],
inventory: [],
notifications: ["bookings"],
parties: [],
resources: [],
staff: [],
});
const installed = Object.keys(generated.graph);
expect(censusOf(generated.graph)).toEqual(c0Of(installed));
});
});

describe("removing a module from the installed list (ADR 0017 §5, §9)", () => {
it("refuses a module that imports the one removed, and says nothing else", () => {
expect(without("bookings")()).toEqual([
"notifications requires bookings; restore src/modules/bookings or remove notifications",
]);
it.each(removals)("refuses the modules that import $removed, and says nothing else", ({ removed, refusals }) => {
expect(without(removed)()).toEqual(refusals);
});

it("composes without the catalog (walk W1)", () => {
Expand Down Expand Up @@ -100,14 +123,18 @@ describe("the UI export a folder names", () => {
describe("the generated client map (ADR 0017 §5)", () => {
const text = () => generated.files?.[MODULE_UIS_PATH] ?? "";

it("imports the ui.ts of the modules that have one", () => {
expect(text()).toContain('import { catalogModuleUi } from "@/modules/catalog/ui";');
expect(text()).toContain('import { inventoryModuleUi } from "@/modules/inventory/ui";');
// From the installed modules' folders, so removing one leaves these cases standing (ADR 0017 §7).
const withUiFile = MODULES.map(({ id }) => id).filter((id) => existsSync(join(ROOT, "src/modules", id, "ui.ts")));
const withUiFolder = MODULES.map(({ id }) => id).filter(
(id) => existsSync(join(ROOT, "src/modules", id, "ui")) && !withUiFile.includes(id),
);

it.each(withUiFile)("imports the ui.ts of %s", (id) => {
expect(text()).toContain(`import { ${uiExportOf(id)} } from "@/modules/${id}/ui";`);
});

it("leaves out a module whose ui is a folder of shared components, not a ui.ts (customers)", () => {
expect(existsSync(join(ROOT, "src/modules/customers/ui"))).toBe(true);
expect(text()).not.toContain("customers");
it.each(withUiFolder)("leaves out %s, whose ui is a folder of shared components, not a ui.ts", (id) => {
expect(text()).not.toContain(`@/modules/${id}`);
});

const declared = MODULES.flatMap((module) => (module.views ?? []).map(({ id }) => id)).sort();
Expand Down
27 changes: 17 additions & 10 deletions src/app/(main)/dashboard/_components/nav-model.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { describe, expect, it } from "vitest";

import { VERTICALS } from "@/config/vertical";

import { examplesNav } from "../(examples)/_nav/examples-nav";
import { buildShellNav, type NavData } from "./nav-model";

Expand All @@ -8,11 +10,17 @@ const text = Object.fromEntries(
) as Parameters<typeof buildShellNav>[1]["text"];
const examples = { groups: examplesNav, text };

/** The fixture is the salon's own nav, so a module that leaves the preset leaves the fixture with it. */
const presetNav = VERTICALS.salon.nav;
const shown = presetNav.filter((entry) => entry.placement === "area").slice(0, 2);
const shownIds = shown.map((entry) => entry.id);
const shownTitles = shownIds.map((id) => `label:${id}`);

const data = (overrides: Partial<NavData>): NavData => ({
presetId: "salon",
visibleIds: ["home", "bookings"],
labels: { home: "Home", bookings: "Appointments" },
groupLabels: { overview: "Overview", operations: "Operations" },
visibleIds: shownIds,
labels: Object.fromEntries(presetNav.map((entry) => [entry.id, `label:${entry.id}`])),
groupLabels: Object.fromEntries(presetNav.map((entry) => [entry.group, `group:${entry.group}`])),
showExamples: false,
...overrides,
});
Expand All @@ -21,22 +29,21 @@ const titles = (items: readonly { title: string }[]) => items.map((item) => item

describe("buildShellNav", () => {
it("lists the preset areas with the labels the server resolved", () => {
expect(titles(buildShellNav(data({}), examples).top)).toEqual(["Home", "Appointments"]);
expect(titles(buildShellNav(data({}), examples).top)).toEqual(shownTitles);
});

it.each([
["only home", ["home"], ["Home"]],
["only the first area", shownIds.slice(0, 1), shownTitles.slice(0, 1)],
["nothing", [], []],
["an id the preset does not define", ["staff"], []],
])("hides entries that are not visible: %s", (_name, visibleIds, expected) => {
expect(titles(buildShellNav(data({ visibleIds }), examples).top)).toEqual(expected);
});

it("groups the preset entries for the search dialog", () => {
expect(buildShellNav(data({}), examples).searchGroups.map((group) => [group.id, group.label])).toEqual([
["overview", "Overview"],
["operations", "Operations"],
]);
expect(buildShellNav(data({}), examples).searchGroups.map((group) => [group.id, group.label])).toEqual(
[...new Set(shown.map((entry) => entry.group))].map((group) => [group, `group:${group}`]),
);
});

it("leaves the showcase screens out unless asked", () => {
Expand All @@ -45,7 +52,7 @@ describe("buildShellNav", () => {

it("puts the preset first and the showcase screens after it", () => {
const nav = buildShellNav(data({ showExamples: true }), examples);
expect([titles(nav.top).slice(0, 2), nav.top.length > 2]).toEqual([["Home", "Appointments"], true]);
expect([titles(nav.top).slice(0, shown.length), nav.top.length > shown.length]).toEqual([shownTitles, true]);
});

it.each([
Expand Down
20 changes: 20 additions & 0 deletions src/config/adapter-contract.testkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { describe, expect, it } from "vitest";

import { DEFAULT_ROLES, permissionsOf } from "@/core/access";
import { type Actor, type Adapter, createClient } from "@/core/client";
import { fixedClock } from "@/core/clock";
import { createMockAdapter, createSessionStore } from "@/core/mock";

import { CATALOG } from "./catalog";
import { DEMO, type DemoSeed, MOCK_HANDLERS, settingsFor } from "./demo-kernel";
import { VERTICALS, type VerticalId } from "./vertical";

const verticalIds = Object.keys(VERTICALS) as VerticalId[];
Expand Down Expand Up @@ -130,6 +133,23 @@ export const ownerOf = (vertical: VerticalId): Actor => ({
permissions: permissionsOf(DEFAULT_ROLES[0], CATALOG, VERTICALS[vertical].modules),
});

/** A session on the preset's seed without the given collections, as if their modules were not installed (ADR 0017 §3). */
export function sessionWithout(vertical: VerticalId, absent: ReadonlySet<string>) {
const seed = Object.fromEntries(Object.entries(DEMO[vertical].seed).filter(([name]) => !absent.has(name)));
const adapter = createMockAdapter({
handlers: MOCK_HANDLERS,
// The seed lacks the absent modules' collections, which an installed composition's types require: the point here.
store: createSessionStore(seed as unknown as DemoSeed),
sessionId: crypto.randomUUID(),
clock: fixedClock(DEMO[vertical].clock),
settings: settingsFor(vertical),
});
return {
adapter,
client: createClient(CATALOG, adapter, { ...quiet, mode: "production", actor: ownerOf(vertical) }),
};
}

/** Everything a visitor can read in a preset, as one value, so two moments of a session can be compared. */
const stateOf = (client: ReturnType<typeof createClient>, ids: readonly string[], vertical: VerticalId) =>
Promise.all(ids.map((id) => client.call(id, inputFor(id, vertical))));
Expand Down
Loading
Loading