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("can deselect the last environment", () => {
20 expect(toggleUsageEnvironment(new Set([a]), environments, a)).toEqual(new Set());
21 });
22
23 it("does not count removed IDs toward selecting all current environments", () => {
24 expect(toggleUsageEnvironment(new Set([a, removed]), environments, b)).toEqual(new Set([a, b]));
25 });
26
27 it("returns to all mode despite stale IDs when every current environment is selected", () => {
28 expect(toggleUsageEnvironment(new Set([a, c, removed]), environments, b)).toBeNull();
29 });
30
31 it("ignores a menu action for an environment that was removed", () => {
32 expect(toggleUsageEnvironment(new Set([a]), environments, removed)).toEqual(new Set([a]));
33 });
34
35 it("includes newly connected environments only in all mode", () => {
36 const expanded = [...environments, { environmentId: removed }];
37 expect(toggleUsageEnvironment(null, expanded, a)).toEqual(new Set([b, c, removed]));
38 expect(toggleUsageEnvironment(new Set([a, b, c]), expanded, a)).toEqual(new Set([b, c]));
39 });
40});