Open History to see the last commit
1import { EnvironmentId } from "@t3tools/contracts";
2import { expect, it, vi } from "vite-plus/test";
3import { page, userEvent } from "vite-plus/test/browser";
4
5import { render } from "../../../test/render";
6import { ProposedPlanCard } from "./ProposedPlanCard";
7
8const writeFile = vi.hoisted(() =>
9 vi.fn<(request: unknown) => Promise<{ _tag: "Success"; value: { relativePath: string } }>>(),
10);
11
12vi.mock(import("~/state/session"), async (original) => ({
13 ...(await original()),
14 readEnvironmentScope: (() => true) as never,
15 useEnvironmentScope: (() => true) as never,
16}));
17vi.mock(import("~/state/use-atom-command"), () => ({
18 useAtomCommand: (() => writeFile) as never,
19}));
20
21it("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});