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

localEnvironment.test.ts

61 lines2.4 KB

1import { assert, describe, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4​
5import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
6import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts";
7import * as DesktopShutdown from "../../app/DesktopShutdown.ts";
8import * as DesktopState from "../../app/DesktopState.ts";
9import * as ElectronApp from "../../electron/ElectronApp.ts";
10import * as ElectronTheme from "../../electron/ElectronTheme.ts";
11import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
12import * as DesktopWindow from "../../window/DesktopWindow.ts";
13import { getLocalEnvironmentEnabled, setLocalEnvironmentEnabled } from "./localEnvironment.ts";
14​
15const layerUnusedLifecycleRuntime = Layer.mergeAll(
16 DesktopShutdown.layer,
17 DesktopState.layer,
18 Layer.succeed(
19 DesktopEnvironment.DesktopEnvironment,
20 DesktopEnvironment.DesktopEnvironment.of(
21 {} as DesktopEnvironment.DesktopEnvironment["Service"],
22 ),
23 ),
24 Layer.mock(DesktopWindow.DesktopWindow, {}),
25 Layer.mock(ElectronApp.ElectronApp, {}),
26 Layer.mock(ElectronTheme.ElectronTheme, {}),
27);
28​
29describe("local environment IPC", () => {
30 it.effect("relaunches only when the setting changes and keeps other settings", () => {
31 const relaunchReasons: Array<string> = [];
32 const layer = Layer.mergeAll(
33 DesktopAppSettings.layerTest({
34 ...DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,
35 wslBackendEnabled: true,
36 }),
37 Layer.mock(DesktopLifecycle.DesktopLifecycle, {
38 relaunch: (reason) =>
39 Effect.sync(() => {
40 relaunchReasons.push(reason);
41 }),
42 }),
43 layerUnusedLifecycleRuntime,
44 );
45 return Effect.gen(function* () {
46 yield* setLocalEnvironmentEnabled.handler(false);
47 assert.isFalse(yield* getLocalEnvironmentEnabled.handler());
48 yield* setLocalEnvironmentEnabled.handler(false);
49 assert.deepEqual(relaunchReasons, ["localEnvironmentEnabled=false"]);
50​
51 yield* setLocalEnvironmentEnabled.handler(true);
52 assert.isTrue(yield* getLocalEnvironmentEnabled.handler());
53 const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
54 assert.isTrue((yield* appSettings.get).wslBackendEnabled);
55 assert.deepEqual(relaunchReasons, [
56 "localEnvironmentEnabled=false",
57 "localEnvironmentEnabled=true",
58 ]);
59 }).pipe(Effect.provide(layer));
60 });
61});