mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Remove all usages of legacy global logger Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global storageClassApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global serviceApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global secretApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global resourceQuotaApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global persistentVolumeClaimApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global nodeApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global networkPolicyApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix formatting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global configMapApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global jobApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global cronJobApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove exports of NonInjected components - To improve auto-complete Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global catalogEntityRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add lint against using legacy global works Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in KubeObject file Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global catalogCategoryRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global navigation Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global navigate Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unneeded index file Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global customResourceDefinitionStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global eventStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podSecurityPolicyStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global storageClassStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global persistentVolumeStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global clusterRoleBindingStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global clusterRoleStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleBindingStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move files around Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global serviceAccountStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove final uses of asLegacyGlobalForExtensionApi in application code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint rule and start fixing lint errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make listHelmReleases injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make installHelmChart injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make deleteHelmRelease injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make getHelmReleaseValues injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make getHelmReleaseHistory injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make rollbackHelmRelease injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary overrides from getDiForUnitTesting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for logger Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for history Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cleanup typing around getting injectables within jest Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move some more overrides to global if needed Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for forcusWindow Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in KubeApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in catalog/index.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last usages of legacy global getDetailsUrl Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last usages of legacy global showDetails Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add functions back to extension API Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove all uses of legacy global Notification functions Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer existing export Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary overrides Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix injecting side effects by using more injectables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster role binding dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster role dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix create service account dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix history override Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make KubeApi consume its dependencies while not breaking the extension API Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix CephFs tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix user store tests by using override of config Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in hotbar store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add direct devDep of memfs Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in cluster store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in router tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in kube auth proxy tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in log resource selector tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in hotbar remove command tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in the select component tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove mock-fs as a dependency Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer necessary mocks Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix namespace select filter tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in the extension loader tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixing edit-namespace-from-new-tab test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix app paths tests by making the tests run in "production" mode Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last vestiges of isTestEnv and the is* globals Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix delete-cluster-dialog tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix install-helm-chart-from-previously-opened-tab tests - Split out storage initialization to a runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary override of non side effect injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix disable-kube-object-detail-items-when-cluster-is-not-relevant tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix reactively-hide-kube-object-detail-item tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix sidebar-and-tab-navigation-for-core tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove need to override lensLocalStoragePath in tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace more overrides with global ones Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix typings Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer needed technical test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
268 lines
9.0 KiB
TypeScript
268 lines
9.0 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import "@testing-library/jest-dom/extend-expect";
|
|
import { KubeConfig } from "@kubernetes/client-node";
|
|
import type { RenderResult } from "@testing-library/react";
|
|
import type { CreateCluster } from "../../../common/cluster/create-cluster-injection-token";
|
|
import { createClusterInjectionToken } from "../../../common/cluster/create-cluster-injection-token";
|
|
import createContextHandlerInjectable from "../../../main/context-handler/create-context-handler.injectable";
|
|
import createKubeconfigManagerInjectable from "../../../main/kubeconfig-manager/create-kubeconfig-manager.injectable";
|
|
import normalizedPlatformInjectable from "../../../common/vars/normalized-platform.injectable";
|
|
import kubectlBinaryNameInjectable from "../../../main/kubectl/binary-name.injectable";
|
|
import kubectlDownloadingNormalizedArchInjectable from "../../../main/kubectl/normalized-arch.injectable";
|
|
import openDeleteClusterDialogInjectable, { type OpenDeleteClusterDialog } from "../../../renderer/components/delete-cluster-dialog/open.injectable";
|
|
import { type ApplicationBuilder, getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
|
|
import type { Cluster } from "../../../common/cluster/cluster";
|
|
import navigateToCatalogInjectable from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable";
|
|
import directoryForKubeConfigsInjectable from "../../../common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
|
import joinPathsInjectable from "../../../common/path/join-paths.injectable";
|
|
import { advanceFakeTime } from "../../../common/test-utils/use-fake-time";
|
|
|
|
const currentClusterServerUrl = "https://localhost";
|
|
const nonCurrentClusterServerUrl = "http://localhost";
|
|
const multiClusterConfig = `
|
|
apiVersion: v1
|
|
clusters:
|
|
- cluster:
|
|
server: ${currentClusterServerUrl}
|
|
name: some-current-context-cluster
|
|
- cluster:
|
|
server: ${nonCurrentClusterServerUrl}
|
|
name: some-non-current-context-cluster
|
|
contexts:
|
|
- context:
|
|
cluster: some-current-context-cluster
|
|
user: some-user
|
|
name: some-current-context
|
|
- context:
|
|
cluster: some-non-current-context-cluster
|
|
user: some-user
|
|
name: some-non-current-context
|
|
current-context: some-current-context
|
|
kind: Config
|
|
preferences: {}
|
|
users:
|
|
- name: some-user
|
|
user:
|
|
token: kubeconfig-user-q4lm4:xxxyyyy
|
|
`;
|
|
|
|
const singleClusterServerUrl = "http://localhost";
|
|
const singleClusterConfig = `
|
|
apiVersion: v1
|
|
clusters:
|
|
- cluster:
|
|
server: ${singleClusterServerUrl}
|
|
name: some-cluster
|
|
contexts:
|
|
- context:
|
|
cluster: some-cluster
|
|
user: some-user
|
|
name: some-context
|
|
current-context: some-context
|
|
kind: Config
|
|
preferences: {}
|
|
users:
|
|
- name: some-user
|
|
user:
|
|
token: kubeconfig-user-q4lm4:xxxyyyy
|
|
`;
|
|
|
|
describe("Deleting a cluster", () => {
|
|
let builder: ApplicationBuilder;
|
|
let openDeleteClusterDialog: OpenDeleteClusterDialog;
|
|
let createCluster: CreateCluster;
|
|
let rendered: RenderResult;
|
|
let config: KubeConfig;
|
|
|
|
beforeEach(async () => {
|
|
config = new KubeConfig();
|
|
builder = getApplicationBuilder();
|
|
|
|
builder.beforeApplicationStart((mainDi) => {
|
|
mainDi.override(createContextHandlerInjectable, () => () => undefined as never);
|
|
mainDi.override(createKubeconfigManagerInjectable, () => () => undefined as never);
|
|
mainDi.override(kubectlBinaryNameInjectable, () => "kubectl");
|
|
mainDi.override(kubectlDownloadingNormalizedArchInjectable, () => "amd64");
|
|
mainDi.override(normalizedPlatformInjectable, () => "darwin");
|
|
});
|
|
|
|
builder.beforeWindowStart((windowDi) => {
|
|
openDeleteClusterDialog = windowDi.inject(openDeleteClusterDialogInjectable);
|
|
});
|
|
|
|
builder.afterWindowStart(windowDi => {
|
|
createCluster = windowDi.inject(createClusterInjectionToken);
|
|
|
|
const navigateToCatalog = windowDi.inject(navigateToCatalogInjectable);
|
|
|
|
navigateToCatalog();
|
|
});
|
|
|
|
rendered = await builder.render();
|
|
});
|
|
|
|
describe("when the kubeconfig has multiple clusters", () => {
|
|
let currentCluster: Cluster;
|
|
let nonCurrentCluster: Cluster;
|
|
|
|
beforeEach(() => {
|
|
config.loadFromString(multiClusterConfig);
|
|
|
|
currentCluster = createCluster({
|
|
id: "some-current-context-cluster",
|
|
contextName: "some-current-context",
|
|
preferences: {
|
|
clusterName: "some-current-context-cluster",
|
|
},
|
|
kubeConfigPath: "./temp-kube-config",
|
|
}, {
|
|
clusterServerUrl: currentClusterServerUrl,
|
|
});
|
|
nonCurrentCluster = createCluster({
|
|
id: "some-non-current-context-cluster",
|
|
contextName: "some-non-current-context",
|
|
preferences: {
|
|
clusterName: "some-non-current-context-cluster",
|
|
},
|
|
kubeConfigPath: "./temp-kube-config",
|
|
}, {
|
|
clusterServerUrl: currentClusterServerUrl,
|
|
});
|
|
});
|
|
|
|
describe("when the dialog is opened for the current cluster", () => {
|
|
// TODO: replace with actual behaviour instead of technical use
|
|
beforeEach(async () => {
|
|
openDeleteClusterDialog(config, currentCluster);
|
|
advanceFakeTime(1000);
|
|
await rendered.findByTestId("delete-cluster-dialog");
|
|
});
|
|
|
|
it("renders", () => {
|
|
expect(rendered.baseElement).toMatchSnapshot();
|
|
});
|
|
|
|
it("shows context switcher", () => {
|
|
expect(rendered.queryByText("Select new context...")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows warning", () => {
|
|
expect(rendered.queryByTestId("current-context-warning")).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe("when the dialog is opened for not the current cluster", () => {
|
|
// TODO: replace with actual behaviour instead of technical use
|
|
beforeEach(async () => {
|
|
openDeleteClusterDialog(config, nonCurrentCluster);
|
|
advanceFakeTime(1000);
|
|
await rendered.findByTestId("delete-cluster-dialog");
|
|
});
|
|
|
|
it("renders", () => {
|
|
expect(rendered.baseElement).toMatchSnapshot();
|
|
});
|
|
|
|
it("shows warning", () => {
|
|
expect(rendered.queryByTestId("kubeconfig-change-warning")).toBeInTheDocument();
|
|
});
|
|
|
|
it("does not show context switcher", () => {
|
|
expect(rendered.queryByText("Select new context...")).not.toBeInTheDocument();
|
|
});
|
|
|
|
describe("when context switching checkbox is clicked", () => {
|
|
beforeEach(() => {
|
|
rendered.getByTestId("delete-cluster-dialog-context-switch").click();
|
|
});
|
|
|
|
it("renders", () => {
|
|
expect(rendered.baseElement).toMatchSnapshot();
|
|
});
|
|
|
|
it("shows context switcher", () => {
|
|
expect(rendered.queryByText("Select new context...")).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("when an internal kubeconfig cluster is used", () => {
|
|
let currentCluster: Cluster;
|
|
|
|
beforeEach(() => {
|
|
config.loadFromString(singleClusterConfig);
|
|
|
|
const directoryForKubeConfigs = builder.applicationWindow.only.di.inject(directoryForKubeConfigsInjectable);
|
|
const joinPaths = builder.applicationWindow.only.di.inject(joinPathsInjectable);
|
|
|
|
currentCluster = createCluster({
|
|
id: "some-cluster",
|
|
contextName: "some-context",
|
|
preferences: {
|
|
clusterName: "some-cluster",
|
|
},
|
|
kubeConfigPath: joinPaths(directoryForKubeConfigs, "some-cluster.json"),
|
|
}, {
|
|
clusterServerUrl: singleClusterServerUrl,
|
|
});
|
|
});
|
|
|
|
describe("when the dialog is opened", () => {
|
|
// TODO: replace with actual behaviour instead of technical use
|
|
beforeEach(async () => {
|
|
openDeleteClusterDialog(config, currentCluster);
|
|
advanceFakeTime(1000);
|
|
await rendered.findByTestId("delete-cluster-dialog");
|
|
});
|
|
|
|
it("renders", () => {
|
|
expect(rendered.baseElement).toMatchSnapshot();
|
|
});
|
|
|
|
it("shows warning", () => {
|
|
expect(rendered.queryByTestId("internal-kubeconfig-warning")).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("when the kubeconfig has only one cluster", () => {
|
|
let currentCluster: Cluster;
|
|
|
|
beforeEach(() => {
|
|
config.loadFromString(singleClusterConfig);
|
|
|
|
currentCluster = createCluster({
|
|
id: "some-cluster",
|
|
contextName: "some-context",
|
|
preferences: {
|
|
clusterName: "some-cluster",
|
|
},
|
|
kubeConfigPath: "./temp-kube-config",
|
|
}, {
|
|
clusterServerUrl: singleClusterServerUrl,
|
|
});
|
|
});
|
|
|
|
describe("when the dialog is opened", () => {
|
|
// TODO: replace with actual behaviour instead of technical use
|
|
beforeEach(async () => {
|
|
openDeleteClusterDialog(config, currentCluster);
|
|
advanceFakeTime(1000);
|
|
await rendered.findByTestId("delete-cluster-dialog");
|
|
});
|
|
|
|
it("renders", () => {
|
|
expect(rendered.baseElement).toMatchSnapshot();
|
|
});
|
|
|
|
it("shows warning", () => {
|
|
expect(rendered.queryByTestId("no-more-contexts-warning")).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
});
|