mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
remove complex createStorage override
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2a8ca21fc9
commit
f2a0b72253
@ -3,6 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* 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 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 ipcRendererInjectable from "../../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||||
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
||||||
@ -29,8 +30,7 @@ describe("DockStore", () => {
|
|||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
||||||
} as never));
|
} as never));
|
||||||
|
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||||
await di.runSetups();
|
|
||||||
|
|
||||||
dockStore = di.inject(dockStoreInjectable);
|
dockStore = di.inject(dockStoreInjectable);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import glob from "glob";
|
import glob from "glob";
|
||||||
import { isEqual, isPlainObject, memoize } from "lodash/fp";
|
import { memoize } from "lodash/fp";
|
||||||
import { createContainer } from "@ogre-tools/injectable";
|
import { createContainer } from "@ogre-tools/injectable";
|
||||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
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";
|
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 hotbarStoreInjectable from "../common/hotbars/store.injectable";
|
||||||
import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-spawning-pool.injectable";
|
import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-spawning-pool.injectable";
|
||||||
import hostedClusterIdInjectable from "../common/cluster-store/hosted-cluster-id.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 type { GetDiForUnitTestingOptions } from "../test-utils/get-dis-for-unit-testing";
|
||||||
import historyInjectable from "./navigation/history.injectable";
|
import historyInjectable from "./navigation/history.injectable";
|
||||||
|
|
||||||
export interface GetRendererDiForUnitTestingOptions extends GetDiForUnitTestingOptions {
|
export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => {
|
||||||
overrideCreateStorage?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getDiForUnitTesting = (opts: GetRendererDiForUnitTestingOptions = {}) => {
|
|
||||||
const {
|
const {
|
||||||
doGeneralOverrides = false,
|
doGeneralOverrides = false,
|
||||||
} = opts;
|
} = opts;
|
||||||
const {
|
|
||||||
overrideCreateStorage = doGeneralOverrides,
|
|
||||||
} = opts;
|
|
||||||
const di = createContainer();
|
const di = createContainer();
|
||||||
|
|
||||||
setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
|
setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
|
||||||
@ -105,43 +94,6 @@ export const getDiForUnitTesting = (opts: GetRendererDiForUnitTestingOptions = {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overrideCreateStorage) {
|
|
||||||
di.override(createStorageInjectable, () => function <MockT>(key: string, defaultValue: MockT) {
|
|
||||||
const srcValue = observable.box(defaultValue);
|
|
||||||
|
|
||||||
return {
|
|
||||||
get: () => srcValue.get(),
|
|
||||||
isDefaultValue: val => isEqual(val, defaultValue),
|
|
||||||
merge: (value: Partial<MockT> | ((draft: Draft<MockT>) => void | Partial<MockT>)) => {
|
|
||||||
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;
|
return di;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user