|
| 1 | +import { EnvironmentId, ProjectId } from "@t3tools/contracts"; |
1 | 2 | import { describe, expect, it } from "vite-plus/test"; |
2 | 3 |
|
3 | | -import { projectGroupTitleNeedsUpdate } from "./ProjectSettingsPanel.logic"; |
| 4 | +import { buildSidebarProjectSnapshots } from "../../sidebarProjectGrouping"; |
| 5 | +import type { Project } from "../../types"; |
| 6 | +import { |
| 7 | + projectGroupTitleNeedsUpdate, |
| 8 | + scopeProjectSettingsGroup, |
| 9 | +} from "./ProjectSettingsPanel.logic"; |
| 10 | + |
| 11 | +const localEnvironmentId = EnvironmentId.make("local"); |
| 12 | +const remoteEnvironmentId = EnvironmentId.make("remote"); |
| 13 | +const customIcon = { kind: "lucide", name: "cloud", color: "red" } as const; |
| 14 | + |
| 15 | +function makeProject(environmentId: EnvironmentId, overrides: Partial<Project> = {}): Project { |
| 16 | + return { |
| 17 | + environmentId, |
| 18 | + id: ProjectId.make(`${environmentId}-project`), |
| 19 | + title: "repo", |
| 20 | + workspaceRoot: `/${environmentId}/repo`, |
| 21 | + repositoryIdentity: { |
| 22 | + canonicalKey: "github.com/owner/repo", |
| 23 | + locator: { |
| 24 | + source: "git-remote", |
| 25 | + remoteName: "origin", |
| 26 | + remoteUrl: "https://github.com/owner/repo.git", |
| 27 | + }, |
| 28 | + provider: "github", |
| 29 | + owner: "owner", |
| 30 | + name: "repo", |
| 31 | + displayName: "owner/repo", |
| 32 | + }, |
| 33 | + defaultModelSelection: null, |
| 34 | + faviconPath: null, |
| 35 | + projectIcon: null, |
| 36 | + scripts: [], |
| 37 | + createdAt: "2026-07-01T00:00:00.000Z", |
| 38 | + updatedAt: "2026-07-01T00:00:00.000Z", |
| 39 | + ...overrides, |
| 40 | + }; |
| 41 | +} |
| 42 | + |
| 43 | +function projectGroup(projects: Project[]) { |
| 44 | + return buildSidebarProjectSnapshots({ |
| 45 | + projects, |
| 46 | + settings: { sidebarProjectGroupingMode: "repository", sidebarProjectGroupingOverrides: {} }, |
| 47 | + primaryEnvironmentId: localEnvironmentId, |
| 48 | + resolveEnvironmentLabel: (id) => id, |
| 49 | + })[0]!; |
| 50 | +} |
| 51 | + |
| 52 | +describe("scopeProjectSettingsGroup", () => { |
| 53 | + it("keeps the sidebar icon when the remote checkout was registered first", () => { |
| 54 | + const group = projectGroup([ |
| 55 | + makeProject(remoteEnvironmentId), |
| 56 | + makeProject(localEnvironmentId, { projectIcon: customIcon }), |
| 57 | + ]); |
| 58 | + const scoped = scopeProjectSettingsGroup(group, group.memberProjects); |
| 59 | + |
| 60 | + expect(scoped.environmentId).toBe(localEnvironmentId); |
| 61 | + expect(scoped.projectIcon).toEqual(customIcon); |
| 62 | + expect(scoped.memberProjects).toHaveLength(2); |
| 63 | + expect(scoped.memberProjects[0]?.projectIcon).toBeNull(); |
| 64 | + }); |
| 65 | + |
| 66 | + it("keeps the favicon source and automatic title with the sidebar representative", () => { |
| 67 | + const group = projectGroup([ |
| 68 | + makeProject(remoteEnvironmentId, { title: "Remote repo", faviconPath: "remote.svg" }), |
| 69 | + makeProject(localEnvironmentId, { title: "Local repo", faviconPath: "local.svg" }), |
| 70 | + ]); |
| 71 | + const scoped = scopeProjectSettingsGroup(group, group.memberProjects); |
| 72 | + |
| 73 | + expect(scoped).toMatchObject({ |
| 74 | + environmentId: localEnvironmentId, |
| 75 | + workspaceRoot: "/local/repo", |
| 76 | + title: "Local repo", |
| 77 | + faviconPath: "local.svg", |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + it("uses the selected environment when it excludes the sidebar representative", () => { |
| 82 | + const group = projectGroup([ |
| 83 | + makeProject(remoteEnvironmentId, { faviconPath: "remote.svg" }), |
| 84 | + makeProject(localEnvironmentId, { projectIcon: customIcon }), |
| 85 | + ]); |
| 86 | + const members = group.memberProjects.filter( |
| 87 | + (member) => member.environmentId === remoteEnvironmentId, |
| 88 | + ); |
| 89 | + const scoped = scopeProjectSettingsGroup(group, members); |
| 90 | + |
| 91 | + expect(scoped).toMatchObject({ |
| 92 | + environmentId: remoteEnvironmentId, |
| 93 | + id: "remote-project", |
| 94 | + workspaceRoot: "/remote/repo", |
| 95 | + faviconPath: "remote.svg", |
| 96 | + projectIcon: null, |
| 97 | + }); |
| 98 | + expect(scoped.memberProjects).toHaveLength(1); |
| 99 | + expect(group.projectIcon).toEqual(customIcon); |
| 100 | + }); |
| 101 | + |
| 102 | + it("uses the selected physical checkout among siblings on the same environment", () => { |
| 103 | + const group = projectGroup([ |
| 104 | + makeProject(localEnvironmentId, { projectIcon: customIcon }), |
| 105 | + makeProject(localEnvironmentId, { |
| 106 | + id: ProjectId.make("other-checkout"), |
| 107 | + workspaceRoot: "/local/other-repo", |
| 108 | + projectIcon: { kind: "emoji", emoji: "🐦" }, |
| 109 | + }), |
| 110 | + ]); |
| 111 | + const members = group.memberProjects.filter((member) => member.id === "other-checkout"); |
| 112 | + const scoped = scopeProjectSettingsGroup(group, members); |
| 113 | + |
| 114 | + expect(scoped).toMatchObject({ |
| 115 | + environmentId: localEnvironmentId, |
| 116 | + id: "other-checkout", |
| 117 | + workspaceRoot: "/local/other-repo", |
| 118 | + projectIcon: { kind: "emoji", emoji: "🐦" }, |
| 119 | + }); |
| 120 | + expect(scoped.memberProjects).toHaveLength(1); |
| 121 | + }); |
| 122 | +}); |
4 | 123 |
|
5 | 124 | describe("projectGroupTitleNeedsUpdate", () => { |
6 | 125 | it("updates divergent member titles even when the next title is the derived group label", () => { |
|
0 commit comments