Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

markdownLinks.test.ts

88 lines2.6 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { resolveMarkdownLinkPresentation } from "@t3tools/mobile-markdown-text/links";
4​
5describe("resolveMarkdownLinkPresentation", () => {
6 it("extracts external link hosts", () => {
7 expect(resolveMarkdownLinkPresentation("https://example.com/docs?q=1")).toEqual({
8 kind: "external",
9 href: "https://example.com/docs?q=1",
10 host: "example.com",
11 });
12 });
13​
14 it("renders file URLs as basename pills with positions", () => {
15 expect(
16 resolveMarkdownLinkPresentation("file:///Users/julius/project/src/main.ts#L42C7"),
17 ).toEqual({
18 kind: "file",
19 href: "file:///Users/julius/project/src/main.ts#L42C7",
20 icon: "typescript",
21 label: "main.ts:42:7",
22 path: "/Users/julius/project/src/main.ts",
23 line: 42,
24 column: 7,
25 });
26 });
27​
28 it("recognizes relative source paths and bare filenames", () => {
29 expect(resolveMarkdownLinkPresentation("apps/mobile/src/index.ts:10")).toEqual({
30 kind: "file",
31 href: "apps/mobile/src/index.ts:10",
32 icon: "typescript",
33 label: "index.ts:10",
34 path: "apps/mobile/src/index.ts",
35 line: 10,
36 });
37 expect(resolveMarkdownLinkPresentation("AGENTS.md")).toEqual({
38 kind: "file",
39 href: "AGENTS.md",
40 icon: "agents",
41 label: "AGENTS.md",
42 path: "AGENTS.md",
43 });
44 expect(resolveMarkdownLinkPresentation("package.json")).toEqual({
45 kind: "file",
46 href: "package.json",
47 icon: "package",
48 label: "package.json",
49 path: "package.json",
50 });
51 });
52​
53 it("extracts line fragments from relative file links", () => {
54 expect(resolveMarkdownLinkPresentation("src/main.ts#L18C2")).toMatchObject({
55 kind: "file",
56 path: "src/main.ts",
57 line: 18,
58 column: 2,
59 label: "main.ts:18:2",
60 });
61 });
62​
63 it("uses the Pierre complete icon mappings", () => {
64 expect(resolveMarkdownLinkPresentation("src/Button.tsx")).toMatchObject({
65 kind: "file",
66 icon: "react",
67 });
68 expect(resolveMarkdownLinkPresentation("vite.config.ts")).toMatchObject({
69 kind: "file",
70 icon: "vite",
71 });
72 expect(resolveMarkdownLinkPresentation("Dockerfile")).toMatchObject({
73 kind: "file",
74 icon: "docker",
75 });
76 expect(resolveMarkdownLinkPresentation("pnpm-lock.yaml")).toMatchObject({
77 kind: "file",
78 icon: "pnpm",
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});