-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathChangedFilesTree.test.tsx
More file actions
242 lines (231 loc) · 7.87 KB
/
Copy pathChangedFilesTree.test.tsx
File metadata and controls
242 lines (231 loc) · 7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import { TurnId } from "@t3tools/contracts";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vite-plus/test";
import { ChangedFilesCard, ChangedFilesTree } from "./ChangedFilesTree";
describe("ChangedFilesCard", () => {
it("keeps its compact header sticky while preserving singular labels", () => {
const markup = renderToStaticMarkup(
<ChangedFilesCard
turnId={TurnId.make("turn-1")}
files={[{ path: "README.md", kind: "modified", additions: 2, deletions: 1 }]}
expanded
showCompactPreview={false}
allDirectoriesExpanded
resolvedTheme="light"
onExpandedChange={() => {}}
onToggleAllDirectories={() => {}}
onOpenTurnDiff={() => {}}
/>,
);
expect(markup).toContain('data-changed-files-state="expanded"');
expect(markup).toContain('aria-expanded="true"');
expect(markup).toContain("whitespace-nowrap");
expect(markup).toContain(
'class="group flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden',
);
expect(markup).toContain('class="flex shrink-0 items-center gap-1 whitespace-nowrap');
expect(markup).toContain('class="ml-1 hidden min-w-0 flex-1 truncate');
expect(markup).toContain("@[24rem]/changed-files:inline");
expect(markup).not.toContain("sm:inline");
expect(markup).toContain('class="flex shrink-0 items-center gap-1.5"');
expect(markup).toContain("!size-[22px]");
expect(markup).toContain("size-3");
expect(markup).toContain('aria-label="Collapse all folders"');
expect(markup).toContain('aria-label="Open diff"');
expect(markup).toContain('role="group" aria-label="2 additions, 1 deletions"');
expect(markup).toContain("1 changed file");
expect(markup).not.toContain("1 changed files");
});
it("renders a scope and representative-file preview for a large latest change", () => {
const markup = renderToStaticMarkup(
<ChangedFilesCard
turnId={TurnId.make("turn-1")}
files={[
{ path: "apps/web/src/App.tsx", kind: "modified", additions: 120, deletions: 20 },
{ path: "apps/web/src/App.test.tsx", kind: "modified", additions: 30, deletions: 2 },
{
path: "packages/shared/src/git.ts",
kind: "modified",
additions: 15,
deletions: 4,
},
{ path: "README.md", kind: "modified", additions: 3, deletions: 0 },
]}
expanded={false}
showCompactPreview
allDirectoriesExpanded={false}
resolvedTheme="light"
onExpandedChange={() => {}}
onToggleAllDirectories={() => {}}
onOpenTurnDiff={() => {}}
/>,
);
expect(markup).toContain('data-changed-files-state="preview"');
expect(markup).toContain('aria-expanded="false"');
expect(markup).toContain("apps");
expect(markup).toContain("2 files");
expect(markup).toContain("packages");
expect(markup).toContain("root");
expect(markup).toContain("App.tsx");
expect(markup).toContain("git.ts");
expect(markup).toContain("README.md");
expect(markup).toContain("Show all 4 files");
expect(markup).not.toContain("App.test.tsx");
});
it("keeps older collapsed changes to a one-line receipt", () => {
const markup = renderToStaticMarkup(
<ChangedFilesCard
turnId={TurnId.make("turn-1")}
files={[{ path: "apps/web/src/App.tsx", kind: "modified", additions: 120, deletions: 20 }]}
expanded={false}
showCompactPreview={false}
allDirectoriesExpanded={false}
resolvedTheme="light"
onExpandedChange={() => {}}
onToggleAllDirectories={() => {}}
onOpenTurnDiff={() => {}}
/>,
);
expect(markup).toContain('data-changed-files-state="collapsed"');
expect(markup).toContain("1 changed file");
expect(markup).not.toContain("Show all");
expect(markup).not.toContain("App.tsx");
});
});
describe("ChangedFilesTree", () => {
it.each([
{
name: "a compacted single-chain directory",
files: [
{ path: "apps/web/src/index.ts", kind: "modified", additions: 2, deletions: 1 },
{ path: "apps/web/src/main.ts", kind: "modified", additions: 3, deletions: 0 },
],
visibleLabels: ["apps/web/src"],
hiddenLabels: ["index.ts", "main.ts"],
},
{
name: "a branch point after a compacted prefix",
files: [
{
path: "apps/server/src/git/Layers/GitCore.ts",
kind: "modified",
additions: 4,
deletions: 3,
},
{
path: "apps/server/src/provider/Layers/CodexAdapter.ts",
kind: "modified",
additions: 7,
deletions: 2,
},
],
visibleLabels: ["apps/server/src"],
hiddenLabels: ["git", "provider", "GitCore.ts", "CodexAdapter.ts"],
},
{
name: "mixed root files and nested compacted directories",
files: [
{ path: "README.md", kind: "modified", additions: 1, deletions: 0 },
{ path: "packages/shared/src/git.ts", kind: "modified", additions: 8, deletions: 2 },
{
path: "packages/contracts/src/orchestration.ts",
kind: "modified",
additions: 13,
deletions: 3,
},
],
visibleLabels: ["README.md", "packages"],
hiddenLabels: ["shared/src", "contracts/src", "git.ts", "orchestration.ts"],
},
])(
"renders $name collapsed on the first render when collapse-all is active",
({ files, visibleLabels, hiddenLabels }) => {
const markup = renderToStaticMarkup(
<ChangedFilesTree
turnId={TurnId.make("turn-1")}
files={files}
allDirectoriesExpanded={false}
resolvedTheme="light"
onOpenTurnDiff={() => {}}
/>,
);
for (const label of visibleLabels) {
expect(markup).toContain(label);
}
for (const label of hiddenLabels) {
expect(markup).not.toContain(label);
}
},
);
it.each([
{
name: "a compacted single-chain directory",
files: [
{ path: "apps/web/src/index.ts", kind: "modified", additions: 2, deletions: 1 },
{ path: "apps/web/src/main.ts", kind: "modified", additions: 3, deletions: 0 },
],
visibleLabels: ["apps/web/src", "index.ts", "main.ts"],
},
{
name: "a branch point after a compacted prefix",
files: [
{
path: "apps/server/src/git/Layers/GitCore.ts",
kind: "modified",
additions: 4,
deletions: 3,
},
{
path: "apps/server/src/provider/Layers/CodexAdapter.ts",
kind: "modified",
additions: 7,
deletions: 2,
},
],
visibleLabels: [
"apps/server/src",
"git/Layers",
"provider/Layers",
"GitCore.ts",
"CodexAdapter.ts",
],
},
{
name: "mixed root files and nested compacted directories",
files: [
{ path: "README.md", kind: "modified", additions: 1, deletions: 0 },
{ path: "packages/shared/src/git.ts", kind: "modified", additions: 8, deletions: 2 },
{
path: "packages/contracts/src/orchestration.ts",
kind: "modified",
additions: 13,
deletions: 3,
},
],
visibleLabels: [
"README.md",
"packages",
"shared/src",
"contracts/src",
"git.ts",
"orchestration.ts",
],
},
])(
"renders $name expanded on the first render when expand-all is active",
({ files, visibleLabels }) => {
const markup = renderToStaticMarkup(
<ChangedFilesTree
turnId={TurnId.make("turn-1")}
files={files}
allDirectoriesExpanded
resolvedTheme="light"
onOpenTurnDiff={() => {}}
/>,
);
for (const label of visibleLabels) {
expect(markup).toContain(label);
}
},
);
});