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

ComposerPendingUserInputPanel.test.tsx

71 lines2.4 KB

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