Open History to see the last commit
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 it.each([
19 [
20 "an absolute path that is not listed",
21 { query: "/srv/repos/tools/", listedDirectoryPath: null, exactEntryPath: null },
22 { path: "/srv/repos/tools", name: "tools" },
23 ],
24 [
25 "a listed directory, which resolves the home prefix",
26 { query: "~/code/", listedDirectoryPath: "/home/me/code", exactEntryPath: null },
27 { path: "/home/me/code", name: "code" },
28 ],
29 [
30 "an exact entry of the listed directory",
31 {
32 query: "~/code/tools",
33 listedDirectoryPath: "/home/me/code",
34 exactEntryPath: "/home/me/code/tools",
35 },
36 { path: "/home/me/code/tools", name: "tools" },
37 ],
38 [
39 "a directory name longer than a folder name may be",
40 {
41 query: `/srv/${"n".repeat(127)} ${"x".repeat(40)}`,
42 listedDirectoryPath: null,
43 exactEntryPath: null,
44 },
45 { path: `/srv/${"n".repeat(127)} ${"x".repeat(40)}`, name: "n".repeat(127) },
46 ],
47 ])("resolves %s", (_label, input, expected) => {
48 expect(resolveTrackedFolderInput(input)).toEqual(expected);
49 });
50
51 it.each(["", " ", "~/code/too", "relative/path"])("rejects %j without a listing", (query) => {
52 expect(
53 resolveTrackedFolderInput({ query, listedDirectoryPath: null, exactEntryPath: null }),
54 ).toBeNull();
55 });
56});