Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

trackedFolders.logic.test.ts

69 lines2.4 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { resolveTrackedFolderInput, trackedFolderDisplayPath } from "./trackedFolders.logic";
4​
5describe("trackedFolderDisplayPath", () => {
6 it.each([
7 ["/work/app/api", "/work/app", "api"],
8 ["/work/app/packages/web", "/work/app/", "packages/web"],
9 ["/work/other", "/work/app", "/work/other"],
10 ["/work/app-two", "/work/app", "/work/app-two"],
11 ["C:\\Work\\App\\api", "c:\\work\\app", "api"],
12 ])("shows %s under %s as %s", (path, root, expected) => {
13 expect(trackedFolderDisplayPath(path, root)).toBe(expected);
14 });
15});
16​
17describe("resolveTrackedFolderInput", () => {
18 const overflowingPath = `/srv/${"a".repeat(127)}🚀`;
19 const paddedPath = `/srv/${" ".repeat(127)}🚀`;
20​
21 it.each([
22 [
23 "an absolute path that is not listed",
24 { query: "/srv/repos/tools/", listedDirectoryPath: null, exactEntryPath: null },
25 { path: "/srv/repos/tools", name: "tools" },
26 ],
27 [
28 "a listed directory, which resolves the home prefix",
29 { query: "~/code/", listedDirectoryPath: "/home/me/code", exactEntryPath: null },
30 { path: "/home/me/code", name: "code" },
31 ],
32 [
33 "an exact entry of the listed directory",
34 {
35 query: "~/code/tools",
36 listedDirectoryPath: "/home/me/code",
37 exactEntryPath: "/home/me/code/tools",
38 },
39 { path: "/home/me/code/tools", name: "tools" },
40 ],
41 [
42 "an emoji crossing the name limit",
43 { query: overflowingPath, listedDirectoryPath: null, exactEntryPath: null },
44 { path: overflowingPath, name: "a".repeat(127) },
45 ],
46 [
47 "an emoji after leading whitespace at the name limit",
48 { query: paddedPath, listedDirectoryPath: null, exactEntryPath: null },
49 { path: paddedPath, name: "🚀" },
50 ],
51 [
52 "a directory name longer than a folder name may be",
53 {
54 query: `/srv/${"n".repeat(127)} ${"x".repeat(40)}`,
55 listedDirectoryPath: null,
56 exactEntryPath: null,
57 },
58 { path: `/srv/${"n".repeat(127)} ${"x".repeat(40)}`, name: "n".repeat(127) },
59 ],
60 ])("resolves %s", (_label, input, expected) => {
61 expect(resolveTrackedFolderInput(input)).toEqual(expected);
62 });
63​
64 it.each(["", " ", "~/code/too", "relative/path"])("rejects %j without a listing", (query) => {
65 expect(
66 resolveTrackedFolderInput({ query, listedDirectoryPath: null, exactEntryPath: null }),
67 ).toBeNull();
68 });
69});