forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

nav-items.test.ts262 lines, 12.8 KiBHistoryRawDownload
1import { moduleVisible, pathActive, primaryNavItems, primaryPathActive, routeLabelKey, routeNavItem, visibleNavGroups, visibleNavItems } from "@/components/layout/nav-items";
2
3test.each([
4 ["student", ["/", "/homework", "/exams"]],
5 ["teacher", ["/", "/management/classes", "/management/student-attendance"]],
6 ["manager", ["/", "/management/students", "/management/classes"]],
7 ["admin", ["/", "/management/students", "/management/classes"]],
8 ["parent", ["/", "/students", "/appointments"]],
9] as const)("%s gets role-specific primary destinations", (role, expected) => {
10 expect(primaryNavItems(role).map((item) => item.to)).toEqual(expected);
11});
12
13test("every mobile tab reuses its sidebar row's icon and label", () => {
14 for (const role of ["student", "parent", "teacher", "manager", "admin"] as const) {
15 const sidebar = visibleNavGroups(role).flatMap((group) => group.items);
16 for (const tab of primaryNavItems(role).slice(1)) {
17 const row = sidebar.find((item) => item.id === tab.id);
18 expect(row?.Icon).toBe(tab.Icon);
19 expect(row?.labelKey).toBe(tab.labelKey);
20 }
21 }
22});
23
24test("invalid role destinations stay hidden", () => {
25 expect(visibleNavItems("teacher").map((item) => item.to)).not.toContain("/admin/users");
26 expect(visibleNavItems("student").map((item) => item.to)).not.toContain("/admin/users");
27 expect(visibleNavItems("parent").map((item) => item.to)).not.toContain("/management/staff-work");
28});
29
30test("admin's sidebar splits into short labelled sections with the soon shelf last", () => {
31 expect(
32 visibleNavGroups("admin").map((group) => ({
33 id: group.id,
34 items: group.items.map((item) => item.id),
35 })),
36 ).toEqual([
37 { id: "ai", items: ["ai-studio", "ai-study", "ai-insights", "ai-celebi"] },
38 { id: "school", items: ["students-roster", "teachers-roster", "class-groups", "academic-years", "terms", "schedule"] },
39 { id: "teaching", items: ["courses", "homework", "exams", "question-bank", "questions", "notes", "whiteboards"] },
40 { id: "tracking", items: ["student-attendance", "student-marks", "student-pomodoros"] },
41 { id: "services", items: ["events", "appointments", "school-meals"] },
42 { id: "institution", items: ["payments-collection", "staff-work", "work", "users", "license-modules", "settings"] },
43 { id: "soon", items: ["mock-exams", "optical-reading", "reports", "data-protection"] },
44 ]);
45});
46
47test("manager sees the same admin tree minus the admin-only entries", () => {
48 const groups = visibleNavGroups("manager");
49 const institution = groups.find((group) => group.id === "institution");
50 expect(institution?.items.map((item) => item.id)).toEqual(["payments-collection", "staff-work", "work", "settings"]);
51 const ids = groups.flatMap((group) => group.items.map((item) => item.id));
52 expect(ids).not.toContain("license-modules");
53 expect(ids).not.toContain("users");
54 expect(ids).not.toContain("data-protection");
55});
56
57test("teacher's sidebar splits into short labelled sections, every entry live", () => {
58 expect(
59 visibleNavGroups("teacher").map((group) => ({
60 id: group.id,
61 items: group.items.map((item) => item.id),
62 })),
63 ).toEqual([
64 { id: "ai", items: ["ai-studio", "ai-study", "ai-celebi"] },
65 { id: "my-classroom", items: ["my-classes", "my-schedule", "courses"] },
66 { id: "tracking", items: ["student-attendance", "student-marks", "student-pomodoros", "student-analysis"] },
67 { id: "teaching", items: ["homework", "exams", "question-bank", "question-generation", "questions", "pending-approvals", "notes", "whiteboards"] },
68 { id: "other", items: ["parent-communication", "appointments", "events", "meals", "work", "settings-teacher"] },
69 ]);
70});
71
72test("student's sidebar splits into short labelled sections with the soon shelf last", () => {
73 expect(
74 visibleNavGroups("student").map((group) => ({
75 id: group.id,
76 items: group.items.map((item) => item.id),
77 })),
78 ).toEqual([
79 { id: "ai", items: ["ai-studio", "ai-study", "ai-insights", "ai-celebi"] },
80 { id: "study", items: ["topic-mastery", "exam-results", "my-homework", "pomodoro"] },
81 { id: "teaching", items: ["courses", "notes", "questions", "whiteboards"] },
82 { id: "other", items: ["calendar", "events", "messages", "appointments", "meals", "settings-student"] },
83 { id: "soon", items: ["study-plan"] },
84 ]);
85});
86
87test("every soon entry sits in the folded soon shelf and nowhere else", () => {
88 for (const role of ["student", "parent", "teacher", "manager", "admin"] as const) {
89 for (const group of visibleNavGroups(role)) {
90 const soon = group.items.filter((item) => item.soon);
91 if (group.id === "soon") {
92 expect(group.defaultFolded).toBe(true);
93 expect(soon).toHaveLength(group.items.length);
94 } else {
95 expect(soon).toHaveLength(0);
96 }
97 }
98 }
99});
100
101test("parent's sidebar keeps the Figma Öğrencim / Kurum tree plus every backed page", () => {
102 expect(
103 visibleNavGroups("parent").map((group) => ({
104 id: group.id,
105 items: group.items.map((item) => item.id),
106 })),
107 ).toEqual([
108 { id: "ai", items: ["ai-insights"] },
109 { id: "my-student", items: ["progress-report", "absence", "child-exam-results", "child-study-plan"] },
110 { id: "institution", items: ["payment-statement", "appointments", "messages", "calendar", "events", "meals", "settings-parent"] },
111 // A parent's only AI surface: their children's analysis.
112 ]);
113});
114
115test("appointments and meals are reachable from every role's sidebar", () => {
116 for (const role of ["student", "parent", "teacher", "manager", "admin"] as const) {
117 const paths = visibleNavGroups(role).flatMap((g) => g.items.map((i) => i.to));
118 expect(paths).toContain("/appointments");
119 expect(paths).toContain("/meals");
120 }
121});
122
123test("parent's child entries open the progress page on their own tab, not a placeholder", () => {
124 const items = visibleNavGroups("parent").flatMap((g) => g.items);
125 expect(items.filter((i) => i.soon).map((i) => i.id)).toEqual([]);
126 expect(routeNavItem("/students/attendance", "parent")?.id).toBe("absence");
127 expect(routeNavItem("/students/exams", "parent")?.id).toBe("child-exam-results");
128 expect(routeNavItem("/students/study", "parent")?.id).toBe("child-study-plan");
129 expect(routeNavItem("/students", "parent")?.id).toBe("progress-report");
130});
131
132test("license modules is a real admin page and the work log includes admin", () => {
133 const admin = visibleNavGroups("admin").flatMap((g) => g.items);
134 const licenseModules = admin.find((i) => i.id === "license-modules");
135 expect(licenseModules?.to).toBe("/management/modules");
136 expect(licenseModules?.soon).toBeFalsy();
137 expect(admin.map((i) => i.to)).toContain("/work");
138 expect(admin.filter((i) => i.id.endsWith("-roster")).map((i) => [i.to, i.soon ?? false])).toEqual([
139 ["/management/students", false],
140 ["/management/teachers", false],
141 ]);
142 expect(visibleNavGroups("manager").flatMap((g) => g.items).map((i) => i.id)).not.toContain("license-modules");
143});
144
145test("entries with no backend yet are flagged soon and route to the shared placeholder", () => {
146 const opticalReading = visibleNavGroups("admin")
147 .flatMap((g) => g.items)
148 .find((i) => i.id === "optical-reading");
149 expect(opticalReading?.soon).toBe(true);
150 expect(opticalReading?.to).toBe("/coming-soon/optik-okuma");
151});
152
153test("the AI group exposes four separate module routes", () => {
154 // A teacher reaches the analysis board as "Öğrenci analizi" under Tracking.
155 expect(visibleNavGroups("teacher").find((group) => group.id === "ai")?.items.map((item) => item.id)).toEqual(["ai-studio", "ai-study", "ai-celebi"]);
156 expect(routeNavItem("/ai/insights", "teacher")?.id).toBe("student-analysis");
157 for (const role of ["student", "manager", "admin"] as const) {
158 const ai = visibleNavGroups(role).find((group) => group.id === "ai");
159 expect(ai?.items.map((item) => item.id)).toEqual(["ai-studio", "ai-study", "ai-insights", "ai-celebi"]);
160 expect(ai?.items.every((item) => !item.soon)).toBe(true);
161 }
162 expect(visibleNavGroups("parent").find((group) => group.id === "ai")?.items.map((item) => item.id)).toEqual(["ai-insights"]);
163 expect(routeNavItem("/ai/studio", "student")?.id).toBe("ai-studio");
164 expect(routeNavItem("/ai/insights", "parent")?.id).toBe("ai-insights");
165 expect(routeLabelKey("/ai/studio", "student")).toBe("aiHub.tab.studio");
166});
167
168test("AI modules navigate while Çelebi and account settings open shell surfaces", () => {
169 const celebi = visibleNavGroups("student")
170 .flatMap((g) => g.items)
171 .find((i) => i.id === "ai-celebi");
172 expect(celebi?.to).toBe("");
173 expect(celebi?.action).toBe("celebi");
174 expect(routeNavItem("/ai/celebi", "student")).toBeUndefined();
175 const settings = visibleNavGroups("student")
176 .flatMap((g) => g.items)
177 .find((i) => i.id === "settings-student");
178 expect(settings?.action).toBe("profile");
179});
180
181test("nested entity routes keep their primary destination active", () => {
182 expect(pathActive("/management/classes/class-1", "/management/classes")).toBe(true);
183 expect(routeNavItem("/management/classes/class-1", "teacher")?.id).toBe("my-classes");
184 expect(routeNavItem("/management/student-attendance", "teacher")?.id).toBe("student-attendance");
185 expect(primaryPathActive("/homework/hw-1", primaryNavItems("student")[1]!)).toBe(true);
186});
187
188test.each([
189 ["/homework/hw-1", "student", "my-homework"],
190 ["/homework/hw-1", "teacher", "homework"],
191 ["/management/student-attendance", "teacher", "student-attendance"],
192 ["/management/settings", "manager", "settings"],
193] as const)("sidebar resolves one active item for %s", (pathname, role, expected) => {
194 // Mobile tabs reuse the sidebar's own item objects, so dedupe by identity.
195 const items = [...new Set([...primaryNavItems(role), ...visibleNavGroups(role).flatMap((group) => group.items)])];
196 const current = routeNavItem(pathname, role);
197
198 expect(items.filter((item) => item.id === current?.id).map((item) => item.id)).toEqual([expected]);
199});
200
201// The shell header used to print the raw pathname for any route without a
202// sidebar entry, so /profile/me read as "/profile/me".
203test.each([
204 ["/profile/me", "profile.myProfile"],
205 ["/profile/u-1", "profile.title"],
206 ["/guide", "nav.guide"],
207 ["/attendance", "nav.attendance"],
208 ["/studies", "courses.kind.study"],
209 ["/clubs", "courses.kind.club"],
210 ["/courses", "nav.classes"],
211 ["/courses/course-1", "nav.classes"],
212 ["/notes", "nav.notes"],
213 ["/questions", "nav.questions"],
214 ["/events", "nav.events"],
215 ["/meals", "nav.meals"],
216] as const)("%s has a header label", (pathname, expected) => {
217 expect(routeLabelKey(pathname, "student")).toBe(expected);
218});
219
220test("routes with a sidebar entry still take their nav label", () => {
221 expect(routeLabelKey("/homework/hw-1", "teacher")).toBe(routeNavItem("/homework/hw-1", "teacher")?.labelKey);
222});
223
224test("a route rendered outside the shell has no label rather than a raw path", () => {
225 expect(routeLabelKey("/login", undefined)).toBeUndefined();
226});
227
228test("a page keeps its name for a viewer who may not open it", () => {
229 // /students is parent-only; an admin lands on the no-access screen, and the
230 // shell header must still say what page that is.
231 expect(routeLabelKey("/students", "admin")).toBe("nav.progressReport");
232 expect(routeLabelKey("/students", "parent")).toBe("nav.progressReport");
233});
234
235test("module gate fails open while the entitlement lookup is unknown", () => {
236 expect(primaryNavItems("student", null).map((item) => item.to)).toEqual(primaryNavItems("student").map((item) => item.to));
237 expect(primaryNavItems("student", undefined).map((item) => item.to)).toEqual(primaryNavItems("student").map((item) => item.to));
238});
239
240test("module gate hides nests the school did not buy", () => {
241 const enabled = ["courses"];
242 const teacherPaths = visibleNavGroups("teacher", enabled).flatMap((group) => group.items.map((item) => item.to));
243 expect(teacherPaths).not.toContain("/homework");
244 expect(teacherPaths).not.toContain("/exams");
245 expect(teacherPaths).not.toContain("/whiteboards");
246 // Classes is a module too, so an unbought "classes" nest hides it; the
247 // schedule carries no module and stays.
248 expect(teacherPaths).not.toContain("/management/classes");
249 expect(visibleNavGroups("teacher", ["courses", "classes"]).flatMap((group) => group.items.map((item) => item.to)))
250 .toContain("/management/classes");
251 expect(teacherPaths).toContain("/calendar");
252});
253
254test("ungated entries never drop on module filtering", () => {
255 expect(moduleVisible({ id: "x", to: "/calendar", labelKey: "nav.calendar", Icon: (() => null) as never }, [])).toBe(true);
256});
257
258test("a search-carrying entry wins over the plain entry for the same path", () => {
259 expect(routeNavItem("/questions", "teacher", { status: "pending" })?.id).toBe("pending-approvals");
260 expect(routeNavItem("/questions", "teacher", { status: "approved" })?.id).toBe("questions");
261 expect(routeNavItem("/questions", "teacher")?.id).toBe("questions");
262});