diff --git a/src/renderer/components/dock/__test__/dock-store.test.ts b/src/renderer/components/dock/__test__/dock-store.test.ts index 98f8d2787f..ef1f575a1d 100644 --- a/src/renderer/components/dock/__test__/dock-store.test.ts +++ b/src/renderer/components/dock/__test__/dock-store.test.ts @@ -3,6 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ +import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; import hostedClusterIdInjectable from "../../../../common/cluster-store/hosted-cluster-id.injectable"; import ipcRendererInjectable from "../../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable"; import { getDiForUnitTesting } from "../../../getDiForUnitTesting"; @@ -29,8 +30,7 @@ describe("DockStore", () => { on: jest.fn(), invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge } as never)); - - await di.runSetups(); + di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data"); dockStore = di.inject(dockStoreInjectable); }); diff --git a/src/renderer/getDiForUnitTesting.tsx b/src/renderer/getDiForUnitTesting.tsx index cabd29791f..e994304bfe 100644 --- a/src/renderer/getDiForUnitTesting.tsx +++ b/src/renderer/getDiForUnitTesting.tsx @@ -4,7 +4,7 @@ */ import glob from "glob"; -import { isEqual, isPlainObject, memoize } from "lodash/fp"; +import { memoize } from "lodash/fp"; import { createContainer } from "@ogre-tools/injectable"; import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import getValueFromRegisteredChannelInjectable from "./app-paths/get-value-from-registered-channel/get-value-from-registered-channel.injectable"; @@ -32,24 +32,13 @@ import { joinPathsFake } from "../common/test-utils/join-paths-fake"; import hotbarStoreInjectable from "../common/hotbars/store.injectable"; import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-spawning-pool.injectable"; import hostedClusterIdInjectable from "../common/cluster-store/hosted-cluster-id.injectable"; -import createStorageInjectable from "./utils/create-storage/create-storage.injectable"; -import { observable, toJS } from "mobx"; -import type { Draft } from "immer"; -import { produce, isDraft } from "immer"; import type { GetDiForUnitTestingOptions } from "../test-utils/get-dis-for-unit-testing"; import historyInjectable from "./navigation/history.injectable"; -export interface GetRendererDiForUnitTestingOptions extends GetDiForUnitTestingOptions { - overrideCreateStorage?: boolean; -} - -export const getDiForUnitTesting = (opts: GetRendererDiForUnitTestingOptions = {}) => { +export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => { const { doGeneralOverrides = false, } = opts; - const { - overrideCreateStorage = doGeneralOverrides, - } = opts; const di = createContainer(); setLegacyGlobalDiForExtensionApi(di, Environments.renderer); @@ -105,43 +94,6 @@ export const getDiForUnitTesting = (opts: GetRendererDiForUnitTestingOptions = { })); } - if (overrideCreateStorage) { - di.override(createStorageInjectable, () => function (key: string, defaultValue: MockT) { - const srcValue = observable.box(defaultValue); - - return { - get: () => srcValue.get(), - isDefaultValue: val => isEqual(val, defaultValue), - merge: (value: Partial | ((draft: Draft) => void | Partial)) => { - const nextValue = produce(toJS(srcValue.get()), (draft) => { - - if (typeof value == "function") { - const newValue = value(draft); - - // merge returned plain objects from `value-as-callback` usage - // otherwise `draft` can be just modified inside a callback without returning any value (void) - if (newValue && !isDraft(newValue)) { - Object.assign(draft, newValue); - } - } else if (isPlainObject(value)) { - Object.assign(draft, value); - } - - return draft; - }); - - srcValue.set(nextValue); - }, - reset: () => srcValue.set(defaultValue), - set: (val: MockT) => srcValue.set(val), - get value() { - return srcValue.get(); - }, - whenReady: Promise.resolve(), - }; - }); - } - return di; };