Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { fileBreadcrumbChildren, fileBreadcrumbs, retainedBreadcrumbTrail } from "./filePath";
4
5describe("fileBreadcrumbs", () => {
6 it("starts host paths outside the workspace at the filesystem root", () => {
7 expect(fileBreadcrumbs("t3code", "/tmp/t3-cleanup/report.md")).toEqual([
8 { label: "tmp", path: "/tmp", kind: "directory" },
9 { label: "t3-cleanup", path: "/tmp/t3-cleanup", kind: "directory" },
10 { label: "report.md", path: "/tmp/t3-cleanup/report.md", kind: "file" },
11 ]);
12 expect(fileBreadcrumbs("t3code", "C:\\Temp\\report.md")).toEqual([
13 { label: "C:", path: "C:\\", kind: "directory" },
14 { label: "Temp", path: "C:\\Temp", kind: "directory" },
15 { label: "report.md", path: "C:\\Temp\\report.md", kind: "file" },
16 ]);
17 expect(fileBreadcrumbs("t3code", "\\\\server\\share\\report.md").map((c) => c.path)).toEqual([
18 "\\\\server",
19 "\\\\server\\share",
20 "\\\\server\\share\\report.md",
21 ]);
22 });
23});
24
25describe("fileBreadcrumbChildren", () => {
26 const entries = [
27 { path: "README.md", kind: "file" as const },
28 { path: "src", kind: "directory" as const },
29 { path: "src-old", kind: "directory" as const },
30 { path: "src/index.ts", kind: "file" as const },
31 { path: "src/lib", kind: "directory" as const },
32 { path: "src/lib/file10.ts", kind: "file" as const },
33 { path: "src/lib/file2.ts", kind: "file" as const },
34 { path: "src-old/index.ts", kind: "file" as const },
35 ];
36
37 it("honors segment boundaries and sorts folders before files", () => {
38 expect(fileBreadcrumbChildren(entries, "src")).toEqual([
39 { path: "src/lib", kind: "directory", label: "lib" },
40 { path: "src/index.ts", kind: "file", label: "index.ts" },
41 ]);
42 });
43});
44
45describe("retainedBreadcrumbTrail", () => {
46 it.each([
47 // Walking up keeps the deeper path, all the way to the workspace root.
48 ["apps/web/src", "apps/web", "apps/web/src"],
49 ["apps/web/src", "", "apps/web/src"],
50 // Walking back down inside the trail keeps it too.
51 ["apps/web/src", "apps/web/src", "apps/web/src"],
52 // Somewhere else starts over, including a sibling that shares a name prefix.
53 ["apps/web/src", "apps/mobile", "apps/mobile"],
54 ["src/lib", "src-old", "src-old"],
55 ["apps/web", "apps/web/src/main.tsx", "apps/web/src/main.tsx"],
56 // Workspace and host paths never share a trail.
57 ["apps/web/src", "/tmp/report", "/tmp/report"],
58 ["/tmp/report", "", ""],
59 ["C:\\Temp\\a", "", ""],
60 // Host folders outside the workspace keep their trail the same way.
61 ["/Users/me/projects/scope", "/Users/me", "/Users/me/projects/scope"],
62 ["/Users/me/projects/scope", "/Users/me/proj", "/Users/me/proj"],
63 ["/Volumes/Work/a", "/Volumes/Work/a/", "/Volumes/Work/a"],
64 ["C:\\Users\\me\\scope", "C:\\", "C:\\Users\\me\\scope"],
65 ["C:\\Users\\me\\scope", "C:\\Users", "C:\\Users\\me\\scope"],
66 ["C:\\Users\\me\\scope", "D:\\", "D:\\"],
67 ["\\\\nas\\share\\docs\\notes", "\\\\nas\\share", "\\\\nas\\share\\docs\\notes"],
68 ])("from trail %j to %j keeps %j", (trail, path, expected) => {
69 expect(retainedBreadcrumbTrail(trail, path)).toBe(expected);
70 });
71});