The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 122 lines 4.09 KB
Raw
1 import { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
2 import { expect, it, vi } from "vite-plus/test";
3
4 vi.mock(import("../ChatMarkdown"), () => ({
5 default: (({ text }: { text: string }) => <p>{text}</p>) as never,
6 }));
7
8 import { render } from "../../../test/render";
9 import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
10
11 type Question = {
12 header: string;
13 question: string;
14 options: { label: string; description: string; preview?: string }[];
15 };
16
17 const renderPanel = (questions: Question[], questionIndex = 0) =>
18 render(
19 <ComposerPendingUserInputPanel
20 pendingUserInputs={[
21 {
22 requestId: RuntimeRequestId.make("question-direction"),
23 createdAt: "2026-10-23T00:00:00.000Z",
24 dismissible: false,
25 responseCapability: "live",
26 questions: questions.map((question, index) => ({
27 ...question,
28 id: `question-${index}`,
29 multiSelect: false,
30 })),
31 },
32 ]}
33 cwd={undefined}
34 threadRef={{ environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") }}
35 respondingRequestIds={[]}
36 answers={{}}
37 questionIndex={questionIndex}
38 onToggleOption={() => {}}
39 onAdvance={() => {}}
40 onDismiss={() => {}}
41 />,
42 );
43
44 it("reads a mostly Hebrew question set right to left", async () => {
45 await using screen = await renderPanel([
46 {
47 header: "גישה",
48 question: "איך לבצע את המיגרציה?",
49 options: [
50 {
51 label: "React Server Components בכל המסכים של האפליקציה",
52 description: "מסך אחד בכל פעם",
53 },
54 { label: "Keep it on React 18", description: "English only" },
55 ],
56 },
57 ]);
58
59 const text = (value: string) => screen.getByText(value, { exact: true });
60 await expect.element(text("גישה")).toHaveStyle({ direction: "rtl" });
61 await expect
62 .element(text("React Server Components בכל המסכים של האפליקציה"))
63 .toHaveStyle({ direction: "rtl" });
64 await expect.element(text("מסך אחד בכל פעם")).toHaveStyle({ direction: "rtl" });
65 await expect
66 .element(screen.getByRole("button", { name: /React Server/ }))
67 .toHaveStyle({ direction: "rtl" });
68 await expect.element(text("Keep it on React 18")).toHaveStyle({ direction: "ltr" });
69
70 await screen.getByTitle("Hide the question and its options").click();
71 await expect.element(text("איך לבצע את המיגרציה?")).toHaveStyle({ direction: "rtl" });
72 });
73
74 it("keeps one direction for the whole set when a single question is Hebrew", async () => {
75 await using screen = await renderPanel(
76 [
77 {
78 header: "Migration",
79 question: "How should we move to React Server Components?",
80 options: [
81 { label: "Screen by screen", description: "Lower risk, each step tested alone." },
82 { label: "Server Actions for all forms first", description: "Then the rest." },
83 ],
84 },
85 {
86 header: "גרסה",
87 question: "בחר גרסה",
88 options: [{ label: "גרסה 3 (חדשה!)", description: "!!!" }],
89 },
90 ],
91 1,
92 );
93
94 await expect
95 .element(screen.getByRole("button", { name: /גרסה 3/ }))
96 .toHaveStyle({ direction: "ltr" });
97 await expect
98 .element(screen.getByText("גרסה 3 (חדשה!)", { exact: true }))
99 .toHaveStyle({ direction: "rtl" });
100 });
101
102 it("shows an option's preview so the user can see what they are approving", async () => {
103 await using screen = await renderPanel([
104 {
105 header: "Issue",
106 question: "Approve this issue title and body?",
107 options: [
108 {
109 label: "Approve",
110 description: "File it as drafted.",
111 preview: "Title: Login fails\n\nBody: A quote in the password breaks login.",
112 },
113 { label: "Cancel", description: "Do not file it." },
114 ],
115 },
116 ]);
117
118 await screen.getByRole("button", { name: /Approve/ }).hover();
119 await expect
120 .element(screen.getByText("A quote in the password breaks login.", { exact: false }))
121 .toBeVisible();
122 });