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

PullRequestSummaryTab.browser.test.tsx

110 lines3.5 KB

1import { SourceControlProviderKind } from "@t3tools/contracts";
2import { EnvironmentId, ProjectId, type PullRequestDetailView } from "@t3tools/contracts";
3import { expect, it, vi } from "vite-plus/test";
4import { userEvent } from "vite-plus/test/browser";
5​
6vi.mock(import("~/state/use-atom-command"), async (original) => ({
7 ...(await original()),
8 useAtomCommand: (() => vi.fn()) as never,
9}));
10​
11import { act, render as renderUi } from "../../../test/render";
12import { PullRequestSummaryTab } from "./PullRequestSummaryTab";
13​
14const detail: PullRequestDetailView = {
15 provider: SourceControlProviderKind.make("github"),
16 projectId: ProjectId.make("project"),
17 projectTitle: "Project",
18 workspaceRoot: "/workspace",
19 repository: "owner/repo",
20 number: 1,
21 title: "Test pull request",
22 body: "Original description",
23 url: "https://github.com/owner/repo/pull/1",
24 author: { login: "author", name: null, avatarUrl: null },
25 viewer: "author",
26 state: "open",
27 isDraft: false,
28 mergeability: "mergeable",
29 additions: 1,
30 deletions: 0,
31 changedFiles: 1,
32 headBranch: "feature",
33 baseBranch: "main",
34 createdAt: "2026-09-01T00:00:00Z",
35 updatedAt: "2026-09-01T00:00:00Z",
36 mergedAt: null,
37 closedAt: null,
38 reviewers: [],
39 labels: [],
40 checks: [{ name: "Unit tests", status: "success", description: null, url: null }],
41 comments: [],
42 commentCount: 0,
43 commentsTruncated: false,
44 reviewThreads: [],
45 commits: [],
46 mergeCapabilities: { merge: false, squash: false, rebase: false },
47 capabilities: {
48 diff: true,
49 comment: true,
50 search: true,
51 actions: [],
52 mergeMethods: [],
53 review: { inlineComment: false, reply: false, resolve: false, verdicts: [] },
54 reviewers: { request: false, listCandidates: false },
55 edit: { changeRequest: true, comment: true },
56 },
57 viewerPermissions: {
58 actions: [],
59 comment: true,
60 resolve: false,
61 verdicts: [],
62 requestReviewers: false,
63 },
64};
65​
66// The comment filter persists to localStorage, so tests that touch it start and end empty.
67​
68const tab = (value = detail) => (
69 <PullRequestSummaryTab
70 scrollerRef={() => {}}
71 environmentId={EnvironmentId.make("environment")}
72 threadRef={null}
73 reference={value}
74 detail={value}
75 activityPending={false}
76 activityError={null}
77 onRefresh={() => {}}
78 />
79);
80​
81async function render(value = detail) {
82 const screen = await renderUi(tab(value));
83 const { container } = screen;
84 const heading = (title: string) => {
85 const section = container.querySelector(`section[aria-label="${title}"]`);
86 expect(section, `section ${title}`).not.toBeNull();
87 return [...section!.querySelectorAll("button")].find(
88 (button) => button.querySelector("span")?.textContent === title,
89 )!;
90 };
91 return Object.assign(screen, {
92 click: (title: string) => act(async () => heading(title).click()),
93 expanded: (title: string) => heading(title).getAttribute("aria-expanded"),
94 visibleText: () => container.innerText,
95 });
97​
98it("keeps an unsaved description when collapsed and reopened", async () => {
99 await using screen = await render();
100 await act(async () =>
101 screen.container.querySelector<HTMLButtonElement>('[aria-label="Edit description"]')!.click(),
102 );
103 const textarea = screen.container.querySelector("textarea")!;
104 await userEvent.clear(textarea);
105 await userEvent.type(textarea, "Unsaved description");
106 await screen.click("Description");
107 expect(screen.expanded("Description")).toBe("false");
108 await screen.click("Description");
109 expect(screen.container.querySelector("textarea")!.value).toBe("Unsaved description");
110});