Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { fileChipMenu, resolveFileChipTarget } from "./fileChipMenu";
4
5describe("resolveFileChipTarget", () => {
6 it("resolves a workspace-relative link to both paths", () => {
7 expect(resolveFileChipTarget("src/app.ts:12", "/repo")).toEqual({
8 fullPath: "/repo/src/app.ts",
9 relativePath: "src/app.ts",
10 });
11 });
12
13 it("keeps only the full path for a host file outside the workspace", () => {
14 expect(resolveFileChipTarget("/tmp/report.md", "/repo")).toEqual({
15 fullPath: "/tmp/report.md",
16 });
17 });
18
19 it("keeps only the relative path when the workspace root is unknown", () => {
20 expect(resolveFileChipTarget("src/app.ts", null)).toEqual({ relativePath: "src/app.ts" });
21 });
22
23 it("ignores links that are not files or cannot be opened", () => {
24 expect(resolveFileChipTarget("https://example.com/app.ts", "/repo")).toBeNull();
25 expect(resolveFileChipTarget("~/report.md", "/repo")).toBeNull();
26 expect(resolveFileChipTarget("../other/file.ts", "/repo")).toBeNull();
27 });
28});
29
30describe("fileChipMenu", () => {
31 it("offers only the copies the target can satisfy", () => {
32 expect(fileChipMenu({ fullPath: "/tmp/report.md" })).toEqual({
33 title: "/tmp/report.md",
34 actions: [
35 { id: "copy-full-path", title: "Copy full path" },
36 { id: "open-file", title: "Open in file viewer" },
37 ],
38 });
39 expect(fileChipMenu({ relativePath: "src/app.ts" }).actions.map(({ id }) => id)).toEqual([
40 "copy-relative-path",
41 "open-file",
42 ]);
43 });
44});