Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 formatFileCommentRange,
5 normalizeFileCommentRange,
6 remapFileCommentAnnotations,
7} from "./fileCommentAnnotations";
8import {
9 isMarkdownPreviewFile,
10 setMarkdownTaskChecked,
11 shouldShowFileExplorer,
12} from "./filePreviewMode";
13
14describe("file comment annotations", () => {
15 it("normalizes and formats selected line ranges", () => {
16 expect(normalizeFileCommentRange({ start: 16, end: 7 })).toEqual({
17 startLine: 7,
18 endLine: 16,
19 });
20 expect(formatFileCommentRange(7, 7)).toBe("L7");
21 expect(formatFileCommentRange(7, 16)).toBe("L7 to L16");
22 });
23
24 it("keeps an annotation range attached when Pierre remaps its anchor line", () => {
25 expect(
26 remapFileCommentAnnotations([
27 {
28 lineNumber: 20,
29 metadata: {
30 entries: [
31 {
32 id: "comment-1",
33 kind: "comment",
34 startLine: 7,
35 endLine: 16,
36 text: "Keep this guarded.",
37 },
38 ],
39 },
40 },
41 ]),
42 ).toEqual([
43 {
44 lineNumber: 20,
45 metadata: {
46 entries: [
47 {
48 id: "comment-1",
49 kind: "comment",
50 startLine: 11,
51 endLine: 20,
52 text: "Keep this guarded.",
53 },
54 ],
55 },
56 },
57 ]);
58 });
59});
60
61describe("isMarkdownPreviewFile", () => {
62 it("recognizes markdown and MDX files case-insensitively", () => {
63 expect(isMarkdownPreviewFile("README.md")).toBe(true);
64 expect(isMarkdownPreviewFile("docs/guide.MDX")).toBe(true);
65 });
66
67 it("does not treat other text files as markdown", () => {
68 expect(isMarkdownPreviewFile("docs/guide.txt")).toBe(false);
69 expect(isMarkdownPreviewFile("docs/markdown.ts")).toBe(false);
70 });
71});
72
73describe("shouldShowFileExplorer", () => {
74 it("hides the workspace tree for host files and attachments", () => {
75 expect(
76 shouldShowFileExplorer({
77 relativePath: "/tmp/report.pdf",
78 explorerOpen: true,
79 attachmentOpen: false,
80 }),
81 ).toBe(false);
82 expect(
83 shouldShowFileExplorer({
84 relativePath: "report.pdf",
85 explorerOpen: true,
86 attachmentOpen: true,
87 }),
88 ).toBe(false);
89 });
90
91 it("keeps the saved explorer preference for workspace files", () => {
92 expect(
93 shouldShowFileExplorer({
94 relativePath: "docs/report.pdf",
95 explorerOpen: true,
96 attachmentOpen: false,
97 }),
98 ).toBe(true);
99 expect(
100 shouldShowFileExplorer({
101 relativePath: "docs/report.pdf",
102 explorerOpen: false,
103 attachmentOpen: false,
104 }),
105 ).toBe(false);
106 });
107});
108
109describe("setMarkdownTaskChecked", () => {
110 const markdown = "- [ ] First\n- [x] Second\n";
111
112 it("checks and unchecks the task marker at the supplied offset", () => {
113 expect(setMarkdownTaskChecked(markdown, 2, true)).toBe("- [x] First\n- [x] Second\n");
114 expect(setMarkdownTaskChecked(markdown, 14, false)).toBe("- [ ] First\n- [ ] Second\n");
115 expect(setMarkdownTaskChecked("1. [X] Ordered\n", 3, false)).toBe("1. [ ] Ordered\n");
116 });
117
118 it("leaves the document unchanged for a stale or invalid marker offset", () => {
119 expect(setMarkdownTaskChecked(markdown, 0, true)).toBe(markdown);
120 expect(setMarkdownTaskChecked(markdown, 200, true)).toBe(markdown);
121 });
122});