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

settingsScopeAxis.test.ts

85 lines3.0 KB

1import { EnvironmentId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 environmentAxisValue,
6 projectAxisValue,
7 selectEnvironmentAxis,
8 selectProjectAxis,
9 settingsScopeEnvironmentLabel,
10} from "./settingsScopeAxis";
11​
12const first = {
13 environmentId: EnvironmentId.make("first"),
14 label: "Development",
15 displayUrl: "https://first.example.com",
16};
17const second = {
18 environmentId: EnvironmentId.make("second"),
19 label: "Development",
20 displayUrl: "https://second.example.com",
21};
22​
23describe("settings scope environment labels", () => {
24 it("distinguishes same-name environments by address", () => {
25 const environments = [first, second];
26 expect(
27 environments.map((environment) => settingsScopeEnvironmentLabel(environment, environments)),
28 ).toEqual(["Development · first.example.com", "Development · second.example.com"]);
29 });
30​
31 it("falls back to environment IDs when duplicate names have no display URL", () => {
32 const environments = [first, second].map((environment) => ({
33 ...environment,
34 displayUrl: null,
35 }));
36 expect(
37 environments.map((environment) => settingsScopeEnvironmentLabel(environment, environments)),
38 ).toEqual(["Development · first", "Development · second"]);
39 });
40​
41 it("keeps unique names compact and removes disambiguation after a rename", () => {
42 expect(settingsScopeEnvironmentLabel(first, [first])).toBe("Development");
43 expect(settingsScopeEnvironmentLabel(first, [first, { ...second, label: "Production" }])).toBe(
44 "Development",
45 );
46 });
47});
48​
49describe("settings scope axes", () => {
50 it("maps each axis to its search key and back", () => {
51 expect(projectAxisValue({})).toBe("all");
52 expect(projectAxisValue({ project: "app" })).toBe("app");
53 expect(selectProjectAxis({ machine: "second" }, "app")).toEqual({
54 project: "app",
55 machine: "second",
56 });
57 expect(selectProjectAxis({ machine: "second", project: "app" }, "all")).toEqual({
58 machine: "second",
59 });
60 expect(selectEnvironmentAxis({ project: "app" }, "first")).toEqual({
61 project: "app",
62 machine: "first",
63 });
64 expect(selectEnvironmentAxis({ project: "app", machine: "first" }, "all")).toEqual({
65 project: "app",
66 });
67 });
68​
69 it("drops a checkout narrowing from older links when either axis changes", () => {
70 const checkout = { project: "app", checkout: "app@first", machine: "first" };
71 expect(selectEnvironmentAxis(checkout, "second")).toEqual({
72 project: "app",
73 machine: "second",
74 });
75 expect(selectProjectAxis(checkout, "app")).toEqual({ project: "app", machine: "first" });
76 });
77});
78​
79describe("environmentAxisValue", () => {
80 it("shows the checkout's environment for a legacy checkout link", () => {
81 expect(environmentAxisValue({ project: "p", checkout: "c" }, "laptop")).toBe("laptop");
82 expect(environmentAxisValue({ project: "p" }, null)).toBe("all");
83 expect(environmentAxisValue({ machine: "desk" }, "laptop")).toBe("desk");
84 });
85});