import { describe, expect, it } from "vite-plus/test"; import { getCachedNativeReviewDiffData, type BuildNativeReviewDiffDataInput,} from "./nativeReviewDiffAdapter";import type { ReviewInlineComment } from "./reviewCommentSelection";import { buildReviewParsedDiff } from "./reviewModel"; const parsedDiff = buildReviewParsedDiff( [ "diff --git a/example.ts b/example.ts", "--- a/example.ts", "+++ b/example.ts", "@@ -1 +1 @@", "-const before = 1;", "+const after = 2;", ].join("\n"), "native-review-cache-test",); function makeComment(text: string): ReviewInlineComment { return { id: "comment-1", sectionId: "git:working-tree", sectionTitle: "Dirty worktree", filePath: "example.ts", startIndex: 0, endIndex: 0, rangeLabel: "-1", text, diff: "@@ -1,1 +1,0 @@\n-const before = 1;", };} function buildInput(comments: BuildNativeReviewDiffDataInput["comments"]) { return { parsedDiff, comments } satisfies BuildNativeReviewDiffDataInput;} describe("getCachedNativeReviewDiffData", () => { it("reuses the row model for equivalent empty comment arrays", () => { const first = getCachedNativeReviewDiffData(buildInput([])); const second = getCachedNativeReviewDiffData(buildInput([])); expect(second).toBe(first); }); it("reuses equivalent comment contents and invalidates changed comments", () => { const first = getCachedNativeReviewDiffData(buildInput([makeComment("First")])); const equivalent = getCachedNativeReviewDiffData(buildInput([makeComment("First")])); const changed = getCachedNativeReviewDiffData(buildInput([makeComment("Changed")])); expect(equivalent).toBe(first); expect(changed).not.toBe(first); });});
import { describe, expect, it } from "vite-plus/test";
import {
getCachedNativeReviewDiffData,
type BuildNativeReviewDiffDataInput,
} from "./nativeReviewDiffAdapter";
import type { ReviewInlineComment } from "./reviewCommentSelection";
import { buildReviewParsedDiff } from "./reviewModel";
const parsedDiff = buildReviewParsedDiff(
[
"diff --git a/example.ts b/example.ts",
"--- a/example.ts",
"+++ b/example.ts",
"@@ -1 +1 @@",
"-const before = 1;",
"+const after = 2;",
].join("\n"),
"native-review-cache-test",
);
function makeComment(text: string): ReviewInlineComment {
return {
id: "comment-1",
sectionId: "git:working-tree",
sectionTitle: "Dirty worktree",
filePath: "example.ts",
startIndex: 0,
endIndex: 0,
rangeLabel: "-1",
text,
diff: "@@ -1,1 +1,0 @@\n-const before = 1;",
};
}
function buildInput(comments: BuildNativeReviewDiffDataInput["comments"]) {
return { parsedDiff, comments } satisfies BuildNativeReviewDiffDataInput;
}
describe("getCachedNativeReviewDiffData", () => {
it("reuses the row model for equivalent empty comment arrays", () => {
const first = getCachedNativeReviewDiffData(buildInput([]));
const second = getCachedNativeReviewDiffData(buildInput([]));
expect(second).toBe(first);
});
it("reuses equivalent comment contents and invalidates changed comments", () => {
const first = getCachedNativeReviewDiffData(buildInput([makeComment("First")]));
const equivalent = getCachedNativeReviewDiffData(buildInput([makeComment("First")]));
const changed = getCachedNativeReviewDiffData(buildInput([makeComment("Changed")]));
expect(equivalent).toBe(first);
expect(changed).not.toBe(first);
});
});