Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ComposerPendingUserInputPanel.test.tsx

61 lines2.0 KB

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};
24​
25function renderPanel() {
26 return renderToStaticMarkup(
27 <ComposerPendingUserInputPanel
28 pendingUserInputs={[prompt]}
29 respondingRequestIds={[]}
30 answers={{}}
31 questionIndex={0}
32 onToggleOption={() => {}}
33 onAdvance={() => {}}
34 />,
35 );
37​
38describe("ComposerPendingUserInputPanel", () => {
39 it("renders the header as a disclosure control for the question body", () => {
40 const markup = renderPanel();
41​
42 const toggle = markup.match(/<button[^>]*data-pending-user-input-toggle="[^"]*"[^>]*>/)?.[0];
43 expect(toggle).toBeDefined();
44 expect(toggle).toContain('data-pending-user-input-toggle="expanded"');
45 expect(toggle).toContain('aria-expanded="true"');
46 expect(toggle).toContain('type="button"');
47​
48 const controlledId = toggle?.match(/aria-controls="([^"]+)"/)?.[1];
49 expect(controlledId).toBeDefined();
50 expect(markup).toMatch(new RegExp(`<div[^>]*\\sid="${controlledId}"`));
51 });
52​
53 it("starts expanded so the question and its options are visible", () => {
54 const markup = renderPanel();
55​
56 expect(markup).toContain("Approach");
57 expect(markup).toContain("Which approach should the migration take?");
58 expect(markup).toContain("Incremental");
59 expect(markup).toContain("Big bang");
60 });
61});