@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 74 lines 2.25 KB
Raw
1 import { EnvironmentId, IssueTrackerKind, ProjectId } from "@t3tools/contracts";
2 import { expect, it, vi } from "vite-plus/test";
3 import { page, userEvent } from "vite-plus/test/browser";
4
5 const state = vi.hoisted(() => ({ detail: null as unknown, error: null as unknown }));
6 vi.mock(import("~/state/query"), async (original) => ({
7 ...(await original()),
8 useEnvironmentQuery: ((atom: unknown) => ({
9 data: atom === null ? null : state.detail,
10 dataUpdatedAt: 0,
11 error: atom === null ? null : state.error,
12 failure: null,
13 isPending: false,
14 isSuccess: state.detail !== null,
15 refresh: () => undefined,
16 })) as never,
17 }));
18
19 import { render } from "../../../test/render";
20 import { IssueLinkPreview } from "./IssueLinkPreview";
21
22 const url = "https://github.com/owner/repo/issues/7";
23
24 function setup({ detail = null as unknown, error = null as unknown } = {}) {
25 state.detail = detail;
26 state.error = error;
27 }
28
29 function renderPreview() {
30 return render(
31 <IssueLinkPreview
32 link={<a href={url}>#7</a>}
33 originalUrl={url}
34 target={{
35 environmentId: EnvironmentId.make("environment"),
36 input: {
37 projectId: ProjectId.make("project"),
38 tracker: IssueTrackerKind.make("github"),
39 scope: "owner/repo",
40 key: "7",
41 },
42 }}
43 />,
44 );
45 }
46
47 it("shows the issue's title, state and author on hover", async () => {
48 setup({
49 detail: {
50 scope: "owner/repo",
51 displayKey: "#7",
52 title: "Hover cards for issues",
53 state: { category: "closed", name: "Closed", closeReason: "completed" },
54 author: { login: "octocat" },
55 createdAt: "2026-08-01T00:00:00Z",
56 },
57 });
58 await using screen = await renderPreview();
59
60 await userEvent.hover(screen.getByRole("link"));
61
62 await expect.element(page.getByText("Hover cards for issues")).toBeVisible();
63 await expect.element(page.getByText("Closed", { exact: true })).toBeVisible();
64 await expect.element(page.getByText("octocat")).toBeVisible();
65 });
66
67 it("falls back to the link's URL when the issue cannot be read", async () => {
68 setup({ error: new Error("unavailable") });
69 await using screen = await renderPreview();
70
71 await userEvent.hover(screen.getByRole("link"));
72
73 await expect.element(page.getByText(url)).toBeVisible();
74 });