|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
2 | 2 |
|
3 | | -import { selectEnvironmentAxis, selectProjectAxis } from "./settingsScopeAxis"; |
| 3 | +import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping"; |
| 4 | +import { |
| 5 | + selectCheckoutAxis, |
| 6 | + selectEnvironmentAxis, |
| 7 | + selectProjectAxis, |
| 8 | + settingsScopeCheckoutChoices, |
| 9 | +} from "./settingsScopeAxis"; |
| 10 | + |
| 11 | +const checkout = (environmentId: string, physicalProjectKey: string) => |
| 12 | + ({ environmentId, physicalProjectKey }) as SidebarProjectSnapshot["memberProjects"][number]; |
| 13 | +const group = (...memberProjects: SidebarProjectSnapshot["memberProjects"]) => |
| 14 | + ({ memberProjects }) as SidebarProjectSnapshot; |
4 | 15 |
|
5 | 16 | describe("settings scope axes", () => { |
6 | 17 | it("drops a checkout narrowing from older links when either axis changes", () => { |
7 | | - const checkout = { project: "app", checkout: "app@first", machine: "first" }; |
8 | | - expect(selectEnvironmentAxis(checkout, "second")).toEqual({ |
| 18 | + const legacy = { project: "app", checkout: "app@first", machine: "first" }; |
| 19 | + expect(selectEnvironmentAxis(legacy, "second")).toEqual({ |
9 | 20 | project: "app", |
10 | 21 | machine: "second", |
11 | 22 | }); |
12 | | - expect(selectProjectAxis(checkout, "app")).toEqual({ project: "app", machine: "first" }); |
| 23 | + expect(selectProjectAxis(legacy, "app")).toEqual({ project: "app", machine: "first" }); |
| 24 | + }); |
| 25 | + |
| 26 | + it("offers checkouts only where an environment cannot tell them apart", () => { |
| 27 | + const a = checkout("laptop", "a"); |
| 28 | + const b = checkout("laptop", "b"); |
| 29 | + const c = checkout("server", "c"); |
| 30 | + |
| 31 | + expect(settingsScopeCheckoutChoices(group(a, b, c), { machine: "laptop" })).toEqual([a, b]); |
| 32 | + expect(settingsScopeCheckoutChoices(group(a, b), {})).toEqual([a, b]); |
| 33 | + expect(settingsScopeCheckoutChoices(group(a, b, c), { checkout: "b" })).toEqual([a, b]); |
| 34 | + expect(settingsScopeCheckoutChoices(group(a, b, c), {})).toEqual([]); |
| 35 | + expect(settingsScopeCheckoutChoices(group(a, b, c), { machine: "server" })).toEqual([]); |
| 36 | + }); |
| 37 | + |
| 38 | + it("narrows to one checkout and back without losing the chosen environment", () => { |
| 39 | + const search = { project: "app", machine: "laptop" }; |
| 40 | + const narrowed = selectCheckoutAxis(search, checkout("laptop", "b")); |
| 41 | + |
| 42 | + expect(narrowed).toEqual({ project: "app", machine: "laptop", checkout: "b" }); |
| 43 | + expect(selectCheckoutAxis(narrowed, null)).toEqual(search); |
| 44 | + expect(selectCheckoutAxis({ project: "app" }, checkout("laptop", "b"))).toEqual(narrowed); |
| 45 | + expect(selectCheckoutAxis({ project: "app", checkout: "b" }, null)).toEqual({ project: "app" }); |
13 | 46 | }); |
14 | 47 | }); |
0 commit comments