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