Open History to see the last commit
1import { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
2import { expect, it, vi } from "vite-plus/test";
3
4vi.mock(import("../ChatMarkdown"), () => ({
5 default: (({ text }: { text: string }) => <p>{text}</p>) as never,
6}));
7
8import { render } from "../../../test/render";
9import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
10
11type Question = {
12 header: string;
13 question: string;
14 options: { label: string; description: string }[];
15};
16
17const 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
44it("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
74it("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});