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

PullRequestsUnavailableState.browser.test.tsx

37 lines1.3 KB

1import { EnvironmentId, 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 { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
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 <PullRequestsUnavailableState
21 error="Not found"
22 host={{
23 url: "https://github.com/owner/repo/pull/1",
24 openLabel: "Open on GitHub",
25 threadRef,
26 }}
27 />,
28 );
29 const link = screen.container.querySelector("a")!;
30 const click = new MouseEvent("click", { bubbles: true, cancelable: true });
31 link.dispatchEvent(click);
32 expect(click.defaultPrevented).toBe(true);
33 expect(useOpenLink).toHaveBeenCalledWith(threadRef);
34 expect(openLink).toHaveBeenCalledWith("https://github.com/owner/repo/pull/1", {
35 event: expect.anything(),
36 });
37});