The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | breadcrumbPathOf, |
| 5 | fileBreadcrumbChildren, |
| 6 | fileBreadcrumbs, |
| 7 | isListableHostFolder, |
| 8 | retainedBreadcrumbTrail, |
| 9 | } from "./filePath"; |
| 10 | |
| 11 | describe("fileBreadcrumbs", () => { |
| 12 | it("starts host paths outside the workspace at the filesystem root", () => { |
| 13 | expect(fileBreadcrumbs("t3code", "/tmp/t3-cleanup/report.md")).toEqual([ |
| 14 | { label: "tmp", path: "/tmp", kind: "directory" }, |
| 15 | { label: "t3-cleanup", path: "/tmp/t3-cleanup", kind: "directory" }, |
| 16 | { label: "report.md", path: "/tmp/t3-cleanup/report.md", kind: "file" }, |
| 17 | ]); |
| 18 | expect(fileBreadcrumbs("t3code", "C:\\Temp\\report.md")).toEqual([ |
| 19 | { label: "C:", path: "C:\\", kind: "directory" }, |
| 20 | { label: "Temp", path: "C:\\Temp", kind: "directory" }, |
| 21 | { label: "report.md", path: "C:\\Temp\\report.md", kind: "file" }, |
| 22 | ]); |
| 23 | expect(fileBreadcrumbs("t3code", "\\\\server\\share\\report.md").map((c) => c.path)).toEqual([ |
| 24 | "\\\\server", |
| 25 | "\\\\server\\share", |
| 26 | "\\\\server\\share\\report.md", |
| 27 | ]); |
| 28 | }); |
| 29 | |
| 30 | it("builds home-relative breadcrumbs with navigable folders", () => { |
| 31 | expect(fileBreadcrumbs("t3code", "~/.claude/CLAUDE.md")).toEqual([ |
| 32 | { label: "~", path: "~/", kind: "directory" }, |
| 33 | { label: ".claude", path: "~/.claude", kind: "directory" }, |
| 34 | { label: "CLAUDE.md", path: "~/.claude/CLAUDE.md", kind: "file" }, |
| 35 | ]); |
| 36 | expect(fileBreadcrumbs("t3code", "~\\.claude/CLAUDE.md")).toEqual([ |
| 37 | { label: "~", path: "~/", kind: "directory" }, |
| 38 | { label: ".claude", path: "~/.claude", kind: "directory" }, |
| 39 | { label: "CLAUDE.md", path: "~/.claude/CLAUDE.md", kind: "file" }, |
| 40 | ]); |
| 41 | expect(isListableHostFolder("~/")).toBe(true); |
| 42 | expect(isListableHostFolder("~/.claude")).toBe(true); |
| 43 | }); |
| 44 | |
| 45 | it("keeps a literal backslash inside a workspace path segment", () => { |
| 46 | expect(fileBreadcrumbs("t3code", "dir\\one/report.txt")).toEqual([ |
| 47 | { label: "t3code", path: "", kind: "project" }, |
| 48 | { label: "dir\\one", path: "dir\\one", kind: "directory" }, |
| 49 | { label: "report.txt", path: "dir\\one/report.txt", kind: "file" }, |
| 50 | ]); |
| 51 | }); |
| 52 | |
| 53 | it("keeps a project folder named ~ inside the project", () => { |
| 54 | expect(fileBreadcrumbs("t3code", "~").map((crumb) => crumb.path)).toEqual(["", "~"]); |
| 55 | }); |
| 56 | }); |
| 57 | |
| 58 | describe("breadcrumbPathOf", () => { |
| 59 | it("keeps the home root listable", () => { |
| 60 | expect(breadcrumbPathOf("~/")).toBe("~/"); |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | describe("fileBreadcrumbChildren", () => { |
| 65 | const entries = [ |
| 66 | { path: "README.md", kind: "file" as const }, |
| 67 | { path: "src", kind: "directory" as const }, |
| 68 | { path: "src-old", kind: "directory" as const }, |
| 69 | { path: "src/index.ts", kind: "file" as const }, |
| 70 | { path: "src/lib", kind: "directory" as const }, |
| 71 | { path: "src/lib/file10.ts", kind: "file" as const }, |
| 72 | { path: "src/lib/file2.ts", kind: "file" as const }, |
| 73 | { path: "src-old/index.ts", kind: "file" as const }, |
| 74 | ]; |
| 75 | |
| 76 | it("honors segment boundaries and sorts folders before files", () => { |
| 77 | expect(fileBreadcrumbChildren(entries, "src")).toEqual([ |
| 78 | { path: "src/lib", kind: "directory", label: "lib" }, |
| 79 | { path: "src/index.ts", kind: "file", label: "index.ts" }, |
| 80 | ]); |
| 81 | }); |
| 82 | }); |
| 83 | |
| 84 | describe("retainedBreadcrumbTrail", () => { |
| 85 | it.each([ |
| 86 | ["apps/web/src", "apps/web", "apps/web/src"], |
| 87 | ["apps/web/src", "", "apps/web/src"], |
| 88 | ["apps/web/src", "apps/web/src", "apps/web/src"], |
| 89 | ["apps/web/src", "apps/mobile", "apps/mobile"], |
| 90 | ["src/lib", "src-old", "src-old"], |
| 91 | ["apps/web", "apps/web/src/main.tsx", "apps/web/src/main.tsx"], |
| 92 | ["apps/web/src", "/tmp/report", "/tmp/report"], |
| 93 | ["/tmp/report", "", ""], |
| 94 | ["C:\\Temp\\a", "", ""], |
| 95 | ["/Users/me/projects/scope", "/Users/me", "/Users/me/projects/scope"], |
| 96 | ["/Users/me/projects/scope", "/Users/me/proj", "/Users/me/proj"], |
| 97 | ["/Volumes/Work/a", "/Volumes/Work/a/", "/Volumes/Work/a"], |
| 98 | ["C:\\Users\\me\\scope", "C:\\", "C:\\Users\\me\\scope"], |
| 99 | ["C:\\Users\\me\\scope", "C:\\Users", "C:\\Users\\me\\scope"], |
| 100 | ["C:\\Users\\me\\scope", "D:\\", "D:\\"], |
| 101 | ["\\\\nas\\share\\docs\\notes", "\\\\nas\\share", "\\\\nas\\share\\docs\\notes"], |
| 102 | ])("from trail %j to %j keeps %j", (trail, path, expected) => { |
| 103 | expect(retainedBreadcrumbTrail(trail, path)).toBe(expected); |
| 104 | }); |
| 105 | }); |