mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove usage of legacy global causing trouble in unit tests
Co-authored-by: Alex Andreev <alex.andreev.email@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
a0bd4c003a
commit
5a8ffdf191
@ -8,7 +8,6 @@ import React, { useEffect, useRef } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { Icon } from "../../icon";
|
||||
import { watchHistoryState } from "../../../remote-helpers/history-updater";
|
||||
import { cssNames } from "../../../utils";
|
||||
import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
@ -28,6 +27,7 @@ import goForwardInjectable from "./go-forward.injectable";
|
||||
import closeWindowInjectable from "./close-window.injectable";
|
||||
import maximizeWindowInjectable from "./maximize-window.injectable";
|
||||
import toggleMaximizeWindowInjectable from "./toggle-maximize-window.injectable";
|
||||
import watchHistoryStateInjectable from "../../../remote-helpers/watch-history-state.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
navigateToCatalog: NavigateToCatalog;
|
||||
@ -43,6 +43,7 @@ interface Dependencies {
|
||||
minimizeWindow: () => void;
|
||||
toggleMaximizeWindow: () => void;
|
||||
closeWindow: () => void;
|
||||
watchHistoryState: () => () => void;
|
||||
}
|
||||
|
||||
const NonInjectedTopBar = observer(({
|
||||
@ -59,6 +60,7 @@ const NonInjectedTopBar = observer(({
|
||||
closeWindow,
|
||||
minimizeWindow,
|
||||
toggleMaximizeWindow,
|
||||
watchHistoryState,
|
||||
}: Dependencies) => {
|
||||
const elem = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
@ -196,5 +198,6 @@ export const TopBar = withInjectables<Dependencies>(NonInjectedTopBar, {
|
||||
closeWindow: di.inject(closeWindowInjectable),
|
||||
minimizeWindow: di.inject(maximizeWindowInjectable),
|
||||
toggleMaximizeWindow: di.inject(toggleMaximizeWindowInjectable),
|
||||
watchHistoryState: di.inject(watchHistoryStateInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -20,7 +20,6 @@ import { KubeObjectDetails } from "../../components/kube-object-details";
|
||||
import { KubeConfigDialog } from "../../components/kubeconfig-dialog";
|
||||
import { Sidebar } from "../../components/layout/sidebar";
|
||||
import { Dock } from "../../components/dock";
|
||||
import { watchHistoryState } from "../../remote-helpers/history-updater";
|
||||
import { PortForwardDialog } from "../../port-forward";
|
||||
import { DeleteClusterDialog } from "../../components/delete-cluster-dialog";
|
||||
import type { NamespaceStore } from "../../components/+namespaces/store";
|
||||
@ -32,6 +31,7 @@ import currentRouteComponentInjectable from "../../routes/current-route-componen
|
||||
import startUrlInjectable from "./start-url.injectable";
|
||||
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";
|
||||
import currentPathInjectable from "../../routes/current-path.injectable";
|
||||
import watchHistoryStateInjectable from "../../remote-helpers/watch-history-state.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
namespaceStore: NamespaceStore;
|
||||
@ -39,6 +39,7 @@ interface Dependencies {
|
||||
startUrl: IComputedValue<string>;
|
||||
subscribeStores: SubscribeStores;
|
||||
currentPath: IComputedValue<string>;
|
||||
watchHistoryState: () => () => void;
|
||||
}
|
||||
|
||||
export const NonInjectedClusterFrame = observer(({
|
||||
@ -47,6 +48,7 @@ export const NonInjectedClusterFrame = observer(({
|
||||
startUrl,
|
||||
subscribeStores,
|
||||
currentPath,
|
||||
watchHistoryState,
|
||||
}: Dependencies) => {
|
||||
useEffect(() => disposer(
|
||||
subscribeStores([
|
||||
@ -103,6 +105,7 @@ export const ClusterFrame = withInjectables<Dependencies>(NonInjectedClusterFram
|
||||
startUrl: di.inject(startUrlInjectable),
|
||||
currentRouteComponent: di.inject(currentRouteComponentInjectable),
|
||||
currentPath: di.inject(currentPathInjectable),
|
||||
watchHistoryState: di.inject(watchHistoryStateInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@ -52,6 +52,7 @@ import callForPublicHelmRepositoriesInjectable from "./components/+preferences/k
|
||||
import platformInjectable from "../common/vars/platform.injectable";
|
||||
import startTopbarStateSyncInjectable from "./components/layout/top-bar/start-state-sync.injectable";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable";
|
||||
|
||||
export const getDiForUnitTesting = (opts: { doGeneralOverrides?: boolean } = {}) => {
|
||||
const {
|
||||
@ -96,6 +97,8 @@ export const getDiForUnitTesting = (opts: { doGeneralOverrides?: boolean } = {})
|
||||
|
||||
di.override(lensResourcesDirInjectable, () => "/irrelevant");
|
||||
|
||||
di.override(watchHistoryStateInjectable, () => () => () => {});
|
||||
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
invoke: () => {},
|
||||
on: () => {},
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { reaction } from "mobx";
|
||||
import { emitWindowLocationChanged } from "../ipc";
|
||||
import { navigation } from "../navigation";
|
||||
|
||||
export function watchHistoryState() {
|
||||
return reaction(() => navigation.location, emitWindowLocationChanged);
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
|
||||
import { emitWindowLocationChanged } from "../ipc";
|
||||
import { reaction } from "mobx";
|
||||
import observableHistoryInjectable from "../navigation/observable-history.injectable";
|
||||
|
||||
const watchHistoryStateInjectable = getInjectable({
|
||||
id: "watch-history-state",
|
||||
|
||||
instantiate: (di) => {
|
||||
const observableHistory = di.inject(observableHistoryInjectable);
|
||||
|
||||
return () => reaction(
|
||||
() => observableHistory.location,
|
||||
emitWindowLocationChanged,
|
||||
);
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default watchHistoryStateInjectable;
|
||||
Loading…
Reference in New Issue
Block a user