gitforest 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +24 -4
  3. package/src/github/auth.ts +3 -3
  4. package/src/utils/debug.ts +4 -4
  5. package/.bunignore +0 -7
  6. package/.github/workflows/ci.yml +0 -73
  7. package/CLAUDE.md +0 -111
  8. package/CONTRIBUTING.md +0 -145
  9. package/bun.lock +0 -267
  10. package/bunfig.toml +0 -15
  11. package/cli +0 -0
  12. package/docs/ai/IMPROVEMENT_PLAN.md +0 -341
  13. package/docs/ai/VERIFICATION_REPORT.md +0 -87
  14. package/docs/ai/architecture.md +0 -169
  15. package/docs/ai/checks/check-2025-12-02-tests.md +0 -40
  16. package/docs/ai/checks/check-2025-12-02.md +0 -55
  17. package/docs/ai/checks/test-verification-report.md +0 -85
  18. package/docs/ai/implementation-guide.md +0 -776
  19. package/docs/ai/research/gitty-codebase-analysis.md +0 -221
  20. package/docs/ai/tickets/GENERAL-sitrep.md +0 -30
  21. package/docs/ai/tickets/TASK-database-tests-sitrep.md +0 -25
  22. package/docs/ai/tickets/TASK-deprecated-functions-sitrep.md +0 -28
  23. package/docs/ai/tickets/TASK-detail-modal-sitrep.md +0 -28
  24. package/docs/ai/tickets/TASK-filter-overlay-sitrep.md +0 -24
  25. package/docs/ai/tickets/TASK-github-service-sitrep.md +0 -32
  26. package/docs/ai/tickets/TASK-github-token-sitrep.md +0 -51
  27. package/docs/ai/tickets/TASK-hascommits-sitrep.md +0 -35
  28. package/docs/ai/tickets/TASK-keybindings-sitrep.md +0 -26
  29. package/docs/ai/tickets/TASK-layout-sitrep.md +0 -25
  30. package/docs/ai/tickets/TASK-markdown-sitrep.md +0 -28
  31. package/docs/ai/tickets/TASK-project-item-sitrep.md +0 -79
  32. package/docs/ai/tickets/TASK-sitrep.md +0 -28
  33. package/docs/ai/tickets/TASK-state-sitrep.md +0 -26
  34. package/docs/ai/tickets/TASK-types-sitrep.md +0 -25
  35. package/docs/ai/tickets/TASK-unified-item-fix-sitrep.md +0 -26
  36. package/docs/ai/tickets/TKT-001-sitrep.md +0 -24
  37. package/docs/ai/tickets/TKT-002-sitrep.md +0 -25
  38. package/docs/ai/tickets/TKT-003-git-service-refactoring-complete.md +0 -46
  39. package/docs/ai/tickets/TKT-003-git-service-refactoring-plan.md +0 -135
  40. package/docs/ai/tickets/TKT-003-sitrep.md +0 -26
  41. package/docs/ai/tickets/TKT-004-sitrep.md +0 -27
  42. package/docs/ai/tickets/TKT-005-sitrep.md +0 -25
  43. package/docs/ai/tickets/TKT-006-sitrep.md +0 -26
  44. package/docs/ai/tickets/TKT-007-sitrep.md +0 -30
  45. package/docs/ai/tickets/TKT-008-sitrep.md +0 -32
  46. package/docs/ai/tickets/TKT-009-sitrep.md +0 -27
  47. package/docs/ai/tickets/TKT-010-sitrep.md +0 -27
  48. package/docs/ai/tickets/TKT-011-sitrep.md +0 -26
  49. package/docs/ai/tickets/TKT-012-sitrep.md +0 -25
  50. package/docs/ai/tickets/sitreps/TASK-actions-sitrep.md +0 -28
  51. package/docs/ai/tickets/sitreps/TASK-actions-test-sitrep.md +0 -25
  52. package/docs/ai/tickets/sitreps/TASK-app-integration-sitrep.md +0 -25
  53. package/docs/ai/tickets/sitreps/TASK-background-fetch-sitrep.md +0 -24
  54. package/docs/ai/tickets/sitreps/TASK-background-fetch-test-sitrep.md +0 -29
  55. package/docs/ai/tickets/sitreps/TASK-batch-tests-sitrep.md +0 -29
  56. package/docs/ai/tickets/sitreps/TASK-bun-test-sitrep.md +0 -26
  57. package/docs/ai/tickets/sitreps/TASK-cache-tests-sitrep.md +0 -30
  58. package/docs/ai/tickets/sitreps/TASK-cli-tests-sitrep.md +0 -28
  59. package/docs/ai/tickets/sitreps/TASK-clone-error-handling-sitrep.md +0 -26
  60. package/docs/ai/tickets/sitreps/TASK-commands-tests-sitrep.md +0 -25
  61. package/docs/ai/tickets/sitreps/TASK-component-tests-1-sitrep.md +0 -30
  62. package/docs/ai/tickets/sitreps/TASK-configloader-tests-sitrep.md +0 -25
  63. package/docs/ai/tickets/sitreps/TASK-confirm-dialog-test-sitrep.md +0 -29
  64. package/docs/ai/tickets/sitreps/TASK-coverage-sitrep.md +0 -95
  65. package/docs/ai/tickets/sitreps/TASK-database-tests-summary.md +0 -61
  66. package/docs/ai/tickets/sitreps/TASK-error-boundary-sitrep.md +0 -30
  67. package/docs/ai/tickets/sitreps/TASK-error-tests-sitrep.md +0 -27
  68. package/docs/ai/tickets/sitreps/TASK-errors-tests-sitrep.md +0 -25
  69. package/docs/ai/tickets/sitreps/TASK-extract-reducer-sitrep.md +0 -27
  70. package/docs/ai/tickets/sitreps/TASK-filter-overlay-test-sitrep.md +0 -25
  71. package/docs/ai/tickets/sitreps/TASK-final-verification-sitrep.md +0 -28
  72. package/docs/ai/tickets/sitreps/TASK-fix-all-tests-sitrep.md +0 -25
  73. package/docs/ai/tickets/sitreps/TASK-fix-hooks-sitrep.md +0 -26
  74. package/docs/ai/tickets/sitreps/TASK-fix-remaining-tests-sitrep.md +0 -25
  75. package/docs/ai/tickets/sitreps/TASK-fix-test-failures-sitrep.md +0 -26
  76. package/docs/ai/tickets/sitreps/TASK-fix-tests-sitrep.md +0 -24
  77. package/docs/ai/tickets/sitreps/TASK-formatters-tests-sitrep.md +0 -25
  78. package/docs/ai/tickets/sitreps/TASK-git-timeouts-sitrep.md +0 -29
  79. package/docs/ai/tickets/sitreps/TASK-github-cache-test-sitrep.md +0 -25
  80. package/docs/ai/tickets/sitreps/TASK-githubcli-tests-sitrep.md +0 -24
  81. package/docs/ai/tickets/sitreps/TASK-gitstatus-tests-sitrep.md +0 -24
  82. package/docs/ai/tickets/sitreps/TASK-hooks-isolation-sitrep.md +0 -27
  83. package/docs/ai/tickets/sitreps/TASK-keybindings-tests-sitrep.md +0 -25
  84. package/docs/ai/tickets/sitreps/TASK-layout-tests-sitrep.md +0 -25
  85. package/docs/ai/tickets/sitreps/TASK-mock-factories-sitrep.md +0 -27
  86. package/docs/ai/tickets/sitreps/TASK-modal-tests-sitrep.md +0 -32
  87. package/docs/ai/tickets/sitreps/TASK-processbatch-fix-sitrep.md +0 -27
  88. package/docs/ai/tickets/sitreps/TASK-projectlist-tests-sitrep.md +0 -30
  89. package/docs/ai/tickets/sitreps/TASK-projectutils-tests-sitrep.md +0 -25
  90. package/docs/ai/tickets/sitreps/TASK-scanner-tests-sitrep.md +0 -29
  91. package/docs/ai/tickets/sitreps/TASK-select-all-sitrep.md +0 -25
  92. package/docs/ai/tickets/sitreps/TASK-shell-error-handling-sitrep.md +0 -27
  93. package/docs/ai/tickets/sitreps/TASK-store-tests-sitrep.md +0 -25
  94. package/docs/ai/tickets/sitreps/TASK-test-fixes-sitrep.md +0 -26
  95. package/docs/ai/tickets/sitreps/TASK-test-summary-sitrep.md +0 -25
  96. package/docs/ai/tickets/sitreps/TASK-test-verification-sitrep.md +0 -27
  97. package/docs/ai/tickets/sitreps/TASK-testsuite-sitrep.md +0 -75
  98. package/docs/ai/tickets/sitreps/TASK-unified-reducer-tests-sitrep.md +0 -29
  99. package/docs/ai/tickets/sitreps/TASK-unified-repos-test-sitrep.md +0 -29
  100. package/docs/ai/tickets/sitreps/TASK-unified-tests-sitrep.md +0 -25
  101. package/docs/ai/tickets/sitreps/TASK-useprojects-tests-sitrep.md +0 -25
  102. package/docs/ai/tickets/sitreps/TASK-utility-tests-sitrep.md +0 -32
  103. package/docs/ai/tickets/sitreps/TKT-003-git-service-refactoring-sitrep.md +0 -64
  104. package/docs/ai/tkt-001-fix-database-error.md +0 -217
  105. package/docs/ai/ui-enhancement-plan.md +0 -562
  106. package/test/integration/app.isolated.tsx +0 -240
  107. package/test/integration/cli-commands.test.ts +0 -287
  108. package/test/integration/cli-validation.test.ts +0 -264
  109. package/test/integration/git-operations.test.ts +0 -218
  110. package/test/integration/scanner.test.ts +0 -228
  111. package/test/preload.ts +0 -18
  112. package/test/unit/cli/commands.test.ts +0 -13
  113. package/test/unit/cli/formatters.test.ts +0 -1116
  114. package/test/unit/cli/github-commands.test.ts +0 -12
  115. package/test/unit/components/CloneDialog.test.tsx +0 -240
  116. package/test/unit/components/ColumnHeader.test.tsx +0 -128
  117. package/test/unit/components/CommandPalette.test.tsx +0 -355
  118. package/test/unit/components/ConfirmDialog.test.tsx +0 -111
  119. package/test/unit/components/ErrorBoundary.test.tsx +0 -139
  120. package/test/unit/components/FilterBar.test.tsx +0 -43
  121. package/test/unit/components/FilterOptionsOverlay.test.tsx +0 -197
  122. package/test/unit/components/HelpOverlay.test.tsx +0 -90
  123. package/test/unit/components/Layout.test.tsx +0 -328
  124. package/test/unit/components/MarkdownRenderer.test.tsx +0 -45
  125. package/test/unit/components/ProgressBar.test.tsx +0 -138
  126. package/test/unit/components/ProjectItem.test.tsx +0 -182
  127. package/test/unit/components/ProjectList.test.tsx +0 -311
  128. package/test/unit/components/RepoDetailModal.test.tsx +0 -445
  129. package/test/unit/components/StatusBar.test.tsx +0 -112
  130. package/test/unit/components/UnifiedProjectItem.test.tsx +0 -618
  131. package/test/unit/components/ViewModeIndicator.test.tsx +0 -137
  132. package/test/unit/components/test-utils.tsx +0 -63
  133. package/test/unit/config/loader.test.ts +0 -692
  134. package/test/unit/db/database.test.ts +0 -978
  135. package/test/unit/db/index.test.ts +0 -314
  136. package/test/unit/fixtures/setup.ts +0 -186
  137. package/test/unit/git/commands-untested.test.ts +0 -205
  138. package/test/unit/git/commands.test.ts +0 -269
  139. package/test/unit/git/operations.test.ts +0 -322
  140. package/test/unit/git/status.test.ts +0 -219
  141. package/test/unit/github/auth.test.ts +0 -317
  142. package/test/unit/github/cache.test.ts +0 -1028
  143. package/test/unit/github/cli.test.ts +0 -135
  144. package/test/unit/github/unified.test.ts +0 -1201
  145. package/test/unit/graceful-shutdown.test.ts +0 -83
  146. package/test/unit/hooks/useBackgroundFetch.test.tsx +0 -239
  147. package/test/unit/hooks/useConfirmDialogActions.test.tsx +0 -81
  148. package/test/unit/hooks/useKeyBindings.isolated.ts +0 -715
  149. package/test/unit/hooks/useProjects.test.tsx +0 -186
  150. package/test/unit/hooks/useUnifiedRepos-simple.test.tsx +0 -115
  151. package/test/unit/hooks/useUnifiedRepos.test.tsx +0 -177
  152. package/test/unit/mocks/config.ts +0 -109
  153. package/test/unit/mocks/git-service.ts +0 -274
  154. package/test/unit/mocks/github-service.ts +0 -250
  155. package/test/unit/mocks/index.ts +0 -72
  156. package/test/unit/mocks/project.ts +0 -148
  157. package/test/unit/mocks/state-mocks.ts +0 -187
  158. package/test/unit/mocks/unified.ts +0 -169
  159. package/test/unit/operations/batch.test.ts +0 -216
  160. package/test/unit/operations/commands.test.ts +0 -550
  161. package/test/unit/scanner/errors.test.ts +0 -297
  162. package/test/unit/scanner/index.test.ts +0 -1011
  163. package/test/unit/scanner/markers.test.ts +0 -150
  164. package/test/unit/scanner/submodules.test.ts +0 -99
  165. package/test/unit/services/git-errors.test.ts +0 -190
  166. package/test/unit/services/git.test.ts +0 -442
  167. package/test/unit/services/github-errors.test.ts +0 -293
  168. package/test/unit/services/github.test.ts +0 -200
  169. package/test/unit/state/actions.test.ts +0 -217
  170. package/test/unit/state/reducer.test.ts +0 -745
  171. package/test/unit/state/store.test.tsx +0 -711
  172. package/test/unit/types/commands.test.ts +0 -220
  173. package/test/unit/types/schema.test.ts +0 -179
  174. package/test/unit/utils/array.test.ts +0 -73
  175. package/test/unit/utils/debug.test.ts +0 -23
  176. package/test/unit/utils/errors.test.ts +0 -295
  177. package/test/unit/utils/markdown.test.ts +0 -163
  178. package/test/unit/utils/project-utils.test.ts +0 -756
  179. package/test/unit/utils/rate-limiter.test.ts +0 -256
  180. package/test/unit/utils/retry.test.ts +0 -165
  181. package/test/unit/utils/strip-ansi.ts +0 -13
  182. package/test/unit/utils/timeout.test.ts +0 -93
  183. package/tsconfig.json +0 -29
