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

nativeReviewDiffAdapter.test.ts

81 lines2.7 KB

1import { describe, expect, it } from "vite-plus/test";
2import { MOBILE_THEME_IDS } from "../../lib/mobileTheme";
3​
4import {
5 createNativeReviewDiffTheme,
6 getCachedNativeReviewDiffData,
7 type BuildNativeReviewDiffDataInput,
8} from "./nativeReviewDiffAdapter";
9import type { ReviewInlineComment } from "./reviewCommentSelection";
10import { buildReviewParsedDiff } from "./reviewModel";
11​
12const parsedDiff = buildReviewParsedDiff(
13 [
14 "diff --git a/example.ts b/example.ts",
15 "--- a/example.ts",
16 "+++ b/example.ts",
17 "@@ -1 +1 @@",
18 "-const before = 1;",
19 "+const after = 2;",
20 ].join("\n"),
21 "native-review-cache-test",
22);
23​
24function makeComment(text: string): ReviewInlineComment {
25 return {
26 id: "comment-1",
27 sectionId: "git:working-tree",
28 sectionTitle: "Dirty worktree",
29 filePath: "example.ts",
30 startIndex: 0,
31 endIndex: 0,
32 rangeLabel: "-1",
33 text,
34 diff: "@@ -1,1 +1,0 @@\n-const before = 1;",
35 };
37​
38function buildInput(comments: BuildNativeReviewDiffDataInput["comments"]) {
39 return { parsedDiff, comments } satisfies BuildNativeReviewDiffDataInput;
41​
42describe("getCachedNativeReviewDiffData", () => {
43 it("reuses the row model for equivalent empty comment arrays", () => {
44 const first = getCachedNativeReviewDiffData(buildInput([]));
45 const second = getCachedNativeReviewDiffData(buildInput([]));
46​
47 expect(second).toBe(first);
48 });
49​
50 it("reuses equivalent comment contents and invalidates changed comments", () => {
51 const first = getCachedNativeReviewDiffData(buildInput([makeComment("First")]));
52 const equivalent = getCachedNativeReviewDiffData(buildInput([makeComment("First")]));
53 const changed = getCachedNativeReviewDiffData(buildInput([makeComment("Changed")]));
54​
55 expect(equivalent).toBe(first);
56 expect(changed).not.toBe(first);
57 });
58});
59​
60describe("createNativeReviewDiffTheme", () => {
61 it("serializes every native color as cross-platform opaque hex", () => {
62 for (const themeId of MOBILE_THEME_IDS) {
63 for (const appearance of ["light", "dark"] as const) {
64 const theme = createNativeReviewDiffTheme(appearance, themeId);
65 for (const color of Object.values(theme)) {
66 expect(color, `${themeId}/${appearance}`).toMatch(/^#[\da-f]{6}$/i);
67 }
68 }
69 }
70 });
71​
72 it("uses the selected app palette for native code surfaces", () => {
73 const standard = createNativeReviewDiffTheme("dark", "t3-code");
74 const iris = createNativeReviewDiffTheme("dark", "iris");
75​
76 expect(iris.background).not.toBe(standard.background);
77 expect(iris.hunkText).not.toBe(standard.hunkText);
78 expect(iris.addBar).toBe(standard.addBar);
79 expect(iris.deleteBar).toBe(standard.deleteBar);
80 });
81});