-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfileOpen.test.ts
More file actions
57 lines (50 loc) · 1.64 KB
/
fileOpen.test.ts
File metadata and controls
57 lines (50 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { describe, expect, it, vi } from "vitest";
import {
openFileReference,
resolveCodeViewerRelativePath,
splitFileTargetPosition,
} from "./fileOpen";
describe("splitFileTargetPosition", () => {
it("extracts line and column suffixes", () => {
expect(splitFileTargetPosition("/Users/julius/project/src/main.ts:42:7")).toEqual({
path: "/Users/julius/project/src/main.ts",
line: 42,
column: 7,
});
});
it("leaves plain paths unchanged", () => {
expect(splitFileTargetPosition("/Users/julius/project/README.md")).toEqual({
path: "/Users/julius/project/README.md",
line: null,
column: null,
});
});
});
describe("resolveCodeViewerRelativePath", () => {
it("maps an absolute target under cwd into a relative code viewer path", () => {
expect(
resolveCodeViewerRelativePath(
"/Users/julius/project/src/components/ChatMarkdown.tsx:42",
"/Users/julius/project",
),
).toBe("src/components/ChatMarkdown.tsx");
});
it("returns null for targets outside cwd", () => {
expect(
resolveCodeViewerRelativePath("/Users/julius/other/file.ts:1", "/Users/julius/project"),
).toBeNull();
});
});
describe("openFileReference", () => {
it("opens files in the code viewer when external editors are not preferred", async () => {
const openInViewer = vi.fn();
await openFileReference({
api: {} as never,
cwd: "/Users/julius/project",
targetPath: "/Users/julius/project/src/main.ts:12:4",
preferExternal: false,
openInViewer,
});
expect(openInViewer).toHaveBeenCalledWith("/Users/julius/project", "src/main.ts");
});
});