|
1 | | -import { EnvironmentId } from "@t3tools/contracts"; |
| 1 | +import { EnvironmentId, ProjectId } from "@t3tools/contracts"; |
2 | 2 | import { describe, expect, it } from "vite-plus/test"; |
3 | 3 |
|
| 4 | +import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping"; |
4 | 5 | import { |
5 | 6 | environmentAxisValue, |
6 | 7 | projectAxisValue, |
| 8 | + projectScopeMenuGroups, |
7 | 9 | selectEnvironmentAxis, |
8 | 10 | selectProjectAxis, |
9 | 11 | settingsScopeEnvironmentLabel, |
@@ -83,3 +85,54 @@ describe("environmentAxisValue", () => { |
83 | 85 | expect(environmentAxisValue({ machine: "desk" }, "laptop")).toBe("desk"); |
84 | 86 | }); |
85 | 87 | }); |
| 88 | + |
| 89 | +describe("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 | +}); |
0 commit comments