Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CommandPalette.composition.browser.test.tsx

621 lines24.9 KB

1import { describe, expect, it, vi } from "vite-plus/test";
2import { page, userEvent } from "vite-plus/test/browser";
3import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
4import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
5import {
6 AuthOrchestrationOperateScope,
7 AuthSourceControlWriteScope,
8 EnvironmentId,
9 ProjectId,
10 ThreadId,
11} from "@t3tools/contracts";
12import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
13import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
14import { act, render, stubGlobal } from "../../test/render";
15import { CommandPalette } from "./CommandPalette";
16import { openCommandPalette } from "../commandPaletteBus";
17import { DraftId, useComposerDraftStore } from "../composerDraftStore";
18import { moveDraftToProject } from "../lib/moveDraftToProject";
19import { primaryServerKeybindingsAtom } from "../state/server";
20import { filesystemEnvironment } from "../state/filesystem";
21import { projectEnvironment } from "../state/projects";
22import { sourceControlEnvironment } from "../state/sourceControl";
23import { openThreadWorkspaceDialog } from "../state/threadWorkspace";
24import { AsyncResult } from "effect/reactivity";
25​
26const createdProject = {
27 _tag: "Success",
28 value: { projectId: "project-created", workspaceRoot: "/workspace/new-project" },
29} as const;
30​
31const scopes = vi.hoisted(() => ({
32 denied: undefined as string | undefined,
33 sourceControl: undefined as unknown,
34 isBrowsePending: false,
35 lookupRepository: vi.fn(),
36 hasRemote: false,
37 browse: vi.fn().mockResolvedValue({ _tag: "Success", value: { entries: [] } }),
38 moveWorkspace: vi.fn().mockResolvedValue({ _tag: "Success" }),
39 createNewProject: vi.fn<() => Promise<typeof createdProject>>(),
40 openDraft: vi.fn<() => Promise<void>>(),
41 addProject: vi.fn<() => Promise<{ _tag: "Success"; value: Partial<EnvironmentProject> }>>(),
42 waitForProject: vi.fn<() => Promise<EnvironmentProject | undefined>>(),
43}));
44const setup = (deniedScope?: string, sourceControl?: unknown, isBrowsePending = false) => {
45 scopes.denied = deniedScope;
46 scopes.sourceControl = sourceControl;
47 scopes.hasRemote = false;
48 scopes.browse.mockClear();
49 scopes.moveWorkspace.mockClear();
50 scopes.createNewProject.mockReset().mockResolvedValue(createdProject);
51 scopes.openDraft.mockReset().mockResolvedValue(undefined);
52 scopes.addProject.mockReset().mockResolvedValue({
53 _tag: "Success",
54 value: { id: ProjectId.make("project-cloned") },
55 });
56 scopes.isBrowsePending = isBrowsePending;
57 scopes.waitForProject.mockReset().mockResolvedValue(undefined);
58};
59const githubAvailable = {
60 versionControlSystems: [],
61 sourceControlProviders: [
62 {
63 kind: "github",
64 label: "GitHub",
65 status: "available",
66 version: { _tag: "None" },
67 installHint: "Install GitHub CLI",
68 detail: { _tag: "None" },
69 auth: {
70 status: "authenticated",
71 account: { _tag: "Some", value: "demo" },
72 host: { _tag: "None" },
73 detail: { _tag: "None" },
74 },
75 },
76 ],
77};
78​
79vi.mock("@effect/atom-react", async (original) => ({
80 ...(await original<typeof import("@effect/atom-react")>()),
81 useAtomValue: (atom: unknown) =>
82 atom === primaryServerKeybindingsAtom ? DEFAULT_RESOLVED_KEYBINDINGS : [],
83}));
84vi.mock("../hooks/useTheme", () => ({
85 useRenderedAppearance: () => "light",
86 useTheme: () => ({ theme: "t3-chat", resolvedTheme: "light", appearanceMode: "light" }),
87}));
88vi.mock("../hooks/useCustomThemes", () => ({ useCustomThemes: () => [] }));
89vi.mock("../hooks/useEnvironmentTheme", () => ({ useEnvironmentThemeDefinitions: () => [] }));
90vi.mock("../hooks/useSettings", async (original) => ({
91 ...(await original<typeof import("../hooks/useSettings")>()),
92 useClientSettings: () => DEFAULT_CLIENT_SETTINGS,
93 useUpdateEnvironmentSettings: () => () => undefined,
94}));
95vi.mock("../hooks/useScratchProject", () => ({
96 useScratchProject: () => ({ scratchEnvironmentId: () => null }),
97}));
98vi.mock("../hooks/useHandleNewThread", () => ({
99 useHandleNewThread: () => ({
100 activeDraftThread: null,
101 activeThread: null,
102 defaultProjectRef: null,
103 handleNewThread: scopes.openDraft,
104 }),
105 useNewThreadHandler: () => async () => undefined,
106}));
107vi.mock("../hooks/useOpenPanelPullRequestUrl", () => ({ useOpenPanelPullRequestUrl: () => null }));
108vi.mock("../connection/useDesktopLocalBootstraps", () => ({ useDesktopLocalBootstraps: () => [] }));
109vi.mock("../state/use-atom-command", () => ({
110 // The add-project destination step starts a clone and follows its project id.
111 useAtomCommand: (command: unknown) =>
112 command === projectEnvironment.createNew
113 ? scopes.createNewProject
114 : command === projectEnvironment.create
115 ? scopes.addProject
116 : command === projectEnvironment.moveThreadWorkspace
117 ? scopes.moveWorkspace
118 : async () => ({ _tag: "Success", value: { projectId: "project-cloned" } }),
119}));
120vi.mock("../state/use-atom-query-runner", () => ({
121 // Doubles as the add-project folder scan, which finds nothing to track.
122 useAtomQueryRunner: (family: unknown) =>
123 family === sourceControlEnvironment.repository ? scopes.lookupRepository : scopes.browse,
124}));
125vi.mock("../state/environments", async (original) => ({
126 ...(await original<typeof import("../state/environments")>()),
127 useEnvironments: () => ({
128 environments: [
129 {
130 environmentId: "local",
131 label: "Local",
132 connection: { phase: "connected" },
133 entry: { target: { _tag: "PrimaryConnectionTarget" } },
134 serverConfig: {
135 environment: { platform: { os: "linux" }, capabilities: { projectCloneTracking: true } },
136 settings: { addProjectBaseDirectory: "/workspace/" },
137 newProjectsRoot: "/workspace/",
138 },
139 },
140 ...(scopes.hasRemote
141 ? [
142 {
143 environmentId: "remote",
144 label: "Build machine",
145 connection: { phase: "connected" },
146 entry: { target: { _tag: "BearerConnectionTarget", connectionId: "saved:remote" } },
147 serverConfig: {
148 environment: { platform: { os: "linux" }, capabilities: {} },
149 settings: { addProjectBaseDirectory: "/remote/" },
150 },
151 },
152 ]
153 : []),
154 ],
155 }),
156 usePrimaryEnvironmentId: () => "local",
157 useEnvironmentProviders: () => new Map(),
158}));
159vi.mock("../state/entities", async (original) => ({
160 ...(await original<typeof import("../state/entities")>()),
161 useProjects: () => [],
162 useThreadShells: () => [],
163 useVisibleThreadShells: () => [],
164 useHiddenThreadKeys: () => new Set(),
165 useAnyEnvironmentHiding: () => false,
166 useEnvironmentThreadRefs: () => [],
167 useServerConfigs: () => new Map(),
168 waitForProject: scopes.waitForProject,
169}));
170vi.mock("../state/queries", async (original) => ({
171 ...(await original<typeof import("../state/queries")>()),
172 useThreadSearch: (_environmentIds: unknown, query: string) => ({
173 matches: [],
174 query,
175 isPending: false,
176 }),
177}));
178vi.mock("../state/session", async (original) => ({
179 ...(await original<typeof import("../state/session")>()),
180 useEnvironmentScope: (_environmentId: unknown, scope: string) => scope !== scopes.denied,
181 readEnvironmentScope: () => true,
182}));
183vi.mock("../state/filesystem", async (original) => ({
184 ...(await original<typeof import("../state/filesystem")>()),
185 useFilesystemReadAccess: () => ({ canReadFiles: true, isPending: false, error: null }),
186}));
187vi.mock("../state/query", async (original) => ({
188 ...(await original<typeof import("../state/query")>()),
189 useEnvironmentQuery: (atom: unknown) => {
190 const remoteBrowse = (partialPath: string) =>
191 filesystemEnvironment.browse({
192 environmentId: EnvironmentId.make("remote"),
193 input: { partialPath },
194 });
195 const data =
196 scopes.hasRemote && atom === remoteBrowse("/remote/")
197 ? { parentPath: "/remote", entries: [{ name: "app", fullPath: "/remote/app" }] }
198 : scopes.hasRemote && atom === remoteBrowse("/remote/app/")
199 ? { parentPath: "/remote/app", entries: [] }
200 : scopes.sourceControl;
201 return { data, isLoading: false, isPending: scopes.isBrowsePending };
202 },
203}));
204vi.mock("./settings/useAvailableSettingsSearchItems", () => ({
205 useAvailableSettingsSearchItems: () => [],
206}));
207​
208it("browses and updates the project on the thread's remote machine", async () => {
209 setup();
210 scopes.hasRemote = true;
211 const thread = scopeThreadRef(EnvironmentId.make("remote"), ThreadId.make("thread-to-repair"));
212 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
213 await act(() => openThreadWorkspaceDialog(thread, "project-directory"));
214 const input = page.getByRole("combobox");
215 await expect.element(input).toHaveValue("/remote/");
216 await expect.element(page.getByRole("button", { name: /^Use folder/ })).toBeEnabled();
217 await page.getByText("app", { exact: true }).click();
218 await expect.element(input).toHaveValue("/remote/app/");
219 expect(scopes.browse).toHaveBeenCalledWith({
220 environmentId: thread.environmentId,
221 input: { partialPath: "/remote/app/" },
222 });
223 await userEvent.keyboard("{Enter}");
224 await expect.element(input).not.toBeInTheDocument();
225 expect(scopes.moveWorkspace).toHaveBeenCalledExactlyOnceWith({
226 environmentId: thread.environmentId,
227 input: {
228 threadId: thread.threadId,
229 target: { type: "project-directory", path: "/remote/app" },
230 },
231 });
232 expect(scopes.addProject).not.toHaveBeenCalled();
233});
234​
235// The real palette and Base UI input must agree that confirming composition is typing.
236describe.each(["repository", "folder", "destination"] as const)("add-project %s", (step) => {
237 it.each([
238 { isComposing: true, keyCode: 13 },
239 { isComposing: false, keyCode: 229 },
240 ])("keeps Enter in the input during composition: %j", async (composition) => {
241 setup();
242 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
243 await act(() => openCommandPalette({ open: "add-project" }));
244 await page.getByText(step === "folder" ? "Local folder" : "Git URL", { exact: true }).click();
245 const input = () => page.getByRole("combobox");
246 if (step === "destination") {
247 await input().fill("https://example.com/team/project.git");
248 await userEvent.keyboard("{Enter}");
249 }
250 const value = step === "repository" ? "https://example.com/team/計画.git" : "/workspace/計画";
251 await input().fill(value);
252 const event = new KeyboardEvent("keydown", {
253 key: "Enter",
254 bubbles: true,
255 cancelable: true,
256 ...composition,
257 });
258 await act(() => input().element().dispatchEvent(event));
259 expect(event.defaultPrevented).toBe(false);
260 await expect.element(input()).toHaveValue(value);
261 if (step === "repository") {
262 await userEvent.keyboard("{Enter}");
263 await expect.element(input()).toHaveValue("/workspace/計画");
264 } else {
265 await userEvent.keyboard("{Enter}");
266 await expect.element(page.getByRole("combobox")).not.toBeInTheDocument();
267 }
268 });
269});
270​
271it.each([
272 { isBrowsePending: false, leavesInput: true },
273 { isBrowsePending: true, leavesInput: false },
274])(
275 "Tab with nothing to complete in the folder path: %j",
276 async ({ isBrowsePending, leavesInput }) => {
277 setup(undefined, undefined, isBrowsePending);
278 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
279 await act(() => openCommandPalette({ open: "add-project" }));
280 await page.getByText("Local folder", { exact: true }).click();
281 const input = page.getByRole("combobox");
282 await input.fill("/workspace/zzz");
283 await userEvent.keyboard("{Tab}");
284 if (leavesInput) {
285 await expect.element(input).not.toHaveFocus();
286 expect(page.getByRole("dialog").element().contains(document.activeElement)).toBe(true);
287 } else await expect.element(input).toHaveFocus();
288 await expect.element(input).toHaveValue("/workspace/zzz");
289 },
290);
291​
292it.each([
293 { step: "folder", source: "Local folder", keys: "", description: /^(?!.*(Ctrl|⌘)).*Add.*Enter/ },
294 {
295 step: "highlighted folder",
296 source: "Local folder",
297 keys: "{ArrowDown}",
298 description: /Add.*(Ctrl|⌘) Enter/,
299 },
300 { step: "repository", source: "Git URL", keys: "", description: /Continue.*Enter/ },
301 { step: "new project", source: "New project", keys: "", description: /Create.*Enter/ },
302 {
303 step: "permission-blocked folder",
304 source: "Local folder",
305 keys: "",
306 deniedScope: AuthOrchestrationOperateScope,
307 description: "This connection cannot add projects.",
308 },
309 {
310 step: "permission-blocked destination",
311 source: "Git URL",
312 keys: "https://example.com/team/project.git{Enter}",
313 deniedScope: AuthSourceControlWriteScope,
314 description: "This connection needs permission to write source control and add projects.",
315 },
316])(
317 "tells screen readers how to submit the $step step",
318 async ({ source, keys, deniedScope, description }) => {
319 setup(deniedScope);
320 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
321 await act(() => openCommandPalette({ open: "add-project" }));
322 await page.getByText(source, { exact: true }).click();
323 if (keys) await userEvent.keyboard(keys);
324 await expect.element(page.getByRole("combobox")).toHaveAccessibleDescription(description);
325 },
326);
327​
328it("keeps the caret in place when an edit briefly makes the folder path not a path", async () => {
329 setup();
330 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
331 await act(() => openCommandPalette({ open: "add-project" }));
332 await page.getByText("Local folder", { exact: true }).click();
333 const input = () => page.getByRole("combobox");
334 await input().fill("/workspace/project");
335 await userEvent.keyboard("{Home}{ArrowRight}{Backspace}");
336 await expect.element(input()).toHaveValue("workspace/project");
337 await userEvent.keyboard("/");
338 await expect.element(input()).toHaveValue("/workspace/project");
339 await userEvent.keyboard("w");
340 await expect.element(input()).toHaveValue("/wworkspace/project");
341});
342​
343it.each([
344 { flow: "Git URL", value: "https://github.com/pingdotgg/t3code.git", submit: "Continue (Enter)" },
345 { flow: "New project", value: "demo-tab-order", submit: /^Create \(/ },
346])("moves focus from the $flow input to its enabled submit button on Tab", async (step) => {
347 setup();
348 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
349 await act(() => openCommandPalette({ open: "add-project" }));
350 await page.getByText(step.flow, { exact: true }).click();
351 const input = page.getByRole("combobox");
352 await input.fill(step.value);
353 const submit = page.getByRole("button", { name: step.submit });
354 await expect.element(submit).toBeEnabled();
355 await userEvent.keyboard("{Tab}");
356 await expect.element(submit).toHaveFocus();
357});
358​
359it("tells screen readers whether a new project will be published", async () => {
360 setup(undefined, githubAvailable);
361 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
362 await act(() => openCommandPalette({ open: "add-project" }));
363 await page.getByText("New project", { exact: true }).click();
364 await page.getByRole("combobox").fill("demo-project");
365 const option = page.getByRole("option", { name: /Create private repository/ });
366 await expect.element(option).toHaveAttribute("aria-checked", "false");
367 await option.click();
368 await expect.element(option).toHaveAttribute("aria-checked", "true");
369});
370​
371async function submitProjectAdd(source: string, input: string, draftId?: DraftId) {
372 await act(() => openCommandPalette({ open: "add-project", ...(draftId && { draftId }) }));
373 await page.getByText(source, { exact: true }).click();
374 await page.getByRole("combobox").fill(input);
375 await userEvent.keyboard("{Enter}");
377​
378async function startLateProjectAdd(source: string, input: string, draftId?: DraftId) {
379 const finished = Promise.withResolvers<void>();
380 const created = Promise.withResolvers<typeof createdProject>();
381 scopes.createNewProject.mockReturnValue(created.promise);
382 scopes.openDraft.mockReturnValue(finished.promise);
383 scopes.addProject.mockImplementation(async () => {
384 await finished.promise;
385 return { _tag: "Success", value: project("added") };
386 });
387 await submitProjectAdd(source, input, draftId);
388 return async () => {
389 await act(async () => {
390 created.resolve(createdProject);
391 finished.resolve();
392 await finished.promise;
393 });
394 expect(source === "New project" ? scopes.openDraft : scopes.addProject).toHaveBeenCalledOnce();
395 };
397​
398it.each([
399 { source: "New project", input: "new-project" },
400 { source: "Local folder", input: "/workspace/existing" },
401])("keeps a reopened palette open when $source finishes late", async ({ source, input }) => {
402 setup();
403 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
404 const finish = await startLateProjectAdd(source, input);
405 const search = page.getByRole("combobox");
406 await userEvent.keyboard("{Escape}");
407 await expect.element(search).not.toBeInTheDocument();
408 await act(() => openCommandPalette());
409 await search.fill("another search");
410​
411 await finish();
412 expect(page.getByTestId("command-palette").element()).toHaveAttribute("data-open");
413 expect(search.element()).toHaveValue("another search");
414});
415​
416it("keeps the view the user went back to when a folder add finishes late", async () => {
417 setup();
418 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
419 const finish = await startLateProjectAdd("Local folder", "/workspace/existing");
420 await page.getByRole("combobox").fill("");
421 await expect.element(page.getByText("Git URL", { exact: true })).toBeVisible();
422​
423 await finish();
424 expect(page.getByTestId("command-palette").element()).toHaveAttribute("data-open");
425 expect(page.getByText("Git URL", { exact: true }).element()).toBeVisible();
426});
427​
428it.each(["/", "/?panel=files"])(
429 "opens the added folder after navigation to the same page (%s)",
430 async (to) => {
431 setup();
432 await using screen = await render(<CommandPalette>{null}</CommandPalette>);
433 const finish = await startLateProjectAdd("Local folder", "/workspace/next");
434​
435 await act(() => screen.router!.navigate({ to }));
436 await finish();
437​
438 expect(scopes.openDraft).toHaveBeenCalledOnce();
439 },
440);
441​
442const environmentId = EnvironmentId.make("local");
443const project = (name: string): EnvironmentProject => ({
444 id: ProjectId.make(name),
445 environmentId,
446 title: name,
447 workspaceRoot: `/workspace/${name}`,
448 repositoryIdentity: null,
449 defaultModelSelection: null,
450 createdAt: "2026-03-01T00:00:00.000Z",
451 updatedAt: "2026-03-01T00:00:00.000Z",
452 scripts: [],
453});
454​
455it.each([
456 { selection: [], expected: "added" },
457 { selection: ["other"], expected: "other" },
458 { selection: ["other", "original"], expected: "original" },
459])("keeps the draft's project selection after switching threads (%j)", async (row) => {
460 setup();
461 const draftId = DraftId.make("draft-adding-project");
462 const store = useComposerDraftStore.getState();
463 store.setProjectDraftThreadId(
464 scopeProjectRef(environmentId, ProjectId.make("original")),
465 draftId,
466 );
467 store.setPrompt(draftId, "Keep this draft");
468 try {
469 await using screen = await render(<CommandPalette>{null}</CommandPalette>);
470 const finish = await startLateProjectAdd("Local folder", "/workspace/added", draftId);
471 await userEvent.keyboard("{Escape}");
472 await expect.element(page.getByRole("combobox")).not.toBeInTheDocument();
473 await act(() => {
474 for (const name of row.selection) moveDraftToProject(draftId, project(name));
475 });
476 await act(() =>
477 screen.router!.navigate({
478 to: "/$environmentId/$threadId",
479 params: { environmentId, threadId: "another-thread" },
480 }),
481 );
482 await finish();
483​
484 expect(screen.router!.state.location.pathname).toBe("/local/another-thread");
485 expect(scopes.openDraft).not.toHaveBeenCalled();
486 expect(store.getDraftSession(draftId)?.projectId).toBe(row.expected);
487 } finally {
488 store.clearDraftThread(draftId);
489 }
490});
491​
492it.each([
493 { replyOrder: ["older", "newer"], assignments: ["original", "newer"] },
494 { replyOrder: ["newer", "older"], assignments: ["newer", "newer"] },
495] as const)("uses the newer folder selection when replies arrive %j", async (row) => {
496 setup();
497 const draftId = DraftId.make("draft-adding-two-projects");
498 const store = useComposerDraftStore.getState();
499 store.setProjectDraftThreadId(
500 scopeProjectRef(environmentId, ProjectId.make("original")),
501 draftId,
502 );
503 store.setPrompt(draftId, "Keep this draft");
504 const pending = {
505 older: Promise.withResolvers<{ _tag: "Success"; value: EnvironmentProject }>(),
506 newer: Promise.withResolvers<{ _tag: "Success"; value: EnvironmentProject }>(),
507 };
508 scopes.addProject
509 .mockReturnValueOnce(pending.older.promise)
510 .mockReturnValueOnce(pending.newer.promise);
511 try {
512 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
513 for (const name of ["older", "newer"]) {
514 await submitProjectAdd("Local folder", `/workspace/${name}`, draftId);
515 await userEvent.keyboard("{Escape}");
516 await expect.element(page.getByRole("combobox")).not.toBeInTheDocument();
517 }
518 for (const [index, name] of row.replyOrder.entries()) {
519 await act(async () => {
520 pending[name].resolve({ _tag: "Success", value: project(name) });
521 await pending[name].promise;
522 });
523 expect(store.getDraftSession(draftId)?.projectId).toBe(row.assignments[index]);
524 }
525 } finally {
526 store.clearDraftThread(draftId);
527 }
528});
529​
530it("keeps a reopened palette open after a late folder pick", async () => {
531 setup();
532 const picked = Promise.withResolvers<string>();
533 const pickFolder = vi.fn(() => picked.promise);
534 using _bridge = stubGlobal("desktopBridge", {
535 getWslState: async () => null,
536 pickFolder,
537 });
538 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
539 await act(() => openCommandPalette({ open: "add-project" }));
540 await page.getByText("Local folder", { exact: true }).click();
541 const search = page.getByRole("combobox");
542 page
543 .getByRole("button", { name: /^Open in / })
544 .element()
545 .focus();
546 await userEvent.keyboard("{Enter}");
547 expect(pickFolder).toHaveBeenCalledOnce();
548 await userEvent.keyboard("{Escape}");
549 await expect.element(search).not.toBeInTheDocument();
550 await act(() => openCommandPalette());
551 await search.fill("another search");
552​
553 await act(async () => {
554 picked.resolve("/workspace/picked");
555 await picked.promise;
556 });
557 expect(scopes.addProject).toHaveBeenCalledOnce();
558 expect(page.getByTestId("command-palette").element()).toHaveAttribute("data-open");
559 expect(search.element()).toHaveValue("another search");
560});
561​
562it("keeps the source list visible after a dismissed repository lookup succeeds", async () => {
563 setup(undefined, githubAvailable);
564 const repository = AsyncResult.success({
565 provider: "github",
566 nameWithOwner: "example/slow",
567 url: "https://github.com/example/slow",
568 sshUrl: "git@github.com:example/slow.git",
569 });
570 const lookup = Promise.withResolvers<typeof repository>();
571 scopes.lookupRepository.mockReset().mockReturnValue(lookup.promise);
572 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
573 await act(() => openCommandPalette({ open: "add-project" }));
574 await page.getByRole("option", { name: /^GitHub repository/ }).click();
575 await page.getByRole("combobox").fill("example/slow");
576 await userEvent.keyboard("{Enter}");
577 expect(scopes.lookupRepository).toHaveBeenCalledOnce();
578 await page.getByRole("combobox").fill("");
579 await userEvent.keyboard("{Backspace}");
580 const sources = page.getByText("Git URL", { exact: true });
581 await expect.element(sources).toBeVisible();
582​
583 await act(async () => {
584 lookup.resolve(repository);
585 await lookup.promise;
586 });
587 expect(sources.element()).toBeVisible();
588});
589​
590it("looks up a corrected repository name after the pending reply for the old one", async () => {
591 setup(undefined, githubAvailable);
592 const repository = AsyncResult.success({
593 provider: "github",
594 nameWithOwner: "example/slow",
595 url: "https://github.com/example/slow",
596 sshUrl: "git@github.com:example/slow.git",
597 });
598 const lookup = Promise.withResolvers<typeof repository>();
599 scopes.lookupRepository
600 .mockReset()
601 .mockReturnValueOnce(lookup.promise)
602 .mockReturnValueOnce(Promise.withResolvers<typeof repository>().promise);
603 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
604 await act(() => openCommandPalette({ open: "add-project" }));
605 await page.getByRole("option", { name: /^GitHub repository/ }).click();
606 const input = page.getByRole("combobox");
607 await input.fill("example/slow");
608 await userEvent.keyboard("{Enter}");
609 expect(scopes.lookupRepository).toHaveBeenCalledOnce();
610 await input.fill("example/corrected");
611​
612 await act(async () => {
613 lookup.resolve(repository);
614 await lookup.promise;
615 });
616 expect(input.element()).toHaveValue("example/corrected");
617 await userEvent.keyboard("{Enter}");
618 expect(scopes.lookupRepository).toHaveBeenLastCalledWith(
619 expect.objectContaining({ input: { provider: "github", repository: "example/corrected" } }),
620 );
621});