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

settingsScopeAxis.test.ts

138 lines5.1 KB

1import { EnvironmentId, ProjectId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
5import {
6 environmentAxisValue,
7 projectAxisValue,
8 projectScopeMenuGroups,
9 selectEnvironmentAxis,
10 selectProjectAxis,
11 settingsScopeEnvironmentLabel,
12} from "./settingsScopeAxis";
13​
14const first = {
15 environmentId: EnvironmentId.make("first"),
16 label: "Development",
17 displayUrl: "https://first.example.com",
18};
19const second = {
20 environmentId: EnvironmentId.make("second"),
21 label: "Development",
22 displayUrl: "https://second.example.com",
23};
24​
25describe("settings scope environment labels", () => {
26 it("distinguishes same-name environments by address", () => {
27 const environments = [first, second];
28 expect(
29 environments.map((environment) => settingsScopeEnvironmentLabel(environment, environments)),
30 ).toEqual(["Development · first.example.com", "Development · second.example.com"]);
31 });
32​
33 it("falls back to environment IDs when duplicate names have no display URL", () => {
34 const environments = [first, second].map((environment) => ({
35 ...environment,
36 displayUrl: null,
37 }));
38 expect(
39 environments.map((environment) => settingsScopeEnvironmentLabel(environment, environments)),
40 ).toEqual(["Development · first", "Development · second"]);
41 });
42​
43 it("keeps unique names compact and removes disambiguation after a rename", () => {
44 expect(settingsScopeEnvironmentLabel(first, [first])).toBe("Development");
45 expect(settingsScopeEnvironmentLabel(first, [first, { ...second, label: "Production" }])).toBe(
46 "Development",
47 );
48 });
49});
50​
51describe("settings scope axes", () => {
52 it("maps each axis to its search key and back", () => {
53 expect(projectAxisValue({})).toBe("all");
54 expect(projectAxisValue({ project: "app" })).toBe("app");
55 expect(selectProjectAxis({ machine: "second" }, "app")).toEqual({
56 project: "app",
57 machine: "second",
58 });
59 expect(selectProjectAxis({ machine: "second", project: "app" }, "all")).toEqual({
60 machine: "second",
61 });
62 expect(selectEnvironmentAxis({ project: "app" }, "first")).toEqual({
63 project: "app",
64 machine: "first",
65 });
66 expect(selectEnvironmentAxis({ project: "app", machine: "first" }, "all")).toEqual({
67 project: "app",
68 });
69 });
70​
71 it("drops a checkout narrowing from older links when either axis changes", () => {
72 const checkout = { project: "app", checkout: "app@first", machine: "first" };
73 expect(selectEnvironmentAxis(checkout, "second")).toEqual({
74 project: "app",
75 machine: "second",
76 });
77 expect(selectProjectAxis(checkout, "app")).toEqual({ project: "app", machine: "first" });
78 });
79});
80​
81describe("environmentAxisValue", () => {
82 it("shows the checkout's environment for a legacy checkout link", () => {
83 expect(environmentAxisValue({ project: "p", checkout: "c" }, "laptop")).toBe("laptop");
84 expect(environmentAxisValue({ project: "p" }, null)).toBe("all");
85 expect(environmentAxisValue({ machine: "desk" }, "laptop")).toBe("desk");
86 });
87});
88​
89describe("settings project picker", () => {
90 function group(
91 projectKey: string,
92 environmentIds: readonly [EnvironmentId, ...EnvironmentId[]],
93 ): SidebarProjectSnapshot {
94 const members = environmentIds.map((environmentId) => ({
95 id: ProjectId.make(`${projectKey}-${environmentId}`),
96 environmentId,
97 title: projectKey,
98 workspaceRoot: `/repos/${projectKey}`,
99 physicalProjectKey: `${environmentId}:/repos/${projectKey}`,
100 environmentLabel: null,
101 defaultModelSelection: null,
102 scripts: [],
103 createdAt: "2026-10-19T00:00:00.000Z",
104 updatedAt: "2026-10-19T00:00:00.000Z",
105 }));
106 return {
107 ...members[0]!,
108 projectKey,
109 displayName: projectKey,
110 memberProjects: members,
111 memberProjectRefs: members.map((member) => ({
112 environmentId: member.environmentId,
113 projectId: member.id,
114 })),
115 groupedProjectCount: members.length,
116 environmentPresence: environmentIds.length > 1 ? "mixed" : "local-only",
117 allRemoteMembersAreDesktopLocal: false,
118 allRemoteMembersAreWsl: false,
119 remoteEnvironmentLabels: [],
120 };
121 }
122​
123 it("offers groups with any checkout on the chosen environment, or all groups without one", () => {
124 const laptop = EnvironmentId.make("laptop");
125 const server = EnvironmentId.make("server");
126 const local = group("local", [laptop]);
127 const shared = group("shared", [laptop, server]);
128 const remote = group("remote", [server]);
129 const groups = [local, shared, remote];
130​
131 expect(projectScopeMenuGroups(groups, { machine: server })).toEqual([shared, remote]);
132 expect(projectScopeMenuGroups(groups, { machine: laptop })).toEqual([local, shared]);
133 expect(projectScopeMenuGroups(groups, { machine: "unknown" })).toEqual([]);
134 expect(projectScopeMenuGroups(groups, {})).toEqual(groups);
135 expect(projectScopeMenuGroups([], { machine: server })).toEqual([]);
136 expect(projectScopeMenuGroups([], {})).toEqual([]);
137 });
138});