Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 fileRoutePathSegments,
5 isSvgImagePreviewFile,
6 resolveWorkspaceRelativeFilePath,
7} from "./filePath";
8
9describe("fileRoutePathSegments", () => {
10 it("round-trips workspace-relative and host paths through the route", () => {
11 expect(fileRoutePathSegments("src/main.ts")).toEqual(["src", "main.ts"]);
12 expect(fileRoutePathSegments("/tmp/t3-cleanup/report.md").join("/")).toBe(
13 "/tmp/t3-cleanup/report.md",
14 );
15 });
16});
17
18describe("resolveWorkspaceRelativeFilePath", () => {
19 it("keeps normalized workspace-relative paths", () => {
20 expect(resolveWorkspaceRelativeFilePath("/repo", "./src/../src/main.ts")).toBe("src/main.ts");
21 });
22
23 it("converts absolute paths inside the workspace", () => {
24 expect(
25 resolveWorkspaceRelativeFilePath("/Users/julius/repo", "/Users/julius/repo/src/main.ts"),
26 ).toBe("src/main.ts");
27 expect(resolveWorkspaceRelativeFilePath("C:\\repo", "c:\\repo\\src\\main.ts")).toBe(
28 "src/main.ts",
29 );
30 });
31
32 it("rejects paths outside the workspace", () => {
33 expect(resolveWorkspaceRelativeFilePath("/repo", "/other/main.ts")).toBeNull();
34 expect(resolveWorkspaceRelativeFilePath("/repo", "../other/main.ts")).toBeNull();
35 expect(resolveWorkspaceRelativeFilePath("/repo", "/repo/../outside.txt")).toBeNull();
36 expect(resolveWorkspaceRelativeFilePath(null, "/repo/main.ts")).toBeNull();
37 });
38});
39
40describe("file preview types", () => {
41 it("identifies SVG images that need web rendering", () => {
42 expect(isSvgImagePreviewFile("assets/diagram.svg#icon")).toBe(true);
43 expect(isSvgImagePreviewFile("assets/photo.png")).toBe(false);
44 });
45});