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

settingsScopeAxis.test.ts

50 lines2.1 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
4import {
5 selectEnvironmentAxis,
6 selectProjectAxis,
7 settingsScopeCheckoutChoices,
8 settingsScopeCheckoutLabel,
9} from "./settingsScopeAxis";
10​
11const member = (environmentId: string, physicalProjectKey: string, workspaceRoot = "") =>
12 ({
13 environmentId,
14 physicalProjectKey,
15 workspaceRoot,
16 }) as SidebarProjectSnapshot["memberProjects"][number];
17const group = (...memberProjects: SidebarProjectSnapshot["memberProjects"]) =>
18 ({ memberProjects }) as SidebarProjectSnapshot;
19​
20describe("settings scope axes", () => {
21 it("drops a checkout narrowing from older links when either axis changes", () => {
22 const checkout = { project: "app", checkout: "app@first", machine: "first" };
23 expect(selectEnvironmentAxis(checkout, "second")).toEqual({
24 project: "app",
25 machine: "second",
26 });
27 expect(selectProjectAxis(checkout, "app")).toEqual({ project: "app", machine: "first" });
28 });
29​
30 it("offers checkouts only where an environment cannot tell them apart", () => {
31 const a = member("laptop", "a");
32 const b = member("laptop", "b");
33 const c = member("server", "c");
34​
35 expect(settingsScopeCheckoutChoices(group(a, b, c), { machine: "laptop" })).toEqual([a, b]);
36 expect(settingsScopeCheckoutChoices(group(a, b), {})).toEqual([a, b]);
37 expect(settingsScopeCheckoutChoices(group(a, b, c), { checkout: "b" })).toEqual([a, b]);
38 expect(settingsScopeCheckoutChoices(group(a, b, c), {})).toEqual([]);
39 expect(settingsScopeCheckoutChoices(group(a, b, c), { machine: "server" })).toEqual([]);
40 });
41​
42 it("labels a checkout by its full path only when its folder name repeats", () => {
43 const first = member("laptop", "a", "/work/one/app");
44 const second = member("laptop", "b", "C:\\work\\two\\app");
45 const other = member("laptop", "c", "/work/tools");
46​
47 expect(settingsScopeCheckoutLabel(second, [first, second, other])).toBe("C:\\work\\two\\app");
48 expect(settingsScopeCheckoutLabel(other, [first, second, other])).toBe("tools");
49 });
50});