Skip to content

Commit 13522fe

Browse files
fix(web): open implementation menu with composer focus preserved
1 parent 5d5f95d commit 13522fe

3 files changed

Lines changed: 67 additions & 96 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import "~/index.css";
2+
3+
import { act } from "react";
4+
import { createRoot } from "react-dom/client";
5+
import { expect, it, vi } from "vite-plus/test";
6+
import { page, userEvent } from "vite-plus/test/browser";
7+
8+
vi.mock("~/hooks/useSettings", () => ({
9+
useEnvironmentIdentificationMode: () => "none",
10+
}));
11+
vi.mock("../SidebarStageBackdrop", () => ({
12+
StageBackdropButtonArt: () => null,
13+
useSidebarStageBackdropVariant: () => null,
14+
}));
15+
16+
import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
17+
18+
it("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+
});

‎apps/web/src/components/chat/ComposerPrimaryActions.menus.test.tsx‎

Lines changed: 0 additions & 95 deletions
This file was deleted.

‎apps/web/src/components/chat/ComposerPrimaryActions.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
239239
"h-9 rounded-l-none border-l border-message-action-foreground/20 px-2 sm:h-8",
240240
)}
241241
aria-label="Implementation actions"
242-
{...pointerFocusProps}
242+
onMouseDown={
243+
preserveComposerFocusOnPointerDown ? (event) => event.preventDefault() : undefined
244+
}
243245
disabled={isSendBusy || isSendDisabled || isConnecting || isEnvironmentUnavailable}
244246
/>
245247
}

0 commit comments

Comments
 (0)