From 8dd47b84db5bbf4f950b4bc217075569214b8225 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 19 Aug 2022 14:33:03 -0400 Subject: [PATCH] Fix installing-helm-chart-from-new-tab tests Signed-off-by: Sebastian Malton --- ...installing-helm-chart-from-new-tab.test.ts | 21 ++------------ .../test-utils/get-application-builder.tsx | 29 +++++++++++++++---- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/features/helm-charts/installing-chart/installing-helm-chart-from-new-tab.test.ts b/src/features/helm-charts/installing-chart/installing-helm-chart-from-new-tab.test.ts index f2b3cf1489..dbf9d3c36e 100644 --- a/src/features/helm-charts/installing-chart/installing-helm-chart-from-new-tab.test.ts +++ b/src/features/helm-charts/installing-chart/installing-helm-chart-from-new-tab.test.ts @@ -13,11 +13,8 @@ import getRandomInstallChartTabIdInjectable from "../../../renderer/components/d import type { RequestCreateHelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api/request-create.injectable"; import requestCreateHelmReleaseInjectable from "../../../common/k8s-api/endpoints/helm-releases.api/request-create.injectable"; import currentPathInjectable from "../../../renderer/routes/current-path.injectable"; -import namespaceStoreInjectable from "../../../renderer/components/+namespaces/store.injectable"; -import type { NamespaceStore } from "../../../renderer/components/+namespaces/store"; import writeJsonFileInjectable from "../../../common/fs/write-json-file.injectable"; import directoryForLensLocalStorageInjectable from "../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable"; -import hostedClusterIdInjectable from "../../../renderer/cluster-frame-context/hosted-cluster-id.injectable"; import dockStoreInjectable from "../../../renderer/components/dock/dock/store.injectable"; import readJsonFileInjectable from "../../../common/fs/read-json-file.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; @@ -51,27 +48,12 @@ describe("installing helm chart from new tab", () => { builder.beforeWindowStart((windowDi) => { windowDi.override(directoryForLensLocalStorageInjectable, () => "/some-directory-for-lens-local-storage"); - windowDi.override(hostedClusterIdInjectable, () => "some-cluster-id"); windowDi.override(requestHelmChartsInjectable, () => requestHelmChartsMock); windowDi.override(requestHelmChartVersionsInjectable, () => requestHelmChartVersionsMock); windowDi.override(requestHelmChartReadmeInjectable, () => requestHelmChartReadmeMock); windowDi.override(requestHelmChartValuesInjectable, () => requestHelmChartValuesMock); windowDi.override(requestCreateHelmReleaseInjectable, () => requestCreateHelmReleaseMock); - // TODO: Replace store mocking with mock for the actual side-effect (where the namespaces are coming from) - windowDi.override( - namespaceStoreInjectable, - () => - ({ - contextNamespaces: [], - items: [ - { getName: () => "default" }, - { getName: () => "some-other-namespace" }, - ], - selectNamespaces: () => {}, - } as unknown as NamespaceStore), - ); - windowDi.override(getRandomInstallChartTabIdInjectable, () => jest .fn(() => "some-irrelevant-tab-id") @@ -79,6 +61,9 @@ describe("installing helm chart from new tab", () => { .mockReturnValueOnce("some-second-tab-id"), ); }); + + builder.namespaces.add("default"); + builder.namespaces.add("some-other-namespace"); }); describe("given tab for installing chart was not previously opened and application is started", () => { diff --git a/src/renderer/components/test-utils/get-application-builder.tsx b/src/renderer/components/test-utils/get-application-builder.tsx index 0e249bd79b..c9614198b9 100644 --- a/src/renderer/components/test-utils/get-application-builder.tsx +++ b/src/renderer/components/test-utils/get-application-builder.tsx @@ -67,11 +67,25 @@ import type { LensWindow } from "../../../main/start-main-application/lens-windo import type { FakeExtensionOptions } from "./get-extension-fake"; import { getExtensionFakeForMain, getExtensionFakeForRenderer } from "./get-extension-fake"; import namespaceApiInjectable from "../../../common/k8s-api/endpoints/namespace.api.injectable"; +import { Namespace } from "../../../common/k8s-api/endpoints"; type Callback = (di: DiContainer) => void | Promise; type LensWindowWithHelpers = LensWindow & { rendered: RenderResult; di: DiContainer }; +const createNamespacesFor = (namespaces: Set): Namespace[] => ( + Array.from(namespaces, (namespace) => new Namespace({ + apiVersion: "v1", + kind: "Namespace", + metadata: { + name: namespace, + resourceVersion: "1", + selfLink: `/api/v1/namespaces/${namespace}`, + uid: `namespace-${namespace}`, + }, + })) +); + export interface ApplicationBuilder { mainDi: DiContainer; setEnvironmentToClusterFrame: () => ApplicationBuilder; @@ -249,6 +263,7 @@ export const getApplicationBuilder = () => { let applicationHasStarted = false; const namespaces = observable.set(); + const namespaceItems = observable.array(); const selectedNamespaces = observable.set(); const builder: ApplicationBuilder = { @@ -312,7 +327,10 @@ export const getApplicationBuilder = () => { }, }, namespaces: { - add: action((namespace) => namespaces.add(namespace)), + add: action((namespace) => { + namespaces.add(namespace); + namespaceItems.replace(createNamespacesFor(namespaces)); + }), select: action((namespace) => selectedNamespaces.add(namespace)), }, applicationMenu: { @@ -469,6 +487,7 @@ export const getApplicationBuilder = () => { ); const clusterStub = { + id: "some-cluster-id", accessibleNamespaces: [], isAllowedResource: isAllowedResource(allowedResourcesState), } as unknown as Cluster; @@ -477,7 +496,7 @@ export const getApplicationBuilder = () => { computed(() => catalogEntityFromCluster(clusterStub)), ); - windowDi.override(hostedClusterIdInjectable, () => "irrelevant-hosted-cluster-id"); + windowDi.override(hostedClusterIdInjectable, () => clusterStub.id); // TODO: Figure out a way to remove this stub. const namespaceStoreStub = { @@ -488,14 +507,14 @@ export const getApplicationBuilder = () => { get allowedNamespaces() { return Array.from(namespaces); }, - contextItems: [], + contextItems: namespaceItems, api: windowDi.inject(namespaceApiInjectable), - items: observable.array(), + items: namespaceItems, selectNamespaces: () => {}, getByPath: () => undefined, pickOnlySelected: () => [], isSelectedAll: () => false, - getTotalCount: () => 0, + getTotalCount: () => namespaceItems.length, } as Partial as NamespaceStore; const clusterFrameContextFake = new ClusterFrameContext(