Skip to content

Commit fd9741d

Browse files
MarcoDotIOclaude
andcommitted
test(web): cover a checkout choice chosen twice in the palette
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6d1c12b commit fd9741d

1 file changed

Lines changed: 59 additions & 3 deletions

File tree

‎apps/web/src/components/CommandPalette.composition.browser.test.tsx‎

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { CommandPalette } from "./CommandPalette";
77
import { openCommandPalette } from "../commandPaletteBus";
88
import { primaryServerKeybindingsAtom } from "../state/server";
99

10+
const addProject = vi.hoisted(() => ({
11+
inspection: undefined as unknown,
12+
createdRoots: [] as string[],
13+
createGate: Promise.resolve(),
14+
}));
15+
1016
vi.mock("@effect/atom-react", async (original) => ({
1117
...(await original<typeof import("@effect/atom-react")>()),
1218
useAtomValue: (atom: unknown) =>
@@ -39,10 +45,19 @@ vi.mock("../hooks/useHandleNewThread", () => ({
3945
vi.mock("../hooks/useOpenPanelPullRequestUrl", () => ({ useOpenPanelPullRequestUrl: () => null }));
4046
vi.mock("../connection/useDesktopLocalBootstraps", () => ({ useDesktopLocalBootstraps: () => [] }));
4147
vi.mock("../state/use-atom-command", () => ({
42-
useAtomCommand: () => async () => ({ _tag: "Success", value: undefined }),
48+
useAtomCommand: () => async (args?: { input?: { workspaceRoot?: string } }) => {
49+
if (args?.input?.workspaceRoot !== undefined) {
50+
addProject.createdRoots.push(args.input.workspaceRoot);
51+
await addProject.createGate;
52+
}
53+
return { _tag: "Success", value: undefined };
54+
},
4355
}));
4456
vi.mock("../state/use-atom-query-runner", () => ({
45-
useAtomQueryRunner: () => async () => ({ _tag: "Success", value: undefined }),
57+
useAtomQueryRunner: () => async (args?: { input?: { path?: string } }) => ({
58+
_tag: "Success",
59+
value: args?.input?.path === undefined ? undefined : addProject.inspection,
60+
}),
4661
}));
4762
vi.mock("../state/environments", async (original) => ({
4863
...(await original<typeof import("../state/environments")>()),
@@ -54,7 +69,10 @@ vi.mock("../state/environments", async (original) => ({
5469
connection: { phase: "connected" },
5570
entry: { target: { _tag: "PrimaryConnectionTarget" } },
5671
serverConfig: {
57-
environment: { platform: { os: "linux" }, capabilities: { projectCloneTracking: true } },
72+
environment: {
73+
platform: { os: "linux" },
74+
capabilities: { projectCloneTracking: true, projectCheckoutInspection: true },
75+
},
5876
settings: { addProjectBaseDirectory: "/workspace/" },
5977
},
6078
},
@@ -133,3 +151,41 @@ describe.each(["repository", "folder", "destination"] as const)("add-project %s"
133151
}
134152
});
135153
});
154+
155+
describe("add-project checkout choice", () => {
156+
it("sends one create when chosen again while the first is pending", async () => {
157+
let finishCreate = () => {};
158+
addProject.createGate = new Promise((resolve) => {
159+
finishCreate = resolve;
160+
});
161+
addProject.createdRoots = [];
162+
addProject.inspection = {
163+
projectId: null,
164+
checkout: {
165+
selectedPath: "/workspace/repo/apps",
166+
root: "/workspace/repo",
167+
rootProjectId: null,
168+
branch: "main",
169+
isLinkedWorktree: false,
170+
},
171+
};
172+
using _fixture = {
173+
[Symbol.dispose]() {
174+
addProject.inspection = undefined;
175+
addProject.createGate = Promise.resolve();
176+
},
177+
};
178+
await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
179+
await act(() => openCommandPalette({ open: "add-project" }));
180+
await page.getByText("Local folder", { exact: true }).click();
181+
await page.getByRole("combobox").fill("/workspace/repo/apps");
182+
await userEvent.keyboard("{Enter}");
183+
184+
const addRoot = page.getByText("Add repository root", { exact: true });
185+
await addRoot.click();
186+
await addRoot.click();
187+
await act(() => finishCreate());
188+
189+
expect(addProject.createdRoots).toEqual(["/workspace/repo"]);
190+
});
191+
});

0 commit comments

Comments
 (0)