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

AnnotatableCodeView.test.tsx

65 lines1.9 KB

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