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

PullRequestThreadDialog.browser.test.tsx

45 lines1.7 KB

1import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import * as Cause from "effect/Cause";
3import { AsyncResult } from "effect/reactivity";
4import { expect, it } from "vite-plus/test";
5import { page } from "vite-plus/test/browser";
6​
7import { AppAtomRegistryProvider, appAtomRegistry } from "~/rpc/atomRegistry";
8import { vcsActionManager } from "~/state/vcs";
9import { act, render } from "../../test/render";
10import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
11​
12it("keeps another caller's checkout failure out of the dialog", async () => {
13 const target = { environmentId: EnvironmentId.make("checkout-error-test"), cwd: "/repo" };
14 const failure = AsyncResult.failure(Cause.fail(new Error("Pull request #42 has local changes.")));
15 const reply = Promise.withResolvers<typeof failure>();
16​
17 await using _screen = await render(
18 <AppAtomRegistryProvider>
19 <PullRequestThreadDialog
20 {...target}
21 open
22 initialReference={null}
23 threadId={ThreadId.make("checkout-error-test")}
24 onOpenChange={() => {}}
25 onPrepared={() => {}}
26 />
27 </AppAtomRegistryProvider>,
28 );
29​
30 const dialog = page.getByRole("dialog");
31 const cancel = dialog.getByRole("button", { name: "Cancel" });
32 const checkout = vcsActionManager.track(
33 appAtomRegistry,
34 target,
35 { operation: "prepare_pull_request_thread", label: "Preparing pull request thread" },
36 () => reply.promise,
37 );
38 await expect.element(cancel).toBeDisabled();
39 await act(async () => {
40 reply.resolve(failure);
41 await checkout;
42 });
43 await expect.element(cancel).toBeEnabled();
44 expect(dialog.getByText(/Failed to prepare .* request thread\./).query()).toBeNull();
45});