@@ -1,745 +0,0 @@
1
- import { describe, test, expect } from "bun:test";
2
- import type { UnifiedAppState, UnifiedAppAction, Project, ViewMode, CloneDialogState, DetailModalState, GitHubRepoInfo, UnifiedRepo, QuickFilter } from "../../../src/types/index.ts";
3
- import { appReducer, initialState } from "../../../src/state/reducer.ts";
4
-
5
- // Create a test initial state (can be customized for testing)
6
- function createInitialState(): UnifiedAppState {
7
- return { ...initialState };
8
- }
9
-
10
- function createMockProject(overrides?: Partial<Project>): Project {
11
- return {
12
- id: "test-id",
13
- name: "test-project",
14
- path: "/test/project",
15
- type: "git",
16
- projectMarker: null,
17
- status: null,
18
- submodule: null,
19
- lastScanned: new Date(),
20
- lastModified: null,
21
- ...overrides,
22
- };
23
- }
24
-
25
- function createMockGitHubRepo(overrides?: Partial<GitHubRepoInfo>): GitHubRepoInfo {
26
- return {
27
- name: "test-repo",
28
- fullName: "user/test-repo",
29
- owner: "user",
30
- description: "Test repository",
31
- htmlUrl: "https://github.com/user/test-repo",
32
- sshUrl: "git@github.com:user/test-repo.git",
33
- cloneUrl: "https://github.com/user/test-repo.git",
34
- isPrivate: false,
35
- isArchived: false,
36
- isFork: false,
37
- pushedAt: new Date(),
38
- updatedAt: new Date(),
39
- defaultBranch: "main",
40
- language: "TypeScript",
41
- size: 1000,
42
- ...overrides,
43
- };
44
- }
45
-
46
- function createMockUnifiedRepo(overrides?: Partial<UnifiedRepo>): UnifiedRepo {
47
- return {
48
- id: "test-repo-id",
49
- name: "test-repo",
50
- source: "both",
51
- local: null,
52
- github: createMockGitHubRepo(),
53
- isCloned: false,
54
- isOnGitHub: true,
55
- localPath: null,
56
- ...overrides,
57
- };
58
- }
59
-
60
- describe("appReducer", () => {
61
- describe("SET_PROJECTS", () => {
62
- test("sets projects array", () => {
63
- const state = createInitialState();
64
- const projects = [createMockProject({ id: "1" }), createMockProject({ id: "2" })];
65
-
66
- const newState = appReducer(state, { type: "SET_PROJECTS", payload: projects });
67
-
68
- expect(newState.projects).toHaveLength(2);
69
- expect(newState.projects[0]?.id).toBe("1");
70
- });
71
-
72
- test("adjusts cursor if out of bounds", () => {
73
- const state = { ...createInitialState(), cursorIndex: 5 };
74
- const projects = [createMockProject()];
75
-
76
- const newState = appReducer(state, { type: "SET_PROJECTS", payload: projects });
77
-
78
- expect(newState.cursorIndex).toBe(0);
79
- });
80
-
81
- test("keeps cursor in bounds", () => {
82
- const state = { ...createInitialState(), cursorIndex: 1 };
83
- const projects = [createMockProject({ id: "1" }), createMockProject({ id: "2" }), createMockProject({ id: "3" })];
84
-
85
- const newState = appReducer(state, { type: "SET_PROJECTS", payload: projects });
86
-
87
- expect(newState.cursorIndex).toBe(1);
88
- });
89
- });
90
-
91
- describe("SET_LOADING", () => {
92
- test("sets loading true", () => {
93
- const state = { ...createInitialState(), isLoading: false };
94
- const newState = appReducer(state, { type: "SET_LOADING", payload: true });
95
- expect(newState.isLoading).toBe(true);
96
- });
97
-
98
- test("sets loading false", () => {
99
- const state = createInitialState();
100
- const newState = appReducer(state, { type: "SET_LOADING", payload: false });
101
- expect(newState.isLoading).toBe(false);
102
- });
103
- });
104
-
105
- describe("SET_ERROR", () => {
106
- test("sets error message", () => {
107
- const state = createInitialState();
108
- const newState = appReducer(state, { type: "SET_ERROR", payload: "Test error" });
109
- expect(newState.error).toBe("Test error");
110
- });
111
-
112
- test("clears error message", () => {
113
- const state = { ...createInitialState(), error: "Previous error" };
114
- const newState = appReducer(state, { type: "SET_ERROR", payload: null });
115
- expect(newState.error).toBeNull();
116
- });
117
- });
118
-
119
- describe("SET_MESSAGE", () => {
120
- test("sets message", () => {
121
- const state = createInitialState();
122
- const newState = appReducer(state, { type: "SET_MESSAGE", payload: "Test message" });
123
- expect(newState.message).toBe("Test message");
124
- });
125
-
126
- test("clears message", () => {
127
- const state = { ...createInitialState(), message: "Previous message" };
128
- const newState = appReducer(state, { type: "SET_MESSAGE", payload: null });
129
- expect(newState.message).toBeNull();
130
- });
131
- });
132
-
133
- describe("MOVE_CURSOR", () => {
134
- test("uses unifiedRepos length for cursor bounds when available", () => {
135
- const repos = [
136
- { id: "1", name: "repo1", source: "local" as const, local: createMockProject({ id: "1" }), github: null, isCloned: true, isOnGitHub: false, localPath: "/path1" },
137
- { id: "2", name: "repo2", source: "local" as const, local: createMockProject({ id: "2" }), github: null, isCloned: true, isOnGitHub: false, localPath: "/path2" },
138
- ] as UnifiedRepo[];
139
- const state = { ...createInitialState(), unifiedRepos: repos };
140
-
141
- const newState = appReducer(state, { type: "MOVE_CURSOR", payload: 1 });
142
-
143
- expect(newState.cursorIndex).toBe(1);
144
- });
145
-
146
- test("clamps cursor at minimum (0)", () => {
147
- const state = createInitialState();
148
-
149
- const newState = appReducer(state, { type: "MOVE_CURSOR", payload: -5 });
150
-
151
- expect(newState.cursorIndex).toBe(0);
152
- });
153
-
154
- test("clamps cursor at maximum", () => {
155
- const state = createInitialState();
156
-
157
- const newState = appReducer(state, { type: "MOVE_CURSOR", payload: 10 });
158
-
159
- expect(newState.cursorIndex).toBe(0); // unifiedRepos is empty, so clamped to 0
160
- });
161
- });
162
-
163
- describe("TOGGLE_SELECTION", () => {
164
- test("adds index to selection", () => {
165
- const state = createInitialState();
166
-
167
- const newState = appReducer(state, { type: "TOGGLE_SELECTION", payload: 0 });
168
-
169
- expect(newState.selectedIndices.has(0)).toBe(true);
170
- });
171
-
172
- test("removes index from selection", () => {
173
- const state = { ...createInitialState(), selectedIndices: new Set([0, 1, 2]) };
174
-
175
- const newState = appReducer(state, { type: "TOGGLE_SELECTION", payload: 1 });
176
-
177
- expect(newState.selectedIndices.has(1)).toBe(false);
178
- expect(newState.selectedIndices.has(0)).toBe(true);
179
- expect(newState.selectedIndices.has(2)).toBe(true);
180
- });
181
- });
182
-
183
- describe("SELECT_ALL", () => {
184
- test("selects all unified repos", () => {
185
- const repos = [createMockUnifiedRepo({ id: "1" }), createMockUnifiedRepo({ id: "2" }), createMockUnifiedRepo({ id: "3" })];
186
- const state = { ...createInitialState(), unifiedRepos: repos };
187
-
188
- const newState = appReducer(state, { type: "SELECT_ALL" });
189
-
190
- expect(newState.selectedIndices.size).toBe(3);
191
- expect(newState.selectedIndices.has(0)).toBe(true);
192
- expect(newState.selectedIndices.has(1)).toBe(true);
193
- expect(newState.selectedIndices.has(2)).toBe(true);
194
- });
195
- });
196
-
197
- describe("DESELECT_ALL", () => {
198
- test("clears all selections", () => {
199
- const state = { ...createInitialState(), selectedIndices: new Set([0, 1, 2]) };
200
-
201
- const newState = appReducer(state, { type: "DESELECT_ALL" });
202
-
203
- expect(newState.selectedIndices.size).toBe(0);
204
- });
205
- });
206
-
207
- describe("SET_FILTER", () => {
208
- test("sets filter text", () => {
209
- const state = createInitialState();
210
-
211
- const newState = appReducer(state, { type: "SET_FILTER", payload: "test" });
212
-
213
- expect(newState.filterText).toBe("test");
214
- });
215
-
216
- test("resets cursor to 0", () => {
217
- const state = { ...createInitialState(), cursorIndex: 5 };
218
-
219
- const newState = appReducer(state, { type: "SET_FILTER", payload: "test" });
220
-
221
- expect(newState.cursorIndex).toBe(0);
222
- });
223
- });
224
-
225
- describe("SET_QUICK_FILTER", () => {
226
- test("sets quick filter", () => {
227
- const state = createInitialState();
228
-
229
- const newState = appReducer(state, { type: "SET_QUICK_FILTER", payload: "dirty" });
230
-
231
- expect(newState.quickFilter).toBe("dirty");
232
- });
233
-
234
- test("resets cursor and clears selection", () => {
235
- const state = {
236
- ...createInitialState(),
237
- cursorIndex: 5,
238
- selectedIndices: new Set([1, 2, 3])
239
- };
240
-
241
- const newState = appReducer(state, { type: "SET_QUICK_FILTER", payload: "all" });
242
-
243
- expect(newState.cursorIndex).toBe(0);
244
- expect(newState.selectedIndices.size).toBe(0);
245
- });
246
- });
247
-
248
- describe("SET_SORT", () => {
249
- test("sets sort field and direction", () => {
250
- const state = createInitialState();
251
-
252
- const newState = appReducer(state, {
253
- type: "SET_SORT",
254
- payload: { by: "name", direction: "asc" },
255
- });
256
-
257
- expect(newState.sortBy).toBe("name");
258
- expect(newState.sortDirection).toBe("asc");
259
- });
260
- });
261
-
262
- describe("CYCLE_SORT", () => {
263
- test("cycles from status to name", () => {
264
- const state = { ...createInitialState(), sortBy: "status" as const };
265
-
266
- const newState = appReducer(state, { type: "CYCLE_SORT" });
267
-
268
- expect(newState.sortBy).toBe("name");
269
- });
270
-
271
- test("cycles from name to branch", () => {
272
- const state = { ...createInitialState(), sortBy: "name" as const };
273
-
274
- const newState = appReducer(state, { type: "CYCLE_SORT" });
275
-
276
- expect(newState.sortBy).toBe("branch");
277
- });
278
-
279
- test("cycles from lastActivity to size", () => {
280
- const state = { ...createInitialState(), sortBy: "lastActivity" as const };
281
-
282
- const newState = appReducer(state, { type: "CYCLE_SORT" });
283
-
284
- expect(newState.sortBy).toBe("size");
285
- });
286
-
287
- test("cycles from forks to lastActivity", () => {
288
- const state = { ...createInitialState(), sortBy: "forks" as const };
289
-
290
- const newState = appReducer(state, { type: "CYCLE_SORT" });
291
-
292
- expect(newState.sortBy).toBe("lastActivity");
293
- });
294
-
295
- test("cycles from size back to status", () => {
296
- const state = { ...createInitialState(), sortBy: "size" as const };
297
-
298
- const newState = appReducer(state, { type: "CYCLE_SORT" });
299
-
300
- expect(newState.sortBy).toBe("status");
301
- });
302
- });
303
-
304
- describe("SET_MODE", () => {
305
- test("sets mode to filter", () => {
306
- const state = createInitialState();
307
-
308
- const newState = appReducer(state, { type: "SET_MODE", payload: "filter" });
309
-
310
- expect(newState.mode).toBe("filter");
311
- });
312
-
313
- test("sets mode to help", () => {
314
- const state = createInitialState();
315
-
316
- const newState = appReducer(state, { type: "SET_MODE", payload: "help" });
317
-
318
- expect(newState.mode).toBe("help");
319
- });
320
-
321
- test("sets mode back to normal", () => {
322
- const state = { ...createInitialState(), mode: "filter" as const };
323
-
324
- const newState = appReducer(state, { type: "SET_MODE", payload: "normal" });
325
-
326
- expect(newState.mode).toBe("normal");
327
- });
328
- });
329
-
330
- describe("START_ACTION / END_ACTION / UPDATE_PROGRESS", () => {
331
- test("starts action", () => {
332
- const state = createInitialState();
333
-
334
- const newState = appReducer(state, { type: "START_ACTION", payload: "Pulling" });
335
-
336
- expect(newState.actionInProgress).toBe("Pulling");
337
- expect(newState.actionProgress).toBeNull();
338
- });
339
-
340
- test("ends action", () => {
341
- const state = { ...createInitialState(), actionInProgress: "Pulling" };
342
-
343
- const newState = appReducer(state, { type: "END_ACTION" });
344
-
345
- expect(newState.actionInProgress).toBeNull();
346
- expect(newState.actionProgress).toBeNull();
347
- });
348
-
349
- test("updates progress", () => {
350
- const state = { ...createInitialState(), actionInProgress: "Processing" };
351
- const progress = { current: 5, total: 10 };
352
-
353
- const newState = appReducer(state, { type: "UPDATE_PROGRESS", payload: progress });
354
-
355
- expect(newState.actionProgress).toEqual(progress);
356
- });
357
- });
358
-
359
- describe("SET_SCROLL_OFFSET", () => {
360
- test("sets scroll offset", () => {
361
- const state = createInitialState();
362
-
363
- const newState = appReducer(state, { type: "SET_SCROLL_OFFSET", payload: 10 });
364
-
365
- expect(newState.scrollOffset).toBe(10);
366
- });
367
- });
368
-
369
- describe("UPDATE_PROJECT", () => {
370
- test("updates specific project", () => {
371
- const projects = [
372
- createMockProject({ id: "1", name: "old-name" }),
373
- createMockProject({ id: "2", name: "other" }),
374
- ];
375
- const state = { ...createInitialState(), projects };
376
-
377
- const newState = appReducer(state, {
378
- type: "UPDATE_PROJECT",
379
- payload: { id: "1", updates: { name: "new-name" } },
380
- });
381
-
382
- expect(newState.projects[0]?.name).toBe("new-name");
383
- expect(newState.projects[1]?.name).toBe("other");
384
- });
385
-
386
- test("does not modify projects when id not found", () => {
387
- const projects = [createMockProject({ id: "1" })];
388
- const state = { ...createInitialState(), projects };
389
-
390
- const newState = appReducer(state, {
391
- type: "UPDATE_PROJECT",
392
- payload: { id: "nonexistent", updates: { name: "new-name" } },
393
- });
394
-
395
- expect(newState.projects[0]?.name).toBe("test-project");
396
- });
397
- });
398
-
399
- describe("SHOW_CONFIRM_DIALOG / HIDE_CONFIRM_DIALOG", () => {
400
- test("shows confirm dialog", () => {
401
- const state = createInitialState();
402
- const dialog = {
403
- operation: "setup" as const,
404
- title: "Confirm Setup",
405
- message: "Setup these projects?",
406
- items: ["project1", "project2"],
407
- projectPaths: ["/path1", "/path2"],
408
- showVisibilityToggle: false,
409
- };
410
-
411
- const newState = appReducer(state, { type: "SHOW_CONFIRM_DIALOG", payload: dialog });
412
-
413
- expect(newState.mode).toBe("confirm");
414
- expect(newState.confirmDialog).toEqual(dialog);
415
- });
416
-
417
- test("hides confirm dialog", () => {
418
- const state = {
419
- ...createInitialState(),
420
- mode: "confirm" as const,
421
- confirmDialog: {
422
- operation: "setup" as const,
423
- title: "Confirm Setup",
424
- message: "Setup these projects?",
425
- items: ["project1"],
426
- projectPaths: ["/path1"],
427
- showVisibilityToggle: false,
428
- },
429
- };
430
-
431
- const newState = appReducer(state, { type: "HIDE_CONFIRM_DIALOG" });
432
-
433
- expect(newState.mode).toBe("normal");
434
- expect(newState.confirmDialog).toBeNull();
435
- });
436
- });
437
-
438
- describe("Unified View Actions", () => {
439
- describe("SET_VIEW_MODE", () => {
440
- test("sets view mode", () => {
441
- const state = createInitialState();
442
-
443
- const newState = appReducer(state, { type: "SET_VIEW_MODE", payload: "github" });
444
-
445
- expect(newState.viewMode).toBe("github");
446
- });
447
-
448
- test("resets cursor when changing view mode", () => {
449
- const state = { ...createInitialState(), cursorIndex: 5 };
450
-
451
- const newState = appReducer(state, { type: "SET_VIEW_MODE", payload: "local" });
452
-
453
- expect(newState.cursorIndex).toBe(0);
454
- });
455
- });
456
-
457
- describe("SET_GITHUB_REPOS", () => {
458
- test("sets GitHub repos", () => {
459
- const state = createInitialState();
460
- const repos = [
461
- {
462
- name: "repo1",
463
- fullName: "user/repo1",
464
- owner: "user",
465
- description: null,
466
- htmlUrl: "https://github.com/user/repo1",
467
- sshUrl: "git@github.com:user/repo1.git",
468
- cloneUrl: "https://github.com/user/repo1.git",
469
- isPrivate: false,
470
- isArchived: false,
471
- isFork: false,
472
- pushedAt: null,
473
- updatedAt: null,
474
- defaultBranch: "main",
475
- language: "TypeScript",
476
- size: 100,
477
- },
478
- ] as GitHubRepoInfo[];
479
-
480
- const newState = appReducer(state, { type: "SET_GITHUB_REPOS", payload: repos });
481
-
482
- expect(newState.githubRepos).toEqual(repos);
483
- });
484
- });
485
-
486
- describe("SET_UNIFIED_REPOS", () => {
487
- test("sets unified repos", () => {
488
- const state = createInitialState();
489
- const repos = [
490
- {
491
- id: "repo1",
492
- name: "repo1",
493
- source: "both" as const,
494
- local: createMockProject({ id: "repo1" }),
495
- github: null,
496
- isCloned: true,
497
- isOnGitHub: false,
498
- localPath: "/path/to/repo1",
499
- },
500
- ] as UnifiedRepo[];
501
-
502
- const newState = appReducer(state, { type: "SET_UNIFIED_REPOS", payload: repos });
503
-
504
- expect(newState.unifiedRepos).toEqual(repos);
505
- });
506
- });
507
-
508
- describe("SET_GITHUB_LOADING", () => {
509
- test("sets GitHub loading state", () => {
510
- const state = createInitialState();
511
-
512
- const newState = appReducer(state, { type: "SET_GITHUB_LOADING", payload: true });
513
-
514
- expect(newState.isLoadingGitHub).toBe(true);
515
- });
516
- });
517
-
518
- describe("SET_GITHUB_ERROR", () => {
519
- test("sets GitHub error", () => {
520
- const state = createInitialState();
521
-
522
- const newState = appReducer(state, { type: "SET_GITHUB_ERROR", payload: "API Error" });
523
-
524
- expect(newState.githubError).toBe("API Error");
525
- });
526
-
527
- test("clears GitHub error", () => {
528
- const state = { ...createInitialState(), githubError: "Previous Error" };
529
-
530
- const newState = appReducer(state, { type: "SET_GITHUB_ERROR", payload: null });
531
-
532
- expect(newState.githubError).toBeNull();
533
- });
534
- });
535
-
536
- describe("SET_REFRESHING", () => {
537
- test("sets refreshing state", () => {
538
- const state = createInitialState();
539
-
540
- const newState = appReducer(state, { type: "SET_REFRESHING", payload: true });
541
-
542
- expect(newState.isRefreshing).toBe(true);
543
- });
544
- });
545
-
546
- describe("Clone Dialog Actions", () => {
547
- test("shows clone dialog", () => {
548
- const state = createInitialState();
549
- const dialog = {
550
- repos: [],
551
- directories: [],
552
- selectedDirIndex: 0,
553
- useSSH: false,
554
- } as CloneDialogState;
555
-
556
- const newState = appReducer(state, { type: "SHOW_CLONE_DIALOG", payload: dialog });
557
-
558
- expect(newState.mode).toBe("clone");
559
- expect(newState.cloneDialog).toEqual(dialog);
560
- });
561
-
562
- test("hides clone dialog", () => {
563
- const state = {
564
- ...createInitialState(),
565
- mode: "clone" as const,
566
- cloneDialog: {
567
- repos: [],
568
- directories: [],
569
- selectedDirIndex: 0,
570
- useSSH: false,
571
- } as CloneDialogState,
572
- };
573
-
574
- const newState = appReducer(state, { type: "HIDE_CLONE_DIALOG" });
575
-
576
- expect(newState.mode).toBe("normal");
577
- expect(newState.cloneDialog).toBeNull();
578
- });
579
-
580
- test("updates clone dialog", () => {
581
- const state = {
582
- ...createInitialState(),
583
- cloneDialog: {
584
- repos: [],
585
- directories: [],
586
- selectedDirIndex: 0,
587
- useSSH: false,
588
- } as CloneDialogState,
589
- };
590
-
591
- const newState = appReducer(state, {
592
- type: "UPDATE_CLONE_DIALOG",
593
- payload: { selectedDirIndex: 1, useSSH: true }
594
- });
595
-
596
- expect(newState.cloneDialog?.selectedDirIndex).toBe(1);
597
- expect(newState.cloneDialog?.useSSH).toBe(true);
598
- });
599
- });
600
-
601
- describe("Clone Repo Actions", () => {
602
- test("starts clone repo", () => {
603
- const state = createInitialState();
604
-
605
- const newState = appReducer(state, { type: "CLONE_REPO_START", payload: "repo1" });
606
-
607
- expect(newState.actionInProgress).toBe("Cloning repo1...");
608
- expect(newState.actionProgress).toBeNull();
609
- });
610
-
611
- test("completes clone repo", () => {
612
- const repos = [
613
- {
614
- id: "repo1",
615
- name: "repo1",
616
- source: "github" as const,
617
- local: null,
618
- github: null,
619
- isCloned: false,
620
- isOnGitHub: true,
621
- localPath: null,
622
- },
623
- ] as UnifiedRepo[];
624
- const state = { ...createInitialState(), unifiedRepos: repos };
625
-
626
- const newState = appReducer(state, {
627
- type: "CLONE_REPO_COMPLETE",
628
- payload: { id: "repo1", localPath: "/path/to/repo1" }
629
- });
630
-
631
- expect(newState.unifiedRepos[0]?.isCloned).toBe(true);
632
- expect(newState.unifiedRepos[0]?.localPath).toBe("/path/to/repo1");
633
- expect(newState.actionInProgress).toBeNull();
634
- expect(newState.actionProgress).toBeNull();
635
- });
636
-
637
- test("fails clone repo", () => {
638
- const state = createInitialState();
639
-
640
- const newState = appReducer(state, {
641
- type: "CLONE_REPO_FAILED",
642
- payload: { id: "repo1", error: "Permission denied" }
643
- });
644
-
645
- expect(newState.error).toBe("Failed to clone repo1: Permission denied");
646
- expect(newState.actionInProgress).toBeNull();
647
- expect(newState.actionProgress).toBeNull();
648
- });
649
- });
650
-
651
- describe("Detail Modal Actions", () => {
652
- test("shows detail modal", () => {
653
- const state = createInitialState();
654
- const repo = {
655
- id: "repo1",
656
- name: "repo1",
657
- source: "local" as const,
658
- local: createMockProject({ id: "repo1" }),
659
- github: null,
660
- isCloned: true,
661
- isOnGitHub: false,
662
- localPath: "/path/to/repo1",
663
- } as UnifiedRepo;
664
- const modal = {
665
- repo,
666
- readmeContent: null,
667
- readmeLoading: false,
668
- readmeError: null,
669
- readmeScrollOffset: 0,
670
- } as DetailModalState;
671
-
672
- const newState = appReducer(state, { type: "SHOW_DETAIL_MODAL", payload: modal });
673
-
674
- expect(newState.mode).toBe("detail");
675
- expect(newState.detailModal).toEqual(modal);
676
- });
677
-
678
- test("hides detail modal", () => {
679
- const state = {
680
- ...createInitialState(),
681
- mode: "detail" as const,
682
- detailModal: {
683
- repo: {} as UnifiedRepo,
684
- readmeContent: null,
685
- readmeLoading: false,
686
- readmeError: null,
687
- readmeScrollOffset: 0,
688
- } as DetailModalState,
689
- };
690
-
691
- const newState = appReducer(state, { type: "HIDE_DETAIL_MODAL" });
692
-
693
- expect(newState.mode).toBe("normal");
694
- expect(newState.detailModal).toBeNull();
695
- });
696
-
697
- test("updates detail modal", () => {
698
- const state = {
699
- ...createInitialState(),
700
- detailModal: {
701
- repo: {} as UnifiedRepo,
702
- readmeContent: null,
703
- readmeLoading: false,
704
- readmeError: null,
705
- readmeScrollOffset: 0,
706
- } as DetailModalState,
707
- };
708
-
709
- const newState = appReducer(state, {
710
- type: "UPDATE_DETAIL_MODAL",
711
- payload: { readmeLoading: true, readmeScrollOffset: 100 }
712
- });
713
-
714
- expect(newState.detailModal?.readmeLoading).toBe(true);
715
- expect(newState.detailModal?.readmeScrollOffset).toBe(100);
716
- });
717
- });
718
-
719
- describe("SET_LANGUAGE_FILTER", () => {
720
- test("sets language filter", () => {
721
- const state = createInitialState();
722
-
723
- const newState = appReducer(state, { type: "SET_LANGUAGE_FILTER", payload: "TypeScript" });
724
-
725
- expect(newState.languageFilter).toBe("TypeScript");
726
- });
727
-
728
- test("resets cursor when setting language filter", () => {
729
- const state = { ...createInitialState(), cursorIndex: 5 };
730
-
731
- const newState = appReducer(state, { type: "SET_LANGUAGE_FILTER", payload: "JavaScript" });
732
-
733
- expect(newState.cursorIndex).toBe(0);
734
- });
735
-
736
- test("clears language filter", () => {
737
- const state = { ...createInitialState(), languageFilter: "TypeScript" };
738
-
739
- const newState = appReducer(state, { type: "SET_LANGUAGE_FILTER", payload: null });
740
-
741
- expect(newState.languageFilter).toBeNull();
742
- });
743
- });
744
- });
745
- });