Skip to content

Commit 0e9071c

Browse files
fix(web): pressing Enter submits the Save plan to workspace dialog (#45305)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent 6ee834e commit 0e9071c

2 files changed

Lines changed: 65 additions & 3 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { EnvironmentId } from "@t3tools/contracts";
2+
import { expect, it, vi } from "vite-plus/test";
3+
import { page, userEvent } from "vite-plus/test/browser";
4+
5+
import { render } from "../../../test/render";
6+
import { ProposedPlanCard } from "./ProposedPlanCard";
7+
8+
const writeFile = vi.hoisted(() =>
9+
vi.fn<(request: unknown) => Promise<{ _tag: "Success"; value: { relativePath: string } }>>(),
10+
);
11+
12+
vi.mock(import("~/state/session"), async (original) => ({
13+
...(await original()),
14+
readEnvironmentScope: (() => true) as never,
15+
useEnvironmentScope: (() => true) as never,
16+
}));
17+
vi.mock(import("~/state/use-atom-command"), () => ({
18+
useAtomCommand: (() => writeFile) as never,
19+
}));
20+
21+
it("saves the plan once when Enter is pressed in the workspace path field", async () => {
22+
const pending = Promise.withResolvers<{
23+
_tag: "Success";
24+
value: { relativePath: string };
25+
}>();
26+
writeFile.mockReturnValue(pending.promise);
27+
const environmentId = EnvironmentId.make("environment-local");
28+
29+
await using screen = await render(
30+
<ProposedPlanCard
31+
planMarkdown={"# Migration Plan\n\n- Step 1\n"}
32+
environmentId={environmentId}
33+
cwd="/workspace"
34+
workspaceRoot="/workspace"
35+
/>,
36+
);
37+
38+
await screen.getByRole("button", { name: "Plan actions" }).click();
39+
await page.getByRole("menuitem", { name: "Save to workspace" }).click();
40+
await page.getByRole("textbox", { name: "Workspace path" }).fill("plans/migration.md");
41+
await userEvent.keyboard("{Enter}");
42+
await userEvent.keyboard("{Enter}");
43+
44+
expect(writeFile).toHaveBeenCalledExactlyOnceWith({
45+
environmentId,
46+
input: {
47+
cwd: "/workspace",
48+
relativePath: "plans/migration.md",
49+
contents: "# Migration Plan\n\n- Step 1\n",
50+
},
51+
});
52+
pending.resolve({ _tag: "Success", value: { relativePath: "plans/migration.md" } });
53+
await expect
54+
.element(page.getByRole("dialog", { name: "Save plan to workspace" }))
55+
.not.toBeInTheDocument();
56+
});

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,13 @@ function SavePlanToWorkspaceForm({
287287
const [savePath, setSavePath] = useState(initialPath);
288288
const savePathInputId = useId();
289289
return (
290-
<>
290+
<form
291+
className="flex min-h-0 flex-col"
292+
onSubmit={(event) => {
293+
event.preventDefault();
294+
if (canWriteFiles && !saving) onSave(savePath);
295+
}}
296+
>
291297
<DialogHeader>
292298
<DialogTitle>
293299
<T>Save plan to workspace</T>
@@ -327,10 +333,10 @@ function SavePlanToWorkspaceForm({
327333
<Button variant="outline" size="sm" onClick={onCancel} disabled={saving}>
328334
<T>Cancel</T>
329335
</Button>
330-
<Button size="sm" onClick={() => onSave(savePath)} disabled={!canWriteFiles || saving}>
336+
<Button type="submit" size="sm" disabled={!canWriteFiles || saving}>
331337
{saving ? gt("Saving...") : gt("Save")}
332338
</Button>
333339
</DialogFooter>
334-
</>
340+
</form>
335341
);
336342
}

0 commit comments

Comments
 (0)