Open History to see the last commit
1import { TurnId } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4
5import { ChangedFilesCard, ChangedFilesTree } from "./ChangedFilesTree";
6
7describe("ChangedFilesCard", () => {
8 it("keeps its compact header sticky while preserving singular labels", () => {
9 const markup = renderToStaticMarkup(
10 <ChangedFilesCard
11 turnId={TurnId.make("turn-1")}
12 files={[{ path: "README.md", kind: "modified", additions: 2, deletions: 1 }]}
13 allDirectoriesExpanded
14 resolvedTheme="light"
15 onToggleAllDirectories={() => {}}
16 onOpenTurnDiff={() => {}}
17 />,
18 );
19
20 expect(markup).toContain('class="sticky top-0 z-10');
21 expect(markup).not.toContain("self-start");
22 expect(markup).toContain("whitespace-nowrap");
23 expect(markup).toContain("!size-[22px]");
24 expect(markup).toContain("size-3");
25 expect(markup).toContain('aria-label="Collapse all"');
26 expect(markup).toContain('aria-label="View diff"');
27 expect(markup).toContain("1 changed file");
28 expect(markup).not.toContain("1 changed files");
29 });
30});
31
32describe("ChangedFilesTree", () => {
33 it.each([
34 {
35 name: "a compacted single-chain directory",
36 files: [
37 { path: "apps/web/src/index.ts", kind: "modified", additions: 2, deletions: 1 },
38 { path: "apps/web/src/main.ts", kind: "modified", additions: 3, deletions: 0 },
39 ],
40 visibleLabels: ["apps/web/src"],
41 hiddenLabels: ["index.ts", "main.ts"],
42 },
43 {
44 name: "a branch point after a compacted prefix",
45 files: [
46 {
47 path: "apps/server/src/git/Layers/GitCore.ts",
48 kind: "modified",
49 additions: 4,
50 deletions: 3,
51 },
52 {
53 path: "apps/server/src/provider/Layers/CodexAdapter.ts",
54 kind: "modified",
55 additions: 7,
56 deletions: 2,
57 },
58 ],
59 visibleLabels: ["apps/server/src"],
60 hiddenLabels: ["git", "provider", "GitCore.ts", "CodexAdapter.ts"],
61 },
62 {
63 name: "mixed root files and nested compacted directories",
64 files: [
65 { path: "README.md", kind: "modified", additions: 1, deletions: 0 },
66 { path: "packages/shared/src/git.ts", kind: "modified", additions: 8, deletions: 2 },
67 {
68 path: "packages/contracts/src/orchestration.ts",
69 kind: "modified",
70 additions: 13,
71 deletions: 3,
72 },
73 ],
74 visibleLabels: ["README.md", "packages"],
75 hiddenLabels: ["shared/src", "contracts/src", "git.ts", "orchestration.ts"],
76 },
77 ])(
78 "renders $name collapsed on the first render when collapse-all is active",
79 ({ files, visibleLabels, hiddenLabels }) => {
80 const markup = renderToStaticMarkup(
81 <ChangedFilesTree
82 turnId={TurnId.make("turn-1")}
83 files={files}
84 allDirectoriesExpanded={false}
85 resolvedTheme="light"
86 onOpenTurnDiff={() => {}}
87 />,
88 );
89
90 for (const label of visibleLabels) {
91 expect(markup).toContain(label);
92 }
93 for (const label of hiddenLabels) {
94 expect(markup).not.toContain(label);
95 }
96 },
97 );
98
99 it.each([
100 {
101 name: "a compacted single-chain directory",
102 files: [
103 { path: "apps/web/src/index.ts", kind: "modified", additions: 2, deletions: 1 },
104 { path: "apps/web/src/main.ts", kind: "modified", additions: 3, deletions: 0 },
105 ],
106 visibleLabels: ["apps/web/src", "index.ts", "main.ts"],
107 },
108 {
109 name: "a branch point after a compacted prefix",
110 files: [
111 {
112 path: "apps/server/src/git/Layers/GitCore.ts",
113 kind: "modified",
114 additions: 4,
115 deletions: 3,
116 },
117 {
118 path: "apps/server/src/provider/Layers/CodexAdapter.ts",
119 kind: "modified",
120 additions: 7,
121 deletions: 2,
122 },
123 ],
124 visibleLabels: [
125 "apps/server/src",
126 "git/Layers",
127 "provider/Layers",
128 "GitCore.ts",
129 "CodexAdapter.ts",
130 ],
131 },
132 {
133 name: "mixed root files and nested compacted directories",
134 files: [
135 { path: "README.md", kind: "modified", additions: 1, deletions: 0 },
136 { path: "packages/shared/src/git.ts", kind: "modified", additions: 8, deletions: 2 },
137 {
138 path: "packages/contracts/src/orchestration.ts",
139 kind: "modified",
140 additions: 13,
141 deletions: 3,
142 },
143 ],
144 visibleLabels: [
145 "README.md",
146 "packages",
147 "shared/src",
148 "contracts/src",
149 "git.ts",
150 "orchestration.ts",
151 ],
152 },
153 ])(
154 "renders $name expanded on the first render when expand-all is active",
155 ({ files, visibleLabels }) => {
156 const markup = renderToStaticMarkup(
157 <ChangedFilesTree
158 turnId={TurnId.make("turn-1")}
159 files={files}
160 allDirectoriesExpanded
161 resolvedTheme="light"
162 onOpenTurnDiff={() => {}}
163 />,
164 );
165
166 for (const label of visibleLabels) {
167 expect(markup).toContain(label);
168 }
169 },
170 );
171});