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

nativeReviewDiffAdapter.test.ts

56 lines1.7 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 getCachedNativeReviewDiffData,
5 type BuildNativeReviewDiffDataInput,
6} from "./nativeReviewDiffAdapter";
7import type { ReviewInlineComment } from "./reviewCommentSelection";
8import { buildReviewParsedDiff } from "./reviewModel";
9​
10const parsedDiff = buildReviewParsedDiff(
11 [
12 "diff --git a/example.ts b/example.ts",
13 "--- a/example.ts",
14 "+++ b/example.ts",
15 "@@ -1 +1 @@",
16 "-const before = 1;",
17 "+const after = 2;",
18 ].join("\n"),
19 "native-review-cache-test",
20);
21​
22function makeComment(text: string): ReviewInlineComment {
23 return {
24 id: "comment-1",
25 sectionId: "git:working-tree",
26 sectionTitle: "Dirty worktree",
27 filePath: "example.ts",
28 startIndex: 0,
29 endIndex: 0,
30 rangeLabel: "-1",
31 text,
32 diff: "@@ -1,1 +1,0 @@\n-const before = 1;",
33 };
35​
36function buildInput(comments: BuildNativeReviewDiffDataInput["comments"]) {
37 return { parsedDiff, comments } satisfies BuildNativeReviewDiffDataInput;
39​
40describe("getCachedNativeReviewDiffData", () => {
41 it("reuses the row model for equivalent empty comment arrays", () => {
42 const first = getCachedNativeReviewDiffData(buildInput([]));
43 const second = getCachedNativeReviewDiffData(buildInput([]));
44​
45 expect(second).toBe(first);
46 });
47​
48 it("reuses equivalent comment contents and invalidates changed comments", () => {
49 const first = getCachedNativeReviewDiffData(buildInput([makeComment("First")]));
50 const equivalent = getCachedNativeReviewDiffData(buildInput([makeComment("First")]));
51 const changed = getCachedNativeReviewDiffData(buildInput([makeComment("Changed")]));
52​
53 expect(equivalent).toBe(first);
54 expect(changed).not.toBe(first);
55 });
56});