mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix installing-helm-chart-from-new-tab tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
6a92ee2c7c
commit
8dd47b84db
@ -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", () => {
|
||||
|
||||
@ -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<void>;
|
||||
|
||||
type LensWindowWithHelpers = LensWindow & { rendered: RenderResult; di: DiContainer };
|
||||
|
||||
const createNamespacesFor = (namespaces: Set<string>): 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<string>();
|
||||
const namespaceItems = observable.array<Namespace>();
|
||||
const selectedNamespaces = observable.set<string>();
|
||||
|
||||
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<NamespaceStore> as NamespaceStore;
|
||||
|
||||
const clusterFrameContextFake = new ClusterFrameContext(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user