forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

back-target.test.ts35 lines, 1.0 KiBHistoryRawDownload
1import { backTarget } from "./back-target";
2
3const ROUTES = [
4 "/",
5 "/exams",
6 "/exams/$id",
7 "/exams/$id/live",
8 "/instances/$id",
9 "/exam-room/$id",
10 "/courses",
11 "/management/classes",
12 "/management/classes/$id",
13 "/management/settings",
14 "/profile/$userId",
15];
16
17it("goes from a detail page to its list", () => {
18 expect(backTarget("/exams/42", ROUTES)).toBe("/exams");
19 expect(backTarget("/management/classes/7", ROUTES)).toBe("/management/classes");
20});
21
22it("goes from a nested page to the record it belongs to", () => {
23 expect(backTarget("/exams/42/live", ROUTES)).toBe("/exams/42");
24});
25
26it("uses the hub for details that have no list of their own", () => {
27 expect(backTarget("/instances/7", ROUTES)).toBe("/courses");
28 expect(backTarget("/exam-room/3", ROUTES)).toBe("/exams");
29 expect(backTarget("/profile/u-1", ROUTES)).toBe("/");
30});
31
32it("falls back to home when no ancestor route exists", () => {
33 expect(backTarget("/management/settings", ROUTES)).toBe("/");
34 expect(backTarget("/exams", ROUTES)).toBe("/");
35});