forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouteIntegration.test.ts
More file actions
258 lines (225 loc) · 8.18 KB
/
Copy pathrouteIntegration.test.ts
File metadata and controls
258 lines (225 loc) · 8.18 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import { describe, expect, it } from "vitest";
import { routeCatalog } from "./routeCatalog";
/**
* Integration tests that validate the synchronization between:
* 1. The route catalog (routeCatalog.ts)
* 2. The router definition (main.tsx)
* 3. The navigation components (SIdebar.tsx, etc.)
*
* These tests ensure that routes defined in main.tsx are documented in the catalog
* and that navigation components properly consume the catalog.
*/
describe("Route Catalog Integration - Router and Navigation Sync", () => {
describe("Router Integration", () => {
it("should cover all routes from main.tsx", () => {
/**
* Main.tsx routes (as of implementation):
* - / (home)
* - /dashboard
* - /split/:id
* - /analytics
* - /split-groups
* - /history
* - /pay
* - /create-split
* - /calculator
* - /notifications
* - /drafts
*/
const expectedRoutePaths = [
"/",
"/dashboard",
"/split/:id",
"/analytics",
"/split-groups",
"/history",
"/pay",
"/create-split",
"/calculator",
"/notifications",
"/drafts",
];
const catalogPaths = routeCatalog.map((r) => r.path);
expectedRoutePaths.forEach((path) => {
expect(catalogPaths).toContain(
path,
`Route ${path} from main.tsx not found in catalog`,
);
});
});
it("should have all catalog routes be either in or can be added to router", () => {
// This validates that the catalog doesn't reference routes that don't exist
// or are planned to be added
routeCatalog.forEach((route) => {
expect(route.path).toBeTruthy();
expect(route.id).toBeTruthy();
// Path should be valid React Router format
expect(route.path).toMatch(/^\//);
});
});
});
describe("Navigation Synchronization", () => {
it("should ensure all visible nav routes exist in catalog", () => {
// When SIdebar.tsx calls getNavigationRoutes(), each route should be valid
const navMandatoryRoutes = ["home", "dashboard"];
navMandatoryRoutes.forEach((id) => {
const route = routeCatalog.find((r) => r.id === id);
expect(route).toBeDefined("Navigation route not in catalog: " + id);
expect(route?.showInNavigation).toBe(
true,
"Navigation route should be marked as visible: " + id,
);
});
});
it("should have valid path-to-label mappings for navigation", () => {
const navRoutes = routeCatalog.filter((r) => r.showInNavigation);
navRoutes.forEach((route) => {
// Each nav route should have:
expect(route.path).toBeTruthy();
expect(route.label).toBeTruthy();
// Labels should be suitable for display (not just the path)
expect(route.label).not.toEqual(route.path);
});
});
it("should maintain backward compatibility with ROUTES constant", () => {
// constants/routes.ts now derives from catalog
// This test ensures the transformation maintains data integrity
const navRoutes = routeCatalog.filter((r) => r.showInNavigation);
const expectedRoutesFormat = navRoutes.map((route) => ({
to: route.path,
label: route.label,
}));
// Each expected route should map correctly
expectedRoutesFormat.forEach((route) => {
expect(route.to).toBeTruthy();
expect(route.label).toBeTruthy();
expect(route.to).toMatch(/^\//);
});
});
});
describe("Primary Page Coverage", () => {
it("should have documentation for all primary pages", () => {
const primaryPages = [
"home",
"dashboard",
"analytics",
"split-groups",
"history",
"drafts",
"notifications",
];
primaryPages.forEach((id) => {
const route = routeCatalog.find((r) => r.id === id);
expect(route).toBeDefined(`Primary page missing: ${id}`);
expect(route?.label).toBeTruthy();
expect(route?.showInNavigation).toBe(true);
});
});
it("should have non-primary routes properly hidden from navigation", () => {
const hiddenRoutes = routeCatalog.filter(
(r) => !r.showInNavigation && r.id !== "home",
);
expect(hiddenRoutes.length).toBeGreaterThan(
0,
"Should have at least some routes hidden from navigation",
);
hiddenRoutes.forEach((route) => {
expect(route.showInNavigation).toBe(false);
expect(route.path).toBeDefined();
});
});
});
describe("Route Metadata Consistency", () => {
it("should assign meaningful IDs", () => {
routeCatalog.forEach((route) => {
// IDs should be kebab-case and lowercase
expect(route.id).toMatch(/^[a-z][a-z0-9-]*$/);
});
});
it("should use consistent label formatting", () => {
routeCatalog.forEach((route) => {
// Labels should be title-cased and human-readable
expect(route.label).toMatch(/^[A-Z]/);
// No trailing slashes or special path characters
expect(route.label).not.toMatch(/[\/]/);
});
});
it("should have complete dynamic route specifications", () => {
const dynamicRoutes = routeCatalog.filter((r) => r.path.includes(":"));
expect(dynamicRoutes.length).toBeGreaterThan(
0,
"Should have at least one dynamic route",
);
dynamicRoutes.forEach((route) => {
// Dynamic routes should have meaningful IDs
expect(route.id).toContain("-");
// Should not be in navigation (can't link to dynamic routes)
expect(route.showInNavigation).toBe(false);
});
});
});
describe("Acceptance Criteria Validation", () => {
it("should have one frontend-owned route catalog for labels, paths, and visibility", () => {
// The source of truth exists
expect(routeCatalog).toBeDefined();
expect(routeCatalog.length).toBeGreaterThan(0);
// It includes all necessary metadata
routeCatalog.forEach((route) => {
expect(route.label).toBeTruthy(); // labels ✓
expect(route.path).toBeTruthy(); // paths ✓
expect(typeof route.showInNavigation).toBe("boolean"); // visibility ✓
});
});
it("should have tests that nav links match registered routes", () => {
// This test file itself validates this
const allPaths = routeCatalog.map((r) => r.path);
const uniquePaths = new Set(allPaths);
// All routes should have unique paths
expect(uniquePaths.size).toBe(allPaths.length);
// Navigation routes should be a subset of all routes
const navRoutes = routeCatalog.filter((r) => r.showInNavigation);
navRoutes.forEach((navRoute) => {
const found = allPaths.includes(navRoute.path);
expect(found).toBe(true);
});
});
it("should have tests for route metadata covering all primary pages intentionally", () => {
// This test validates the coverage
const requiredPrimaryPages = [
"home",
"dashboard",
"analytics",
"split-groups",
"history",
"drafts",
"notifications",
];
const catalogIds = routeCatalog.map((r) => r.id);
requiredPrimaryPages.forEach((id) => {
expect(catalogIds).toContain(
id,
`Primary page ${id} not in catalog`,
);
});
});
});
describe("Route Discovery and Lookup", () => {
it("should be discoverable by path from navigation", () => {
const navRoutes = routeCatalog.filter((r) => r.showInNavigation);
navRoutes.forEach((route) => {
// Each navigation route should be findable by its path
const found = routeCatalog.some(
(r) => r.path === route.path && r.id === route.id,
);
expect(found).toBe(true);
});
});
it("should support route parameter patterns", () => {
// Dynamic routes like /split/:id should be properly defined
const splitRoute = routeCatalog.find((r) => r.id === "split-detail");
expect(splitRoute).toBeDefined();
expect(splitRoute?.path).toContain(":");
expect(splitRoute?.showInNavigation).toBe(false);
});
});
});