-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-pane-paths.test.ts
More file actions
117 lines (105 loc) · 3.74 KB
/
Copy pathfile-pane-paths.test.ts
File metadata and controls
117 lines (105 loc) · 3.74 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { describe, expect, it } from "vitest";
import {
isDotHiddenFileName,
isLocalUpDisabled,
joinLocalPath,
localParentDir,
localParentOfHome,
localPathBreadcrumbSegments,
localPathResolvedForTitle,
remotePathBarFullDisplay,
remotePathBreadcrumbSegments,
remoteSshConnectionPrefix,
} from "./file-pane-paths";
describe("file-pane-paths local", () => {
it("isDotHiddenFileName", () => {
expect(isDotHiddenFileName(".bashrc")).toBe(true);
expect(isDotHiddenFileName(".config")).toBe(true);
expect(isDotHiddenFileName("README")).toBe(false);
expect(isDotHiddenFileName("")).toBe(false);
});
it("joinLocalPath handles home-relative and absolute parents", () => {
expect(joinLocalPath("", "Documents")).toBe("Documents");
expect(joinLocalPath("a", "b")).toBe("a/b");
expect(joinLocalPath("/usr", "bin")).toBe("/usr/bin");
expect(joinLocalPath("/", "tmp")).toBe("/tmp");
});
it("localParentDir handles relative and absolute keys", () => {
expect(localParentDir("a/b")).toBe("a");
expect(localParentDir("a")).toBe("");
expect(localParentDir("")).toBe("");
expect(localParentDir("/usr/local")).toBe("/usr");
expect(localParentDir("/usr")).toBe("/");
expect(localParentDir("/")).toBe("/");
});
it("localParentOfHome", () => {
expect(localParentOfHome("/home/joe")).toBe("/home");
expect(localParentOfHome("/")).toBe("/");
});
it("isLocalUpDisabled", () => {
expect(isLocalUpDisabled("/", "/home/joe")).toBe(true);
expect(isLocalUpDisabled("", "/home/joe")).toBe(false);
expect(isLocalUpDisabled("", "/")).toBe(true);
expect(isLocalUpDisabled("", null)).toBe(true);
expect(isLocalUpDisabled("/home", "/home/joe")).toBe(false);
});
it("localPathResolvedForTitle", () => {
expect(localPathResolvedForTitle("/home/joe", "")).toBe("/home/joe");
expect(localPathResolvedForTitle("/home/joe", "x")).toBe("/home/joe/x");
expect(localPathResolvedForTitle("/home/joe", "/etc")).toBe("/etc");
});
it("localPathBreadcrumbSegments for home-relative and absolute", () => {
expect(localPathBreadcrumbSegments("")).toEqual([{ label: "~", path: "" }]);
expect(localPathBreadcrumbSegments("a/b")).toEqual([
{ label: "~", path: "" },
{ label: "a", path: "a" },
{ label: "b", path: "a/b" },
]);
expect(localPathBreadcrumbSegments("/var/log")).toEqual([
{ label: "/", path: "/" },
{ label: "var", path: "/var" },
{ label: "log", path: "/var/log" },
]);
});
});
describe("file-pane-paths remote", () => {
const saved = {
kind: "saved" as const,
host: {
host: "srv-alias",
hostName: "server.example",
user: "root",
port: 22,
identityFile: "",
proxyJump: "",
proxyCommand: "",
},
};
const quick = {
kind: "quick" as const,
request: {
hostName: "10.0.0.4",
user: "joe",
identityFile: "",
proxyJump: "",
proxyCommand: "",
},
};
it("remoteSshConnectionPrefix", () => {
expect(remoteSshConnectionPrefix(saved)).toBe("root@server.example");
expect(remoteSshConnectionPrefix(quick)).toBe("joe@10.0.0.4");
});
it("remotePathBarFullDisplay", () => {
expect(remotePathBarFullDisplay(saved, "/var/log")).toBe("root@server.example:/var/log");
expect(remotePathBarFullDisplay(quick, ".")).toBe("joe@10.0.0.4:.");
});
it("remotePathBreadcrumbSegments for ., /, and nested", () => {
expect(remotePathBreadcrumbSegments(".")).toEqual([{ label: ".", path: "." }]);
expect(remotePathBreadcrumbSegments("/")).toEqual([{ label: "/", path: "/" }]);
expect(remotePathBreadcrumbSegments("/a/b")).toEqual([
{ label: "/", path: "/" },
{ label: "a", path: "/a" },
{ label: "b", path: "/a/b" },
]);
});
});