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

main
tsx 82 lines 2.27 KB
Raw
1 import { SourceControlProviderKind } from "@t3tools/contracts";
2 import * as Option from "effect/Option";
3 import { expect, it, vi } from "vite-plus/test";
4 import { page, userEvent } from "vite-plus/test/browser";
5
6 import { act, render } from "../../test/render";
7 import { PublishRepositoryDialog } from "./GitActionsControl";
8
9 const publish = vi.hoisted(() => ({ run: vi.fn() }));
10
11 vi.mock("~/state/query", () => ({
12 useEnvironmentQuery: () => ({
13 data: {
14 versionControlSystems: [],
15 sourceControlProviders: [
16 {
17 kind: SourceControlProviderKind.make("github"),
18 label: "GitHub",
19 status: "available",
20 version: Option.none(),
21 installHint: "Install gh",
22 detail: Option.none(),
23 auth: {
24 status: "authenticated",
25 account: Option.none(),
26 host: Option.none(),
27 detail: Option.none(),
28 },
29 },
30 ],
31 },
32 }),
33 }));
34
35 vi.mock("~/state/sourceControlActions", () => ({
36 useGitStackedAction: vi.fn(),
37 useSourceControlActionRunning: vi.fn(),
38 useVcsInitAction: vi.fn(),
39 useVcsPullAction: vi.fn(),
40 useSourceControlPublishRepositoryAction: () => ({
41 isAllowed: true,
42 isPending: false,
43 run: publish.run,
44 }),
45 }));
46
47 function setup() {
48 publish.run.mockReset();
49 publish.run.mockReturnValue(new Promise(() => {}));
50 }
51
52 it("keeps composition Enter in the repository path from publishing", async () => {
53 setup();
54 await using _screen = await render(
55 <PublishRepositoryDialog
56 open
57 onOpenChange={() => {}}
58 environmentId={null}
59 threadRef={null}
60 gitCwd="/repo"
61 offeredProviders={undefined}
62 />,
63 );
64 await page.getByRole("button", { name: "Next" }).click();
65 const path = page.getByRole("textbox", { name: "Repository" });
66 await path.fill("octo/repo");
67
68 for (const nativeEvent of [{ isComposing: true }, { keyCode: 229 }]) {
69 const event = new KeyboardEvent("keydown", {
70 key: "Enter",
71 ...nativeEvent,
72 bubbles: true,
73 cancelable: true,
74 });
75 await act(() => path.element().dispatchEvent(event));
76 expect(publish.run).not.toHaveBeenCalled();
77 expect(event.defaultPrevented).toBe(false);
78 }
79
80 await userEvent.keyboard("{Enter}");
81 expect(publish.run).toHaveBeenCalledOnce();
82 });