| 1 | import type { ServerConfig } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { resolveEnvironmentIconPickerLock } from "./EnvironmentIconPicker"; |
| 5 | |
| 6 | const config = (environmentIcon: boolean | undefined) => |
| 7 | ({ |
| 8 | environment: { capabilities: environmentIcon === undefined ? {} : { environmentIcon } }, |
| 9 | }) as unknown as ServerConfig; |
| 10 | |
| 11 | describe("resolveEnvironmentIconPickerLock", () => { |
| 12 | it("locks until the environment is connected", () => { |
| 13 | expect( |
| 14 | resolveEnvironmentIconPickerLock({ serverConfig: null, operateAccess: "granted" }), |
| 15 | ).toMatch(/Connect/); |
| 16 | }); |
| 17 | |
| 18 | it("locks on servers that predate the setting, before looking at permissions", () => { |
| 19 | expect( |
| 20 | resolveEnvironmentIconPickerLock({ |
| 21 | serverConfig: config(undefined), |
| 22 | operateAccess: "denied", |
| 23 | }), |
| 24 | ).toMatch(/too old/); |
| 25 | }); |
| 26 | |
| 27 | it("locks when the session cannot operate the environment", () => { |
| 28 | expect( |
| 29 | resolveEnvironmentIconPickerLock({ serverConfig: config(true), operateAccess: "denied" }), |
| 30 | ).toMatch(/cannot change/); |
| 31 | }); |
| 32 | |
| 33 | it("waits for a settings grant before allowing changes", () => { |
| 34 | expect( |
| 35 | resolveEnvironmentIconPickerLock({ serverConfig: config(true), operateAccess: "pending" }), |
| 36 | ).toMatch(/cannot change/); |
| 37 | expect( |
| 38 | resolveEnvironmentIconPickerLock({ serverConfig: config(true), operateAccess: "granted" }), |
| 39 | ).toBeNull(); |
| 40 | }); |
| 41 | }); |