import { renderToStaticMarkup } from "react-dom/server"; import { describe, expect, it, vi } from "vitest"; import { anyCapability, ok } from "./contracts"; import { HousekeepingPageShell } from "./page/housekeeping-page-shell"; import { HousekeepingPageState } from "./page/housekeeping-page-state"; import type { HousekeepingPreferences } from "./preferences/schema"; import { Favorites } from "./shell/favorites"; import { HousekeepingShell } from "./shell/housekeeping-shell"; import { OperationalInbox } from "./shell/operational-inbox"; import { WidgetGrid } from "./shell/widget-grid"; vi.mock("@/actions/housekeeping-search", () => ({ executeHousekeepingSearch: vi.fn(), })); const capability = anyCapability("admin.users.view"); const preferences: HousekeepingPreferences = { schemaVersion: 1, pinnedRouteIds: ["people.users.list"], pinnedCommandIds: [], shortcutOrder: ["people.users.list"], enabledOptionalWidgetIds: [], widgetOrder: ["people.queue"], }; const savePreferences = vi.fn(async (value: HousekeepingPreferences) => ok(value, "saved"), ); const shellLabels = { skipToContent: "Skip to content", primaryNavigation: "Primary navigation", contextualNavigation: "Context navigation", command: "Search", preview: "Preview", backToSite: "Back to site", operatorRank: "Rank 6", commandDeck: { placeholder: "Search", navigation: "Navigation", commands: "Commands", entities: "Entities", loading: "Loading", empty: "Empty", partial: "Partial", close: "Close", }, }; describe("housekeeping accessibility contract", () => { it("renders the shell and page with labelled landmarks and a coherent heading hierarchy", () => { const html = renderToStaticMarkup(

Inbox

, ); expect(html).toContain('data-housekeeping-root="true"'); expect(html).toContain("Rank 6"); expect(html).toContain("focus-visible:not-sr-only"); }); it.each([ ["loading", "status", "polite"], ["empty", "status", "polite"], ["partial", "status", "polite"], ["error", "alert", "assertive"], ["forbidden", "alert", "assertive"], ["ready", "status", "polite"], ] as const)( "gives the %s page state explicit semantic announcements", (state, role, live) => { const pageState = state === "partial" ? ( ) : ( ); const html = renderToStaticMarkup(pageState); expect(html).toContain(`data-page-state="${state}"`); expect(html).toContain(`role="${role}"`); expect(html).toContain(`aria-live="${live}"`); }, ); it("provides keyboard reorder instructions for favorites and widgets", () => { const favorites = renderToStaticMarkup( , ); const widgets = renderToStaticMarkup( , ); expect(favorites).toContain( 'id="housekeeping-favorites-reorder-instructions"', ); expect(favorites).toContain( 'aria-describedby="housekeeping-favorites-reorder-instructions"', ); expect(favorites).toContain(">Users<"); expect(favorites).not.toContain( ">pages.housekeeping.routes.people.users.list<", ); expect(widgets).toContain('id="housekeeping-widgets-reorder-instructions"'); expect(widgets).toContain( 'aria-describedby="housekeeping-widgets-reorder-instructions"', ); expect(widgets).toContain(">People queue<"); }); it("announces partial provider failures without exposing internal identifiers", () => { const html = renderToStaticMarkup( , ); expect(html).toContain('role="alert"'); expect(html).toContain('aria-live="assertive"'); expect(html).not.toContain("internal.provider"); expect(html).not.toContain("TIMEOUT"); expect(html).not.toContain("private-correlation"); }); });