Open History to see the last commit
1import { ApprovalRequestId } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4
5import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
6import type { PendingUserInput } from "../../session-logic";
7
8const prompt: PendingUserInput = {
9 requestId: ApprovalRequestId.make("request-1"),
10 createdAt: "2026-08-15T00:00:00.000Z",
11 questions: [
12 {
13 id: "question-1",
14 header: "Approach",
15 question: "Which approach should the migration take?",
16 options: [
17 { label: "Incremental", description: "Move one module at a time" },
18 { label: "Big bang", description: "Move everything in one release" },
19 ],
20 multiSelect: false,
21 },
22 ],
23 dismissible: true,
24};
25
26function renderPanel(pendingUserInput: PendingUserInput = prompt) {
27 return renderToStaticMarkup(
28 <ComposerPendingUserInputPanel
29 pendingUserInputs={[pendingUserInput]}
30 respondingRequestIds={[]}
31 answers={{}}
32 questionIndex={0}
33 onToggleOption={() => {}}
34 onAdvance={() => {}}
35 onDismiss={() => {}}
36 />,
37 );
38}
39
40describe("ComposerPendingUserInputPanel", () => {
41 it("renders the header as a disclosure control for the question body", () => {
42 const markup = renderPanel();
43
44 const toggle = markup.match(/<button[^>]*data-pending-user-input-toggle="[^"]*"[^>]*>/)?.[0];
45 expect(toggle).toBeDefined();
46 expect(toggle).toContain('data-pending-user-input-toggle="expanded"');
47 expect(toggle).toContain('aria-expanded="true"');
48 expect(toggle).toContain('type="button"');
49
50 const controlledId = toggle?.match(/aria-controls="([^"]+)"/)?.[1];
51 expect(controlledId).toBeDefined();
52 expect(markup).toMatch(new RegExp(`<div[^>]*\\sid="${controlledId}"`));
53 });
54
55 it("offers dismiss only for async questions", () => {
56 expect(renderPanel()).toContain("data-pending-user-input-dismiss");
57 expect(renderPanel({ ...prompt, dismissible: false })).not.toContain(
58 "data-pending-user-input-dismiss",
59 );
60 });
61
62 it("starts expanded so the question and its options are visible", () => {
63 const markup = renderPanel();
64
65 expect(markup).toContain("Approach");
66 expect(markup).toContain("Which approach should the migration take?");
67 expect(markup).toContain("Incremental");
68 expect(markup).toContain("Big bang");
69 });
70});