mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Kludge around test setup which is difficult because of circular dependencies
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
79e56cb187
commit
c6c128e890
@ -6,16 +6,15 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { asyncComputed } from "@ogre-tools/injectable-react";
|
||||
import namespaceStoreInjectable from "../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import { listReleases } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||
import clusterFrameContextInjectable from "../../cluster-frame-context/cluster-frame-context.injectable";
|
||||
|
||||
const releasesInjectable = getInjectable({
|
||||
id: "releases",
|
||||
|
||||
instantiate: (di) => {
|
||||
const clusterContext = di.inject(clusterFrameContextInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
|
||||
// TODO: Inject clusterContext directly instead of accessing dependency of a dependency
|
||||
const clusterContext = namespaceStore.context;
|
||||
|
||||
return asyncComputed(async () => {
|
||||
const contextNamespaces = namespaceStore.contextNamespaces || [];
|
||||
|
||||
|
||||
@ -18,7 +18,6 @@ import allowedResourcesInjectable from "../../../common/cluster-store/allowed-re
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
import { fireEvent } from "@testing-library/react";
|
||||
import type { KubeResource } from "../../../common/rbac";
|
||||
import directoryForLensLocalStorageInjectable from "../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable";
|
||||
import { Sidebar } from "../layout/sidebar";
|
||||
import { getDisForUnitTesting } from "../../../test-utils/get-dis-for-unit-testing";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
@ -34,9 +33,13 @@ import navigateToPreferencesInjectable from "../../../common/front-end-routing/r
|
||||
import type { MenuItemOpts } from "../../../main/menu/application-menu-items.injectable";
|
||||
import applicationMenuItemsInjectable from "../../../main/menu/application-menu-items.injectable";
|
||||
import navigateToHelmChartsInjectable from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable";
|
||||
import clusterFrameContextInjectable from "../../cluster-frame-context/cluster-frame-context.injectable";
|
||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import hostedClusterInjectable from "../../../common/cluster-store/hosted-cluster.injectable";
|
||||
import { ClusterFrameContext } from "../../cluster-frame-context/cluster-frame-context";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import type { NamespaceStore } from "../+namespaces/namespace-store/namespace.store";
|
||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import namespaceStoreInjectable from "../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import clusterFrameContextInjectable from "../../cluster-frame-context/cluster-frame-context.injectable";
|
||||
|
||||
type Callback = (dis: DiContainers) => void | Promise<void>;
|
||||
|
||||
@ -219,21 +222,26 @@ export const getApplicationBuilder = () => {
|
||||
computed(() => new Set([...allowedResourcesState])),
|
||||
);
|
||||
|
||||
rendererDi.override(
|
||||
directoryForLensLocalStorageInjectable,
|
||||
() => "/irrelevant",
|
||||
);
|
||||
|
||||
rendererDi.override(hostedClusterInjectable, () => ({
|
||||
const clusterStub = {
|
||||
accessibleNamespaces: [],
|
||||
}));
|
||||
} as Cluster;
|
||||
|
||||
const clusterFrameContext = rendererDi.inject(
|
||||
clusterFrameContextInjectable,
|
||||
const namespaceStoreStub = {} as NamespaceStore;
|
||||
|
||||
const clusterFrameContextFake = new ClusterFrameContext(
|
||||
clusterStub,
|
||||
|
||||
{
|
||||
namespaceStore: namespaceStoreStub,
|
||||
},
|
||||
);
|
||||
|
||||
rendererDi.override(namespaceStoreInjectable, () => namespaceStoreStub);
|
||||
rendererDi.override(hostedClusterInjectable, () => clusterStub);
|
||||
rendererDi.override(clusterFrameContextInjectable, () => clusterFrameContextFake);
|
||||
|
||||
// Todo: get rid of global state.
|
||||
KubeObjectStore.defaultContext.set(clusterFrameContext);
|
||||
KubeObjectStore.defaultContext.set(clusterFrameContextFake);
|
||||
|
||||
return builder;
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user