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

nativeReviewDiffAdapter.test.ts

98 lines3.2 KB

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