-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce kludge to make "isEnabledForCluster" work again for cluster…
… page menus PART 2 (#5801) * Kludge "isEnabledForCluster" work again for cluster page menus (sidebar items) Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce kludge to make "isEnabledForCluster" work again for kube object status texts PART 3 (#5802) * Kludge "isEnabledForCluster" work again for kube object status texts Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Kludge "isEnabledForCluster" work again for kube object menu items (#5803) Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
- Loading branch information
Showing
27 changed files
with
4,873 additions
and
277 deletions.
There are no files selected for viewing
1,563 changes: 1,563 additions & 0 deletions
1,563
...ension-api/__snapshots__/disable-sidebar-items-when-cluster-is-not-relevant.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
...aviours/cluster/extension-api/disable-sidebar-items-when-cluster-is-not-relevant.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* 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 { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder"; | ||
import { getExtensionFakeFor } from "../../../renderer/components/test-utils/get-extension-fake"; | ||
import type { KubernetesCluster } from "../../../common/catalog-entities"; | ||
import React from "react"; | ||
import extensionShouldBeEnabledForClusterFrameInjectable from "../../../renderer/extension-loader/extension-should-be-enabled-for-cluster-frame.injectable"; | ||
|
||
describe("disable sidebar items when cluster is not relevant", () => { | ||
let builder: ApplicationBuilder; | ||
let rendered: RenderResult; | ||
let isEnabledForClusterMock: AsyncFnMock<(cluster: KubernetesCluster) => Promise<boolean>>; | ||
|
||
beforeEach(async () => { | ||
builder = getApplicationBuilder(); | ||
|
||
builder.setEnvironmentToClusterFrame(); | ||
|
||
builder.dis.rendererDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable); | ||
|
||
const getExtensionFake = getExtensionFakeFor(builder); | ||
|
||
isEnabledForClusterMock = asyncFn(); | ||
|
||
const testExtension = getExtensionFake({ | ||
id: "test-extension-id", | ||
name: "test-extension", | ||
|
||
rendererOptions: { | ||
isEnabledForCluster: isEnabledForClusterMock, | ||
|
||
clusterPages: [{ | ||
components: { | ||
Page: () => <div data-testid="some-test-page">Some page</div>, | ||
}, | ||
}], | ||
|
||
clusterPageMenus: [ | ||
{ | ||
id: "some-sidebar-item", | ||
title: "Some sidebar item", | ||
|
||
components: { | ||
Icon: () => <div>Some icon</div>, | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
rendered = await builder.render(); | ||
|
||
builder.extensions.enable(testExtension); | ||
}); | ||
|
||
describe("given not yet known if extension should be enabled for the cluster", () => { | ||
it("renders", () => { | ||
expect(rendered.baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
it("does not show the sidebar item", () => { | ||
const actual = rendered.queryByTestId( | ||
"sidebar-item-some-extension-name-some-sidebar-item", | ||
); | ||
|
||
expect(actual).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("given extension shouldn't be enabled for the cluster", () => { | ||
beforeEach(async () => { | ||
await isEnabledForClusterMock.resolve(false); | ||
}); | ||
|
||
it("renders", () => { | ||
expect(rendered.baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
it("does not show the sidebar item", () => { | ||
const actual = rendered.queryByTestId( | ||
"sidebar-item-some-extension-name-some-sidebar-item", | ||
); | ||
|
||
expect(actual).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("given extension should be enabled for the cluster", () => { | ||
beforeEach(async () => { | ||
await isEnabledForClusterMock.resolve(true); | ||
}); | ||
|
||
it("renders", () => { | ||
expect(rendered.baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
it("shows the sidebar item", () => { | ||
const actual = rendered.getByTestId( | ||
"sidebar-item-test-extension-some-sidebar-item", | ||
); | ||
|
||
expect(actual).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.