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

PullRequestTitleEditor.browser.test.tsx

86 lines2.6 KB

1import {
2 EnvironmentId,
3 ProjectId,
4 SourceControlProviderKind,
5 type PullRequestDetail,
6} from "@t3tools/contracts";
7import { expect, it, vi } from "vite-plus/test";
8import { page, userEvent } from "vite-plus/test/browser";
9​
10import { act, render } from "../../../test/render";
11import { RightPanelSheet } from "../RightPanelSheet";
12import { PullRequestTitleEditor } from "./PullRequestTitleEditor";
13​
14const detail: PullRequestDetail = {
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: "",
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: [],
41 mergeCapabilities: { merge: false, squash: false, rebase: false },
42 capabilities: {
43 diff: true,
44 comment: false,
45 search: true,
46 actions: [],
47 mergeMethods: [],
48 review: { inlineComment: false, reply: false, resolve: false, verdicts: [] },
49 reviewers: { request: false, listCandidates: false },
50 edit: { changeRequest: true, comment: false },
51 },
52 viewerPermissions: {
53 actions: [],
54 comment: false,
55 resolve: false,
56 verdicts: [],
57 requestReviewers: false,
58 },
59};
60​
61it("Escape cancels the title edit without closing the right panel sheet", async () => {
62 const onCloseSheet = vi.fn();
63 await using _screen = await render(
64 <RightPanelSheet animationDurationMs={0} open onClose={onCloseSheet}>
65 <PullRequestTitleEditor
66 environmentId={EnvironmentId.make("environment")}
67 reference={{ projectId: detail.projectId, repository: "owner/repo", number: 1 }}
68 pullRequestKey="owner/repo#1"
69 detail={detail}
70 canWriteSourceControl
71 />
72 </RightPanelSheet>,
73 );
74 await act(() =>
75 (page.getByRole("button", { name: "Edit title" }).element() as HTMLElement).click(),
76 );
77 const input = page.getByRole("textbox", { name: "Pull request title" });
78 await expect.element(input).toHaveFocus();
79​
80 await userEvent.keyboard("{Escape}");
81 await expect.element(input).not.toBeInTheDocument();
82 expect(onCloseSheet).not.toHaveBeenCalled();
83​
84 await userEvent.keyboard("{Escape}");
85 expect(onCloseSheet).toHaveBeenCalledTimes(1);
86});