Skip to content

Commit 135f065

Browse files
committed
test: getRoutePathName function
1 parent d4c20f0 commit 135f065

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/core/getRoutePathName.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { describe, expect, it } from "@jest/globals";
2+
import getRoutePathName from "./getRoutePathName";
3+
4+
describe("getRoutePathName", () => {
5+
const rootPath = "/home/omer/Projects/nextjs-app/src/app";
6+
7+
it("should return correct route path by removing rootPath and adjusting path", () => {
8+
const result = getRoutePathName(
9+
"/home/omer/Projects/nextjs-app/src/app/users/[id]/route.ts",
10+
rootPath
11+
);
12+
expect(result).toBe("/users/{id}");
13+
});
14+
15+
it("should replace backslashes with forward slashes", () => {
16+
const result = getRoutePathName(
17+
"C:\\home\\omer\\Projects\\nextjs-app\\src\\app\\users\\[id]\\route.ts",
18+
"C:\\home\\omer\\Projects\\nextjs-app\\src\\app",
19+
);
20+
expect(result).toBe("/users/{id}");
21+
});
22+
23+
it("should handle nested folders with parameters", () => {
24+
const result = getRoutePathName(
25+
"/home/omer/Projects/nextjs-app/src/app/users/[user]/[post]/route.ts",
26+
rootPath
27+
);
28+
expect(result).toBe("/users/{user}/{post}");
29+
});
30+
31+
it("should remove '/route.ts' if present", () => {
32+
const result = getRoutePathName(
33+
"/home/omer/Projects/nextjs-app/src/app/users/test/route.ts",
34+
rootPath
35+
);
36+
expect(result).toBe("/users/test");
37+
});
38+
39+
it("should handle cases with no parameters", () => {
40+
const result = getRoutePathName(
41+
"/home/omer/Projects/nextjs-app/src/app/users/home/route.ts",
42+
rootPath
43+
);
44+
expect(result).toBe("/users/home");
45+
});
46+
});

0 commit comments

Comments
 (0)