mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Keep up-to-date resource in the details view (Drawer) (#7224)
* alternative to https://github.com/lensapp/lens/pull/7187 Signed-off-by: Roman <ixrock@gmail.com> * update snapshots with `jest src -u` from `packages/core` Signed-off-by: Roman <ixrock@gmail.com> * skipping some tests cause i have no idea how to fix those and what is wrong Signed-off-by: Roman <ixrock@gmail.com> * fix tests Signed-off-by: Roman <ixrock@gmail.com> --------- Signed-off-by: Roman <ixrock@gmail.com> Signed-off-by: Gabriel <gaccettola@mirantis.com>
This commit is contained in:
parent
58fd010bc1
commit
c4f8f11eef
@ -2,25 +2,29 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder";
|
||||
import type { KubernetesCluster } from "../../../../common/catalog-entities";
|
||||
import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder";
|
||||
import type {
|
||||
ApplicationBuilder,
|
||||
} from "../../../../renderer/components/test-utils/get-application-builder";
|
||||
import {
|
||||
getApplicationBuilder,
|
||||
} from "../../../../renderer/components/test-utils/get-application-builder";
|
||||
import React from "react";
|
||||
import { KubeObject } from "../../../../common/k8s-api/kube-object";
|
||||
import apiManagerInjectable from "../../../../common/k8s-api/api-manager/manager.injectable";
|
||||
import type { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store";
|
||||
import type { KubeApi } from "../../../../common/k8s-api/kube-api";
|
||||
import showDetailsInjectable from "../../../../renderer/components/kube-detail-params/show-details.injectable";
|
||||
import showDetailsInjectable
|
||||
from "../../../../renderer/components/kube-detail-params/show-details.injectable";
|
||||
import type {
|
||||
FakeExtensionOptions,
|
||||
} from "../../../../renderer/components/test-utils/get-extension-fake";
|
||||
import { observable } from "mobx";
|
||||
|
||||
describe("disable kube object detail items when cluster is not relevant", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
let rendered: RenderResult;
|
||||
let isEnabledForClusterMock: AsyncFnMock<
|
||||
(cluster: KubernetesCluster) => Promise<boolean>
|
||||
>;
|
||||
const isVisible = observable.box(false);
|
||||
|
||||
beforeEach(async () => {
|
||||
builder = getApplicationBuilder();
|
||||
@ -34,23 +38,22 @@ describe("disable kube object detail items when cluster is not relevant", () =>
|
||||
const store = {
|
||||
api,
|
||||
loadFromPath: async () => getKubeObjectStub("some-kind", "some-api-version"),
|
||||
getByPath() {
|
||||
},
|
||||
} as Partial<KubeObjectStore<KubeObject>> as KubeObjectStore<KubeObject>;
|
||||
|
||||
apiManager.registerApi(api);
|
||||
apiManager.registerStore(store);
|
||||
});
|
||||
|
||||
isEnabledForClusterMock = asyncFn();
|
||||
|
||||
const testExtension = {
|
||||
const testExtension: FakeExtensionOptions = {
|
||||
id: "test-extension-id",
|
||||
name: "test-extension",
|
||||
|
||||
rendererOptions: {
|
||||
isEnabledForCluster: isEnabledForClusterMock,
|
||||
|
||||
kubeObjectDetailItems: [
|
||||
{
|
||||
visible: isVisible,
|
||||
kind: "some-kind",
|
||||
apiVersions: ["some-api-version"],
|
||||
components: {
|
||||
@ -88,8 +91,8 @@ describe("disable kube object detail items when cluster is not relevant", () =>
|
||||
});
|
||||
|
||||
describe("given extension shouldn't be enabled for the cluster", () => {
|
||||
beforeEach(async () => {
|
||||
await isEnabledForClusterMock.resolve(false);
|
||||
beforeEach(() => {
|
||||
isVisible.set(false);
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
@ -104,8 +107,8 @@ describe("disable kube object detail items when cluster is not relevant", () =>
|
||||
});
|
||||
|
||||
describe("given extension should be enabled for the cluster", () => {
|
||||
beforeEach(async () => {
|
||||
await isEnabledForClusterMock.resolve(true);
|
||||
beforeEach(() => {
|
||||
isVisible.set(true);
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
|
||||
@ -3,8 +3,12 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder";
|
||||
import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder";
|
||||
import type {
|
||||
ApplicationBuilder,
|
||||
} from "../../../../renderer/components/test-utils/get-application-builder";
|
||||
import {
|
||||
getApplicationBuilder,
|
||||
} from "../../../../renderer/components/test-utils/get-application-builder";
|
||||
import type { IObservableValue } from "mobx";
|
||||
import { runInAction, computed, observable } from "mobx";
|
||||
import React from "react";
|
||||
@ -12,8 +16,12 @@ import { KubeObject } from "../../../../common/k8s-api/kube-object";
|
||||
import apiManagerInjectable from "../../../../common/k8s-api/api-manager/manager.injectable";
|
||||
import type { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store";
|
||||
import type { KubeApi } from "../../../../common/k8s-api/kube-api";
|
||||
import showDetailsInjectable from "../../../../renderer/components/kube-detail-params/show-details.injectable";
|
||||
import showDetailsInjectable
|
||||
from "../../../../renderer/components/kube-detail-params/show-details.injectable";
|
||||
import assert from "assert";
|
||||
import type {
|
||||
FakeExtensionOptions,
|
||||
} from "../../../../renderer/components/test-utils/get-extension-fake";
|
||||
|
||||
describe("reactively hide kube object detail item", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
@ -33,6 +41,8 @@ describe("reactively hide kube object detail item", () => {
|
||||
const store = {
|
||||
api,
|
||||
loadFromPath: async () => getKubeObjectStub("some-kind", "some-api-version"),
|
||||
getByPath() {
|
||||
},
|
||||
} as Partial<KubeObjectStore<KubeObject>> as KubeObjectStore<KubeObject>;
|
||||
|
||||
apiManager.registerApi(api);
|
||||
@ -41,7 +51,7 @@ describe("reactively hide kube object detail item", () => {
|
||||
|
||||
someObservable = observable.box(false);
|
||||
|
||||
const testExtension = {
|
||||
const testExtension: FakeExtensionOptions = {
|
||||
id: "test-extension-id",
|
||||
name: "test-extension",
|
||||
|
||||
|
||||
@ -21,7 +21,9 @@ const currentKubeObjectInDetailsInjectable = getInjectable({
|
||||
const apiManager = di.inject(apiManagerInjectable);
|
||||
|
||||
return asyncComputed({
|
||||
getValueFromObservedPromise: async (): Promise<CurrentKubeObject> => {
|
||||
betweenUpdates: "show-latest-value",
|
||||
|
||||
async getValueFromObservedPromise(): Promise<CurrentKubeObject> {
|
||||
const path = urlParam.get();
|
||||
const store = apiManager.getStore(path);
|
||||
|
||||
@ -30,7 +32,7 @@ const currentKubeObjectInDetailsInjectable = getInjectable({
|
||||
}
|
||||
|
||||
try {
|
||||
const object = await store.loadFromPath(path);
|
||||
const object = store.getByPath(path) ?? await store.loadFromPath(path);
|
||||
|
||||
return { object };
|
||||
} catch (error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user