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