1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

chore: Adapt to injectable feature-wrappers

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2023-04-14 08:47:06 +03:00
parent 19c24b0998
commit 13f1d6f7f3
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
29 changed files with 79 additions and 60 deletions

View File

@ -32,6 +32,7 @@
},
"peerDependencies": {
"@k8slens/feature-core": "^6.5.0-alpha.0",
"@k8slens/basic-dependency-features": "^1.0.0-alpha.0",
"@k8slens/react-application": "^1.0.0-alpha.0",
"@ogre-tools/fp": "^15.3.1",
"@ogre-tools/injectable": "^15.3.1",

View File

@ -1,6 +1,7 @@
import { getFeature } from "@k8slens/feature-core";
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
import { reactApplicationFeature } from "@k8slens/react-application";
import { injectableMobXFeature, injectableReactFeature } from "@k8slens/basic-dependency-features";
export const keyboardShortcutsFeature = getFeature({
id: "keyboard-shortcuts",
@ -13,5 +14,5 @@ export const keyboardShortcutsFeature = getFeature({
});
},
dependencies: [reactApplicationFeature],
dependencies: [injectableReactFeature, injectableMobXFeature, reactApplicationFeature],
});

View File

@ -2,8 +2,6 @@ import userEvent from "@testing-library/user-event";
import type { RenderResult } from "@testing-library/react";
import { render } from "@testing-library/react";
import { createContainer, DiContainer, getInjectable } from "@ogre-tools/injectable";
import { registerInjectableReact } from "@ogre-tools/injectable-react";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { keyboardShortcutInjectionToken } from "./keyboard-shortcut-injection-token";
import { registerFeature } from "@k8slens/feature-core";
import { keyboardShortcutsFeature } from "./feature";
@ -24,9 +22,6 @@ describe("keyboard-shortcuts", () => {
beforeEach(() => {
di = createContainer("irrelevant");
registerInjectableReact(di);
registerMobX(di);
runInAction(() => {
registerFeature(di, keyboardShortcutsFeature);
});

View File

@ -312,6 +312,7 @@
"peerDependencies": {
"@k8slens/application": "^6.5.0-alpha.0",
"@k8slens/application-for-electron-main": "^6.5.0-alpha.0",
"@k8slens/basic-dependency-features": "^1.0.0-alpha.0",
"@k8slens/cluster-settings": "^6.5.0-alpha.1",
"@k8slens/dock": "^1.0.0-alpha.0",
"@k8slens/kubectl-versions": "^1.0.0-alpha.0",

View File

@ -25,9 +25,9 @@ import initializeClusterManagerInjectable from "./cluster/initialize-manager.inj
import type { GlobalOverride } from "@k8slens/test-utils";
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
import { setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { registerFeature } from "@k8slens/feature-core";
import { messagingFeature, testUtils as messagingTestUtils } from "@k8slens/messaging";
import { injectableMobXFeature } from "@k8slens/basic-dependency-features";
export function getDiForUnitTesting() {
const environment = "main";
@ -35,12 +35,15 @@ export function getDiForUnitTesting() {
detectCycles: false,
});
registerMobX(di);
setLegacyGlobalDiForExtensionApi(di, environment);
runInAction(() => {
registerFeature(di, messagingFeature, messagingTestUtils.messagingFeatureForUnitTesting);
registerFeature(
di,
injectableMobXFeature,
messagingFeature,
messagingTestUtils.messagingFeatureForUnitTesting,
);
});
di.preventSideEffects();

View File

@ -15,10 +15,9 @@ import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.in
import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable";
import type { GlobalOverride } from "@k8slens/test-utils";
import { setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { registerInjectableReact } from "@ogre-tools/injectable-react";
import { registerFeature } from "@k8slens/feature-core";
import { messagingFeature, testUtils as messagingTestUtils } from "@k8slens/messaging";
import { injectableReactFeature, injectableMobXFeature } from "@k8slens/basic-dependency-features";
export const getDiForUnitTesting = () => {
const environment = "renderer";
@ -26,12 +25,16 @@ export const getDiForUnitTesting = () => {
detectCycles: false,
});
registerMobX(di);
registerInjectableReact(di);
setLegacyGlobalDiForExtensionApi(di, environment);
runInAction(() => {
registerFeature(di, messagingFeature, messagingTestUtils.messagingFeatureForUnitTesting);
registerFeature(
di,
injectableReactFeature,
injectableMobXFeature,
messagingFeature,
messagingTestUtils.messagingFeatureForUnitTesting
);
});
di.preventSideEffects();

View File

@ -190,6 +190,7 @@
"@k8slens/core": "^6.5.0-alpha.6",
"@k8slens/ensure-binaries": "^6.5.0-alpha.2",
"@k8slens/feature-core": "^6.5.0-alpha.2",
"@k8slens/basic-dependency-features": "^1.0.0-alpha.0",
"@k8slens/keyboard-shortcuts": "^1.0.0-alpha.2",
"@k8slens/kubectl-versions": "^1.0.0-alpha.0",
"@k8slens/legacy-extension-example": "^1.0.0-alpha.4",

View File

@ -6,11 +6,11 @@ import {
registerLensCore,
} from "@k8slens/core/main";
import { createContainer } from "@ogre-tools/injectable";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { registerFeature } from "@k8slens/feature-core";
import { applicationFeature, startApplicationInjectionToken } from '@k8slens/application'
import { applicationFeatureForElectronMain } from '@k8slens/application-for-electron-main'
import { messagingFeatureForMain } from "@k8slens/messaging-for-main";
import { injectableMobXFeature } from "@k8slens/basic-dependency-features";
const environment = "main";
@ -18,12 +18,16 @@ const di = createContainer(environment, {
detectCycles: false,
});
registerMobX(di);
runInAction(() => {
registerLensCore(di, environment);
registerFeature(di, applicationFeature, applicationFeatureForElectronMain, messagingFeatureForMain);
registerFeature(
di,
injectableMobXFeature,
applicationFeature,
applicationFeatureForElectronMain,
messagingFeatureForMain
);
try {
autoRegister({

View File

@ -13,12 +13,11 @@ import {
startApplicationInjectionToken,
} from "@k8slens/application";
import { createContainer } from "@ogre-tools/injectable";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { registerInjectableReact } from "@ogre-tools/injectable-react";
import { messagingFeatureForRenderer } from "@k8slens/messaging-for-renderer";
import { keyboardShortcutsFeature } from "@k8slens/keyboard-shortcuts";
import { reactApplicationFeature } from "@k8slens/react-application";
import { dockFeature } from "@k8slens/dock";
import { injectableReactFeature, injectableMobXFeature } from "@k8slens/basic-dependency-features";
const environment = "renderer";
@ -27,12 +26,12 @@ const di = createContainer(environment, {
});
runInAction(() => {
registerMobX(di);
registerInjectableReact(di);
registerLensCore(di, environment);
registerFeature(
di,
injectableReactFeature,
injectableMobXFeature,
applicationFeature,
messagingFeatureForRenderer,
keyboardShortcutsFeature,

View File

@ -33,6 +33,7 @@
"peerDependencies": {
"@k8slens/application": "^6.5.0-alpha.0",
"@k8slens/feature-core": "^6.5.0-alpha.0",
"@k8slens/basic-dependency-features": "^1.0.0-alpha.0",
"@k8slens/startable-stoppable": "^1.0.0-alpha.1",
"@ogre-tools/injectable": "^15.3.1",
"@ogre-tools/injectable-extension-for-auto-registration": "^15.3.0",

View File

@ -1,11 +1,12 @@
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
import { applicationFeature } from "@k8slens/application";
import { getFeature } from "@k8slens/feature-core";
import { injectableMobXFeature } from "@k8slens/basic-dependency-features";
export const messagingFeature = getFeature({
id: "messaging",
dependencies: [applicationFeature],
dependencies: [injectableMobXFeature, applicationFeature],
register: (di) => {
autoRegister({

View File

@ -1,7 +1,6 @@
import { createContainer, DiContainer, Injectable } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { runInAction } from "mobx";
import {
@ -31,8 +30,6 @@ describe("listening-of-messages", () => {
beforeEach(() => {
di = createContainer("irrelevant");
registerMobX(di);
disposeSomeListenerMock = jest.fn();
disposeSomeUnrelatedListenerMock = jest.fn();

View File

@ -1,7 +1,6 @@
import { createContainer, DiContainer, Injectable } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { _resetGlobalState, configure, runInAction } from "mobx";
import {
@ -37,8 +36,6 @@ describe("listening-of-requests", () => {
di = createContainer("irrelevant");
registerMobX(di);
disposeSomeListenerMock = jest.fn();
disposeSomeUnrelatedListenerMock = jest.fn();

View File

@ -6,7 +6,6 @@ import { startApplicationInjectionToken } from "@k8slens/application";
import { computed, IComputedValue, IObservableValue, observable, reaction, runInAction } from "mobx";
import type { MessageChannel } from "@k8slens/messaging";
import { getMessageChannelListenerInjectable } from "@k8slens/messaging";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { registerFeature } from "@k8slens/feature-core";
import { testUtils } from "@k8slens/messaging";
import { computedChannelInjectionToken, computedChannelObserverInjectionToken } from "./computed-channel.injectable";
@ -40,8 +39,6 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
di1 = createContainer("some-container-1");
di2 = createContainer("some-container-2");
registerMobX(di1);
registerMobX(di2);
const administrationChannelTestListenerInjectable = getMessageChannelListenerInjectable({
id: "administration-channel-test-listener",

View File

@ -4,6 +4,7 @@ import { EnlistMessageChannelListener, enlistMessageChannelListenerInjectionToke
import { createContainer } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import { messagingFeatureForMain } from "../feature";
import { runInAction } from "mobx";
describe("enlist message channel listener in main", () => {
let enlistMessageChannelListener: EnlistMessageChannelListener;
@ -14,7 +15,9 @@ describe("enlist message channel listener in main", () => {
beforeEach(() => {
const di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForMain);
});
onMock = jest.fn();
offMock = jest.fn();

View File

@ -9,6 +9,7 @@ import { getPromiseStatus } from "@k8slens/test-utils";
import { createContainer } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import { messagingFeatureForMain } from "../feature";
import { runInAction } from "mobx";
type TestRequestChannel = RequestChannel<unknown, unknown>;
@ -25,7 +26,9 @@ describe("enlist request channel listener in main", () => {
beforeEach(() => {
const di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForMain);
});
handleMock = jest.fn();
offMock = jest.fn();

View File

@ -3,6 +3,7 @@ import { registerFeature } from "@k8slens/feature-core";
import ipcMainInjectable from "./ipc-main.injectable";
import { ipcMain } from "electron";
import { messagingFeatureForMain } from "../feature";
import { runInAction } from "mobx";
describe("ipc-main", () => {
let di: DiContainer;
@ -10,8 +11,10 @@ describe("ipc-main", () => {
beforeEach(() => {
di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForMain);
});
});
it("is the actual IPC-main of Electron", () => {
const actual = di.inject(ipcMainInjectable);

View File

@ -5,6 +5,7 @@ import { getMessageChannel, sendMessageToChannelInjectionToken } from "@k8slens/
import getWebContentsInjectable from "./get-web-contents.injectable";
import type { WebContents } from "electron";
import allowCommunicationListenerInjectable from "./allow-communication-listener.injectable";
import { runInAction } from "mobx";
const someChannel = getMessageChannel<string>("some-channel");
@ -14,8 +15,10 @@ describe("send-message-to-channel", () => {
beforeEach(() => {
di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForMain);
});
});
it("given no web contents, when sending a message, does not do anything", () => {
di.override(getWebContentsInjectable, () => () => []);

View File

@ -1,5 +1,4 @@
import { createContainer, DiContainer } from "@ogre-tools/injectable";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { startApplicationInjectionToken } from "@k8slens/application";
import { registerFeature } from "@k8slens/feature-core";
import { messagingFeatureForRenderer } from "./feature";
@ -15,8 +14,6 @@ describe("allow communication to iframe", () => {
beforeEach(() => {
di = createContainer("irrelevant");
registerMobX(di);
runInAction(() => {
registerFeature(di, messagingFeatureForRenderer);
});

View File

@ -3,6 +3,7 @@ import { registerFeature } from "@k8slens/feature-core";
import ipcRendererInjectable from "./ipc-renderer.injectable";
import { messagingFeatureForRenderer } from "../feature";
import { ipcRenderer } from "electron";
import { runInAction } from "mobx";
describe("ipc-renderer", () => {
let di: DiContainer;
@ -10,8 +11,10 @@ describe("ipc-renderer", () => {
beforeEach(() => {
di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForRenderer);
});
});
it("is not undefined", () => {
const actual = di.inject(ipcRendererInjectable);

View File

@ -4,6 +4,7 @@ import { EnlistMessageChannelListener, enlistMessageChannelListenerInjectionToke
import { createContainer } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import { messagingFeatureForRenderer } from "../feature";
import { runInAction } from "mobx";
describe("enlist message channel listener in renderer", () => {
let enlistMessageChannelListener: EnlistMessageChannelListener;
@ -14,7 +15,9 @@ describe("enlist message channel listener in renderer", () => {
beforeEach(() => {
const di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForRenderer);
});
onMock = jest.fn();
offMock = jest.fn();

View File

@ -3,6 +3,7 @@ import { registerFeature } from "@k8slens/feature-core";
import { messagingFeatureForRenderer } from "../feature";
import { ipcRenderer } from "electron";
import invokeIpcInjectable from "./invoke-ipc.injectable";
import { runInAction } from "mobx";
describe("ipc-renderer", () => {
let di: DiContainer;
@ -10,8 +11,10 @@ describe("ipc-renderer", () => {
beforeEach(() => {
di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForRenderer);
});
});
it("is IPC-renderer invoke of Electron", () => {
const actual = di.inject(invokeIpcInjectable);

View File

@ -1,11 +1,12 @@
import { createContainer, DiContainer } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import type { RequestChannel } from "@k8slens/messaging";
import { requestFromChannelInjectionToken } from "@k8slens/messaging";
import { messagingFeatureForRenderer } from "../feature";
import type { RequestChannel } from "@k8slens/messaging";
import invokeIpcInjectable from "./invoke-ipc.injectable";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import { runInAction } from "mobx";
describe("request-from-channel", () => {
let di: DiContainer;
@ -14,7 +15,9 @@ describe("request-from-channel", () => {
beforeEach(() => {
di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForRenderer);
});
invokeIpcMock = asyncFn();
di.override(invokeIpcInjectable, () => invokeIpcMock);

View File

@ -1,11 +1,12 @@
import { createContainer, DiContainer } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import type { MessageChannel } from "@k8slens/messaging";
import { sendMessageToChannelInjectionToken } from "@k8slens/messaging";
import { messagingFeatureForRenderer } from "../feature";
import type { MessageChannel } from "@k8slens/messaging";
import sendToIpcInjectable from "./send-to-ipc.injectable";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import { runInAction } from "mobx";
describe("message-from-channel", () => {
let di: DiContainer;
@ -14,7 +15,9 @@ describe("message-from-channel", () => {
beforeEach(() => {
di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForRenderer);
});
sendToIpcMock = asyncFn();
di.override(sendToIpcInjectable, () => sendToIpcMock);

View File

@ -3,6 +3,7 @@ import { registerFeature } from "@k8slens/feature-core";
import { messagingFeatureForRenderer } from "../feature";
import { ipcRenderer } from "electron";
import sendToIpcInjectable from "./send-to-ipc.injectable";
import { runInAction } from "mobx";
describe("ipc-renderer", () => {
let di: DiContainer;
@ -10,8 +11,10 @@ describe("ipc-renderer", () => {
beforeEach(() => {
di = createContainer("irrelevant");
runInAction(() => {
registerFeature(di, messagingFeatureForRenderer);
});
});
it("is IPC-renderer send of Electron", () => {
const actual = di.inject(sendToIpcInjectable);

View File

@ -13,7 +13,6 @@ import {
sendMessageToChannelInjectionToken,
} from "@k8slens/messaging";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { runInAction } from "mobx";
import { getPromiseStatus } from "@k8slens/test-utils";
import { getMessageBridgeFake } from "./get-message-bridge-fake";
@ -50,10 +49,6 @@ const someRequestChannelWithoutListeners: SomeRequestChannel = {
someDiWithoutListeners = createContainer("some-di-3");
registerMobX(someDi1);
registerMobX(someDi2);
registerMobX(someDiWithoutListeners);
runInAction(() => {
const feature = testUtils.messagingFeatureForUnitTesting;

View File

@ -32,6 +32,7 @@
},
"peerDependencies": {
"@k8slens/application": "^6.5.0-alpha.2",
"@k8slens/basic-dependency-features": "^1.0.0-alpha.0",
"@k8slens/feature-core": "^6.5.0-alpha.0",
"@ogre-tools/fp": "^15.3.1",
"@ogre-tools/injectable": "^15.3.1",

View File

@ -1,6 +1,7 @@
import { getFeature } from "@k8slens/feature-core";
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
import { applicationFeature } from "@k8slens/application";
import { injectableMobXFeature, injectableReactFeature } from "@k8slens/basic-dependency-features";
export const reactApplicationFeature = getFeature({
id: "react-application",
@ -13,5 +14,5 @@ export const reactApplicationFeature = getFeature({
});
},
dependencies: [applicationFeature],
dependencies: [injectableReactFeature, injectableMobXFeature, applicationFeature],
});

View File

@ -1,7 +1,5 @@
import { registerFeature } from "@k8slens/feature-core";
import { createContainer, DiContainer, getInjectable } from "@ogre-tools/injectable";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { registerInjectableReact } from "@ogre-tools/injectable-react";
import { reactApplicationFeature } from "./feature";
import { runInAction, computed, observable, IObservableValue } from "mobx";
import { startApplicationInjectionToken } from "@k8slens/application";
@ -26,10 +24,6 @@ describe("react-application", () => {
beforeEach(async () => {
di = createContainer("some-container");
registerInjectableReact(di);
registerMobX(di);
runInAction(() => {
registerFeature(di, reactApplicationFeature);
});