Open History to see the last commit
1import "~/index.css";
2
3import { act } from "react";
4import { createRoot } from "react-dom/client";
5import { expect, it, vi } from "vite-plus/test";
6import { page, userEvent } from "vite-plus/test/browser";
7
8vi.mock("~/hooks/useSettings", () => ({
9 useEnvironmentIdentificationMode: () => "none",
10}));
11vi.mock("../SidebarStageBackdrop", () => ({
12 StageBackdropButtonArt: () => null,
13 useSidebarStageBackdropVariant: () => null,
14}));
15
16import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
17
18it("opens implementation actions with a mouse while the composer is resting", async () => {
19 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
20 const container = document.createElement("div");
21 document.body.append(container);
22 const root = createRoot(container);
23 const onImplementPlanInNewThread = vi.fn();
24
25 try {
26 await act(async () => {
27 root.render(
28 <ComposerPrimaryActions
29 compact={false}
30 canOperateThread
31 pendingAction={null}
32 isRunning={false}
33 canInterrupt={false}
34 showPlanFollowUpPrompt
35 promptHasText={false}
36 isSendBusy={false}
37 sendDisabledReason={null}
38 isConnecting={false}
39 isEnvironmentUnavailable={false}
40 isPreparingWorktree={false}
41 hasSendableContent={false}
42 preserveComposerFocusOnPointerDown
43 onPreviousPendingQuestion={() => {}}
44 onInterrupt={() => {}}
45 onImplementPlanInNewThread={onImplementPlanInNewThread}
46 />,
47 );
48 });
49
50 await act(async () => {
51 await userEvent.click(page.getByRole("button", { name: "Implementation actions" }));
52 });
53 const item = page.getByRole("menuitem", { name: "Implement in a new thread" });
54 await expect.element(item).toBeVisible();
55 await act(async () => {
56 await userEvent.click(item);
57 });
58 expect(onImplementPlanInNewThread).toHaveBeenCalledTimes(1);
59 } finally {
60 await act(async () => root.unmount());
61 container.remove();
62 vi.unstubAllGlobals();
63 }
64});