core/workbench-ui/src/preview/PreviewPage.test.tsx
Shay e89463a975
feat(workbench-ui): design system v1 scaffold (ADR-0162 Branch 1) (#295)
* feat(workbench-ui): design system v1 scaffold

* fix(workbench): close R1 (GroundingSource enum coverage) + R4 (digest test)

R1 — Promote GroundingSource to a typed Literal in core/epistemic_state.py
so it has the same single-source-of-truth shape as ReviewState.  The
existing epistemic_state_for_grounding_source() function already
enumerates the six labels (pack, teaching, vault, partial, oov, none);
this codifies them.

scripts/dump-enums.py now snapshots GroundingSource via the existing
literal_values helper.  workbench-ui's enumCoverage.test.ts gains a
fourth assertion that the badge mapping matches the Python source
1:1.  Adding a grounding-source value on the Python side without
updating the badge fails the build-time test loud — same discipline
as the other three enums.

R4 — Add an explicit DigestBadge test to StableJsonViewer.test.tsx:
asserts the badge text matches the SHA-256 prefix of the source bytes,
and clicking the badge copies the FULL digest (not the truncated
prefix).  Recomputes the expected digest via crypto.subtle to avoid
hard-coding a hex string that could drift.

R2 (component-level reduced-motion enforcement), R3 (EmptyState
copy-CLI affordance), and R5 (`uv run core` packaging paper cut) are
deferred — R2/R3 become meaningful with W-027/W-029, R5 is a
packaging-layer concern outside this PR's scope.

Validation:
- pnpm test: 19 passed (was 17, +1 enum coverage, +1 digest test)
- pnpm build: clean
- pnpm test:enum-coverage: 4 passed
- core test --suite smoke -q: 67 passed
2026-05-26 11:33:27 -07:00

35 lines
1.6 KiB
TypeScript

import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import { PreviewPage } from "./PreviewPage";
describe("/preview", () => {
it("renders every primitive with network unavailable", () => {
vi.stubGlobal("fetch", vi.fn(() => Promise.reject(new Error("network blocked"))));
render(<PreviewPage />);
expect(screen.getByRole("heading", { name: "CORE Workbench Design System v1" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Primitives" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Badges" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "States" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Stable JSON Viewer" })).toBeInTheDocument();
expect(fetch).not.toHaveBeenCalled();
});
it("opens CommandPalette with mod+k and closes overlays with Escape", async () => {
const user = userEvent.setup();
render(<PreviewPage />);
await user.keyboard("{Control>}k{/Control}");
expect(screen.getByRole("dialog", { name: "Command Palette" })).toBeInTheDocument();
await user.keyboard("{Escape}");
expect(screen.queryByRole("dialog", { name: "Command Palette" })).not.toBeInTheDocument();
});
it("keeps tab order in DOM order for preview actions", async () => {
const user = userEvent.setup();
render(<PreviewPage />);
await user.tab();
expect(screen.getByRole("button", { name: "Primary action" })).toHaveFocus();
await user.tab();
expect(screen.getByRole("button", { name: "Quiet action" })).toHaveFocus();
});
});