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

PullRequestDiffUnavailableState.browser.test.tsx

36 lines1.3 KB

1import { EnvironmentId, SourceControlProviderKind, ThreadId } from "@t3tools/contracts";
2import { expect, it, vi } from "vite-plus/test";
3​
4const { openLink, useOpenLink } = vi.hoisted(() => {
5 const openLink = vi.fn(async () => {});
6 return { openLink, useOpenLink: vi.fn((_threadRef: unknown) => openLink) };
7});
8vi.mock(import("~/browser/useOpenLink"), () => ({ useOpenLink }));
9​
10import { render } from "../../../test/render";
11import { PullRequestDiffUnavailableState } from "./PullRequestDiffUnavailableState";
12​
13const threadRef = {
14 environmentId: EnvironmentId.make("environment"),
15 threadId: ThreadId.make("thread"),
16};
17​
18it("opens the host through the link-target setting, not a popup", async () => {
19 await using screen = await render(
20 <PullRequestDiffUnavailableState
21 error="rate limit"
22 provider={SourceControlProviderKind.make("github")}
23 url="https://github.com/owner/repo/pull/1"
24 threadRef={threadRef}
25 onRetry={() => {}}
26 />,
27 );
28 const link = screen.container.querySelector("a")!;
29 const click = new MouseEvent("click", { bubbles: true, cancelable: true });
30 link.dispatchEvent(click);
31 expect(click.defaultPrevented).toBe(true);
32 expect(useOpenLink).toHaveBeenCalledWith(threadRef);
33 expect(openLink).toHaveBeenCalledWith("https://github.com/owner/repo/pull/1", {
34 event: expect.anything(),
35 });
36});