Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion apps/web/src/components/files/filePath.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { describe, expect, it } from "vite-plus/test";

import { fileBreadcrumbChildren, fileBreadcrumbs, retainedBreadcrumbTrail } from "./filePath";
import {
breadcrumbPathOf,
fileBreadcrumbChildren,
fileBreadcrumbs,
isListableHostFolder,
retainedBreadcrumbTrail,
} from "./filePath";

describe("fileBreadcrumbs", () => {
it("starts host paths outside the workspace at the filesystem root", () => {
Expand All @@ -20,6 +26,26 @@ describe("fileBreadcrumbs", () => {
"\\\\server\\share\\report.md",
]);
});

it("builds home-relative breadcrumbs with navigable folders", () => {
expect(fileBreadcrumbs("t3code", "~/.claude/CLAUDE.md")).toEqual([
{ label: "~", path: "~/", kind: "directory" },
{ label: ".claude", path: "~/.claude", kind: "directory" },
{ label: "CLAUDE.md", path: "~/.claude/CLAUDE.md", kind: "file" },
]);
expect(isListableHostFolder("~/")).toBe(true);
expect(isListableHostFolder("~/.claude")).toBe(true);
});

it("keeps a project folder named ~ inside the project", () => {
expect(fileBreadcrumbs("t3code", "~").map((crumb) => crumb.path)).toEqual(["", "~"]);
});
});

describe("breadcrumbPathOf", () => {
it("keeps the home root listable", () => {
expect(breadcrumbPathOf("~/")).toBe("~/");
});
});

describe("fileBreadcrumbChildren", () => {
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/files/filePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function fileBreadcrumbs(projectName: string, relativePath: string): File
return {
label: part,
// A bare drive (`C:`) means the drive's current directory; its root is `C:\`.
path: /^[A-Za-z]:$/.test(path) ? `${path}\\` : path,
// A bare `~` is not a host path; the home folder is `~/`.
path: /^[A-Za-z]:$/.test(path) ? `${path}\\` : hostPath && path === "~" ? "~/" : path,
kind: index === parts.length - 1 ? ("file" as const) : ("directory" as const),
};
}),
Expand Down
Loading