Open History to see the last commit
1import { EnvironmentId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { resolveMarkdownFileLinkMeta } from "../markdown-links";
5
6import {
7 canUseMarkdownFileShellActions,
8 markdownFileCopyMenuItems,
9 shouldUseMarkdownFileBrowserPrimaryAction,
10} from "./ChatMarkdown";
11
12describe("canUseMarkdownFileShellActions", () => {
13 const environmentId = EnvironmentId.make("environment-1");
14
15 it("allows editor and file manager actions only for resolved local environments", () => {
16 expect(canUseMarkdownFileShellActions(environmentId, "local-exec", true)).toBe(true);
17 expect(canUseMarkdownFileShellActions(environmentId, "local-exec", false)).toBe(false);
18 expect(canUseMarkdownFileShellActions(environmentId, "remote-links", true)).toBe(false);
19 expect(canUseMarkdownFileShellActions(environmentId, "remote-unavailable", true)).toBe(false);
20 expect(canUseMarkdownFileShellActions(null, "local-exec", true)).toBe(false);
21 });
22});
23
24describe("shouldUseMarkdownFileBrowserPrimaryAction", () => {
25 const html = { iconPath: "/tmp/report.html", canOpenInBrowser: true };
26
27 it("uses the browser only when it is the sole action, except for PDFs", () => {
28 expect(
29 shouldUseMarkdownFileBrowserPrimaryAction({
30 ...html,
31 canOpenInEditor: false,
32 canOpenInPanel: false,
33 }),
34 ).toBe(true);
35 expect(
36 shouldUseMarkdownFileBrowserPrimaryAction({
37 ...html,
38 canOpenInEditor: true,
39 canOpenInPanel: false,
40 }),
41 ).toBe(false);
42 expect(
43 shouldUseMarkdownFileBrowserPrimaryAction({
44 ...html,
45 canOpenInEditor: false,
46 canOpenInPanel: true,
47 }),
48 ).toBe(false);
49 expect(
50 shouldUseMarkdownFileBrowserPrimaryAction({
51 iconPath: "/tmp/report.pdf",
52 canOpenInEditor: true,
53 canOpenInBrowser: true,
54 canOpenInPanel: true,
55 }),
56 ).toBe(true);
57 });
58});
59
60describe("markdownFileCopyMenuItems", () => {
61 it.each([
62 {
63 name: "project file",
64 href: "/Users/jordan/project/src/main.ts",
65 cwd: "/Users/jordan/project",
66 relative: "src/main.ts",
67 full: "/Users/jordan/project/src/main.ts",
68 },
69 {
70 name: "worktree file with a line and column",
71 href: "src/main.ts:12:3",
72 cwd: "/Users/jordan/project/.claude/worktrees/topic",
73 relative: "src/main.ts:12:3",
74 full: "/Users/jordan/project/.claude/worktrees/topic/src/main.ts:12:3",
75 },
76 {
77 name: "main checkout file outside the thread worktree",
78 href: "/Users/jordan/project/src/main.ts",
79 cwd: "/Users/jordan/project/.claude/worktrees/topic",
80 relative: null,
81 full: "/Users/jordan/project/src/main.ts",
82 },
83 ])("offers accurate clipboard values for $name", ({ href, cwd, relative, full }) => {
84 const meta = resolveMarkdownFileLinkMeta(href, cwd);
85 expect(meta).not.toBeNull();
86 if (!meta) throw new Error(`Expected a file link for ${href}`);
87
88 expect(markdownFileCopyMenuItems(meta)).toEqual([
89 ...(relative === null
90 ? []
91 : [
92 {
93 id: "copy-relative",
94 label: "Copy relative path",
95 value: relative,
96 title: "Relative path",
97 },
98 ]),
99 {
100 id: "copy-full",
101 label: "Copy full path",
102 value: full,
103 title: "Full path",
104 },
105 ]);
106 });
107});