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

AnnotatableCodeView.test.tsx

59 lines1.7 KB

1import { renderToStaticMarkup } from "react-dom/server";
2import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
3​
4const testState = vi.hoisted(() => ({
5 codeViewOptions: null as Record<string, unknown> | null,
6}));
7​
8vi.mock("@pierre/diffs/react", () => ({
9 CodeView: (props: { options: Record<string, unknown> }) => {
10 testState.codeViewOptions = props.options;
11 return null;
12 },
13}));
14​
15vi.mock("~/composerDraftStore", () => ({
16 useComposerDraftStore: (selector: (store: Record<string, unknown>) => unknown) =>
17 selector({
18 addReviewComment: vi.fn(),
19 removeReviewComment: vi.fn(),
20 getComposerDraft: () => undefined,
21 }),
22}));
23​
24vi.mock("./DiffCommentAnnotation", () => ({
25 DiffCommentAnnotation: () => null,
26}));
27​
28vi.mock("../files/fileCommentAnnotations", () => ({
29 nextFileCommentId: () => "comment-test",
30}));
31​
32import { AnnotatableCodeView } from "./AnnotatableCodeView";
33​
34describe("AnnotatableCodeView", () => {
35 beforeEach(() => {
36 testState.codeViewOptions = null;
37 });
38​
39 it("opens comments from Pierre's gutter action without ending line selection", () => {
40 renderToStaticMarkup(
41 <AnnotatableCodeView
42 codeViewKey="test-view"
43 files={[]}
44 sectionId="working-tree"
45 sectionTitle="Working tree"
46 composerDraftTarget={"draft-test" as never}
47 options={{}}
48 renderHeaderPrefix={() => null}
49 />,
50 );
51​
52 expect(testState.codeViewOptions).toMatchObject({
53 enableGutterUtility: true,
54 enableLineSelection: true,
55 onGutterUtilityClick: expect.any(Function),
56 });
57 expect(testState.codeViewOptions).not.toHaveProperty("onLineSelectionEnd");
58 });
59});