Open History to see the last commit
1import { EnvironmentId } from "@t3tools/contracts";
2import { Atom, AtomRegistry } from "effect/reactivity";
3import { describe, expect, it } from "vite-plus/test";
4
5import { createThemeEnvironmentIdAtom } from "./primaryEnvironment";
6
7const PRIMARY = EnvironmentId.make("primary");
8const SERVICE = EnvironmentId.make("service");
9const REMOTE = EnvironmentId.make("remote");
10
11function themeEnvironmentId(input: {
12 primary: EnvironmentId | null;
13 host: string | null;
14 catalog: ReadonlyArray<EnvironmentId>;
15}) {
16 const atom = createThemeEnvironmentIdAtom({
17 primaryEnvironmentIdAtom: Atom.make(input.primary),
18 hostEnvironmentIdAtom: Atom.make(input.host),
19 catalogValueAtom: Atom.make({ entries: new Map(input.catalog.map((id) => [id, null])) }),
20 });
21 return AtomRegistry.make().get(atom);
22}
23
24describe("themeEnvironmentIdAtom", () => {
25 it("prefers the primary environment over this machine's background service", () => {
26 expect(
27 themeEnvironmentId({ primary: PRIMARY, host: "service", catalog: [PRIMARY, SERVICE] }),
28 ).toBe(PRIMARY);
29 });
30
31 it("uses the connected background service sharing the app's T3 home when there is no primary", () => {
32 expect(themeEnvironmentId({ primary: null, host: "service", catalog: [REMOTE, SERVICE] })).toBe(
33 SERVICE,
34 );
35 });
36
37 it("uses no environment when that service is not among the connections", () => {
38 expect(themeEnvironmentId({ primary: null, host: "service", catalog: [REMOTE] })).toBeNull();
39 expect(themeEnvironmentId({ primary: null, host: null, catalog: [REMOTE] })).toBeNull();
40 });
41});