Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { resolveMarkdownLinkPresentation } from "@t3tools/mobile-markdown-text/links";
4
5describe("resolveMarkdownLinkPresentation", () => {
6 it("treats protocol-relative media as an external URL, not a filesystem path", () => {
7 expect(resolveMarkdownLinkPresentation("//cdn.example.com/clip.mp4?sig=a%2fb#t=2")).toEqual({
8 kind: "external",
9 href: "https://cdn.example.com/clip.mp4?sig=a%2fb#t=2",
10 host: "cdn.example.com",
11 });
12 });
13
14 it("separates encoded filename characters from a video playback fragment", () => {
15 expect(resolveMarkdownLinkPresentation("/tmp/clip%23one.mp4#t=2")).toMatchObject({
16 path: "/tmp/clip#one.mp4",
17 label: "clip#one.mp4",
18 icon: "video",
19 });
20 });
21
22 it("extracts external link hosts", () => {
23 expect(resolveMarkdownLinkPresentation("https://example.com/docs?q=1")).toEqual({
24 kind: "external",
25 href: "https://example.com/docs?q=1",
26 host: "example.com",
27 });
28 });
29
30 it.each([
31 ["file:///Users/julius/project/src/main.ts#L42C7", "/Users/julius/project/src/main.ts"],
32 ["file://server/share/src/main.ts#L42C7", "\\\\server\\share\\src\\main.ts"],
33 ])("preserves the file URL path and position for %s", (href, path) => {
34 expect(resolveMarkdownLinkPresentation(href)).toEqual({
35 kind: "file",
36 href,
37 icon: "typescript",
38 label: "main.ts:42:7",
39 path,
40 line: 42,
41 column: 7,
42 });
43 });
44
45 it("recognizes relative source paths and bare filenames", () => {
46 expect(resolveMarkdownLinkPresentation("apps/mobile/src/index.ts:10")).toEqual({
47 kind: "file",
48 href: "apps/mobile/src/index.ts:10",
49 icon: "typescript",
50 label: "index.ts:10",
51 path: "apps/mobile/src/index.ts",
52 line: 10,
53 });
54 expect(resolveMarkdownLinkPresentation("AGENTS.md")).toEqual({
55 kind: "file",
56 href: "AGENTS.md",
57 icon: "agents",
58 label: "AGENTS.md",
59 path: "AGENTS.md",
60 });
61 expect(resolveMarkdownLinkPresentation("package.json")).toEqual({
62 kind: "file",
63 href: "package.json",
64 icon: "package",
65 label: "package.json",
66 path: "package.json",
67 });
68 });
69
70 it.each(["md", "html", "xml"])("recognizes a bare spaced .%s filename", (extension) => {
71 expect(
72 resolveMarkdownLinkPresentation(`Updated%20cutover%20checklist.${extension}`),
73 ).toMatchObject({
74 kind: "file",
75 path: `Updated cutover checklist.${extension}`,
76 label: `Updated cutover checklist.${extension}`,
77 });
78 });
79
80 it("recognizes spaced relative paths", () => {
81 expect(resolveMarkdownLinkPresentation("docs/My%20Folder/checklist.xml")).toMatchObject({
82 kind: "file",
83 path: "docs/My Folder/checklist.xml",
84 label: "checklist.xml",
85 });
86 });
87
88 it("extracts line fragments from relative file links", () => {
89 expect(resolveMarkdownLinkPresentation("src/main.ts#L18C2")).toMatchObject({
90 kind: "file",
91 path: "src/main.ts",
92 line: 18,
93 column: 2,
94 label: "main.ts:18:2",
95 });
96 });
97
98 it("uses the Pierre complete icon mappings", () => {
99 expect(resolveMarkdownLinkPresentation("src/Button.tsx")).toMatchObject({
100 kind: "file",
101 icon: "react",
102 });
103 expect(resolveMarkdownLinkPresentation("vite.config.ts")).toMatchObject({
104 kind: "file",
105 icon: "vite",
106 });
107 expect(resolveMarkdownLinkPresentation("Dockerfile")).toMatchObject({
108 kind: "file",
109 icon: "docker",
110 });
111 expect(resolveMarkdownLinkPresentation("pnpm-lock.yaml")).toMatchObject({
112 kind: "file",
113 icon: "pnpm",
114 });
115 });
116
117 it("does not style app routes as file links", () => {
118 expect(resolveMarkdownLinkPresentation("/chat/settings")).toEqual({
119 kind: "link",
120 href: null,
121 });
122 });
123});