The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { resolveMarkdownLinkPresentation } from "./markdownLinks"; |
| 4 | |
| 5 | describe("resolveMarkdownLinkPresentation", () => { |
| 6 | it("opens relative directory links as workspace paths", () => { |
| 7 | expect(resolveMarkdownLinkPresentation("src/")).toMatchObject({ |
| 8 | kind: "file", |
| 9 | path: "src/", |
| 10 | }); |
| 11 | expect(resolveMarkdownLinkPresentation("docs/My Folder/")).toMatchObject({ |
| 12 | kind: "file", |
| 13 | path: "docs/My Folder/", |
| 14 | }); |
| 15 | }); |
| 16 | |
| 17 | it("treats protocol-relative media as an external URL, not a filesystem path", () => { |
| 18 | expect(resolveMarkdownLinkPresentation("//cdn.example.com/clip.mp4?sig=a%2fb#t=2")).toEqual({ |
| 19 | kind: "external", |
| 20 | href: "https://cdn.example.com/clip.mp4?sig=a%2fb#t=2", |
| 21 | host: "cdn.example.com", |
| 22 | }); |
| 23 | }); |
| 24 | |
| 25 | it("separates encoded filename characters from a video playback fragment", () => { |
| 26 | expect(resolveMarkdownLinkPresentation("/tmp/clip%23one.mp4#t=2")).toMatchObject({ |
| 27 | path: "/tmp/clip#one.mp4", |
| 28 | label: "clip#one.mp4", |
| 29 | icon: "video", |
| 30 | }); |
| 31 | }); |
| 32 | |
| 33 | it.each([ |
| 34 | ["file:///Users/julius/project/src/main.ts#L42C7", "/Users/julius/project/src/main.ts"], |
| 35 | ["file://server/share/src/main.ts#L42C7", "\\\\server\\share\\src\\main.ts"], |
| 36 | ])("preserves the file URL path and position for %s", (href, path) => { |
| 37 | expect(resolveMarkdownLinkPresentation(href)).toEqual({ |
| 38 | kind: "file", |
| 39 | href, |
| 40 | icon: "typescript", |
| 41 | label: "main.ts · L42:C7", |
| 42 | path, |
| 43 | line: 42, |
| 44 | column: 7, |
| 45 | }); |
| 46 | }); |
| 47 | |
| 48 | it("recognizes relative source paths and bare filenames", () => { |
| 49 | expect(resolveMarkdownLinkPresentation("apps/mobile/src/index.ts:10")).toEqual({ |
| 50 | kind: "file", |
| 51 | href: "apps/mobile/src/index.ts:10", |
| 52 | icon: "typescript", |
| 53 | label: "index.ts · L10", |
| 54 | path: "apps/mobile/src/index.ts", |
| 55 | line: 10, |
| 56 | }); |
| 57 | expect(resolveMarkdownLinkPresentation("AGENTS.md")).toEqual({ |
| 58 | kind: "file", |
| 59 | href: "AGENTS.md", |
| 60 | icon: "agents", |
| 61 | label: "AGENTS.md", |
| 62 | path: "AGENTS.md", |
| 63 | }); |
| 64 | expect(resolveMarkdownLinkPresentation("package.json")).toEqual({ |
| 65 | kind: "file", |
| 66 | href: "package.json", |
| 67 | icon: "npm", |
| 68 | label: "package.json", |
| 69 | path: "package.json", |
| 70 | }); |
| 71 | }); |
| 72 | |
| 73 | // regression: #8098 open agent file links in the file viewer |
| 74 | it("recognizes spaced relative paths", () => { |
| 75 | expect(resolveMarkdownLinkPresentation("docs/My%20Folder/checklist.xml")).toMatchObject({ |
| 76 | kind: "file", |
| 77 | path: "docs/My Folder/checklist.xml", |
| 78 | label: "checklist.xml", |
| 79 | }); |
| 80 | }); |
| 81 | |
| 82 | it("does not style app routes as file links", () => { |
| 83 | expect(resolveMarkdownLinkPresentation("/chat/settings")).toEqual({ |
| 84 | kind: "link", |
| 85 | href: null, |
| 86 | }); |
| 87 | }); |
| 88 | }); |