Open History to see the last commit
1import { EnvironmentId, ProjectId, type PullRequestReviewThread } from "@t3tools/contracts";
2import { expect, it, vi } from "vite-plus/test";
3import { userEvent } from "vite-plus/test/browser";
4
5import { registerCommands } from "~/shortcuts/dispatcher";
6import { act, render } from "../../../test/render";
7import { ReviewThreadCard } from "./PullRequestReviewAnnotation";
8
9const thread: PullRequestReviewThread = {
10 id: "thread",
11 path: "a.ts",
12 line: 3,
13 side: "right",
14 isResolved: false,
15 isOutdated: false,
16 comments: [
17 {
18 id: "comment",
19 author: { login: "reviewer", name: null, avatarUrl: null },
20 body: "Rename this.",
21 createdAt: "2026-09-01T00:00:00Z",
22 url: null,
23 },
24 ],
25};
26
27it("leaves IME keys in a review reply to the composition", async () => {
28 const onReply = vi.fn(async () => true);
29 await using screen = await render(
30 <ReviewThreadCard
31 thread={thread}
32 workspaceRoot="/workspace"
33 canReply
34 canResolve={false}
35 canReact={false}
36 environmentId={EnvironmentId.make("environment")}
37 reference={{ projectId: ProjectId.make("project"), repository: "owner/repo", number: 1 }}
38 completionScope={null}
39 pending={false}
40 onReply={onReply}
41 onLoadMore={async () => null}
42 canEditComment={() => false}
43 onEditComment={async () => false}
44 onToggleResolved={() => {}}
45 onReacted={() => {}}
46 />,
47 );
48 const heard: Array<{ key: string; consumed: boolean }> = [];
49 using _observer = {
50 [Symbol.dispose]: registerCommands(
51 {},
52 { observe: (event, consumed) => heard.push({ key: event.key, consumed }) },
53 ),
54 };
55 const reply = () => screen.getByRole("textbox", { name: "Reply to this conversation" });
56 await screen.getByRole("button", { name: "Reply", exact: true }).click();
57 await reply().fill("Draft");
58
59 for (const composing of [{ isComposing: true }, { keyCode: 229 }]) {
60 for (const keys of [
61 { key: "Escape" },
62 { key: "Enter", ctrlKey: true },
63 { key: "Enter", metaKey: true },
64 ]) {
65 const label = JSON.stringify({ ...keys, ...composing });
66 const event = new KeyboardEvent("keydown", {
67 ...keys,
68 ...composing,
69 bubbles: true,
70 cancelable: true,
71 });
72 await act(() => reply().element().dispatchEvent(event));
73 expect(event.defaultPrevented, label).toBe(false);
74 // The pull requests page leaves on an Escape nothing consumed.
75 expect(heard, label).toEqual([]);
76 await expect.element(reply()).toHaveValue("Draft");
77 }
78 }
79 expect(onReply).not.toHaveBeenCalled();
80
81 await userEvent.keyboard("{Escape}");
82 await expect.element(reply()).not.toBeInTheDocument();
83 expect(heard).toEqual([{ key: "Escape", consumed: true }]);
84
85 await screen.getByRole("button", { name: "Reply", exact: true }).click();
86 await reply().fill("Draft");
87 await userEvent.keyboard("{Control>}{Enter}{/Control}");
88 expect(onReply).toHaveBeenCalledExactlyOnceWith("Draft");
89});