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

usageEnvironmentSelection.test.ts

32 lines1.4 KB

1import { EnvironmentId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { toggleUsageEnvironment } from "./usageEnvironmentSelection";
5​
6const a = EnvironmentId.make("a");
7const b = EnvironmentId.make("b");
8const c = EnvironmentId.make("c");
9const removed = EnvironmentId.make("removed");
10const environments = [a, b, c].map((environmentId) => ({ environmentId }));
11​
12describe("usage environment selection", () => {
13 it("can exclude an environment from all, then select all again", () => {
14 const selected = toggleUsageEnvironment(null, environments, b);
15 expect(selected).toEqual(new Set([a, c]));
16 expect(toggleUsageEnvironment(selected, environments, b)).toBeNull();
17 });
18​
19 it("does not count removed IDs toward selecting all current environments", () => {
20 expect(toggleUsageEnvironment(new Set([a, removed]), environments, b)).toEqual(new Set([a, b]));
21 });
22​
23 it("returns to all mode despite stale IDs when every current environment is selected", () => {
24 expect(toggleUsageEnvironment(new Set([a, c, removed]), environments, b)).toBeNull();
25 });
26​
27 it("includes newly connected environments only in all mode", () => {
28 const expanded = [...environments, { environmentId: removed }];
29 expect(toggleUsageEnvironment(null, expanded, a)).toEqual(new Set([b, c, removed]));
30 expect(toggleUsageEnvironment(new Set([a, b, c]), expanded, a)).toEqual(new Set([b, c]));
31 });
32});