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

EnvironmentIconPicker.test.ts

41 lines1.4 KB

1import type { ServerConfig } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { resolveEnvironmentIconPickerLock } from "./EnvironmentIconPicker";
5​
6const config = (environmentIcon: boolean | undefined) =>
7 ({
8 environment: { capabilities: environmentIcon === undefined ? {} : { environmentIcon } },
9 }) as unknown as ServerConfig;
10​
11describe("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});