mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Provide additional unit tests
Signed-off-by: Alex Culliere <alozhkin@mirantis.com>
This commit is contained in:
parent
80074eeb42
commit
c0344a35bc
@ -21,7 +21,7 @@ const deactivateCluster = (clusterId: string) => {
|
||||
/**
|
||||
* Creates handlers for high-level actions
|
||||
* that could be performed on an individual cluster
|
||||
* @param cluster Cluster>
|
||||
* @param cluster Cluster
|
||||
*/
|
||||
export const ClusterActions = (cluster: Cluster) => ({
|
||||
"SHOW_SETTINGS": () => navigate(clusterSettingsURL({
|
||||
|
||||
@ -7,15 +7,18 @@ import "@testing-library/jest-dom/extend-expect";
|
||||
import { MainLayoutHeader } from "../main-layout-header";
|
||||
import { Cluster } from "../../../../main/cluster";
|
||||
import { workspaceStore } from "../../../../common/workspace-store";
|
||||
import { broadcastMessage } from "../../../../common/ipc";
|
||||
import { broadcastMessage, requestMain } from "../../../../common/ipc";
|
||||
import { clusterDisconnectHandler } from "../../../../common/cluster-ipc";
|
||||
import { ConfirmDialog } from "../../confirm-dialog";
|
||||
|
||||
const mockBroadcastIpc = broadcastMessage as jest.MockedFunction<typeof broadcastMessage>;
|
||||
const mockRequestMain = requestMain as jest.MockedFunction<typeof requestMain>;
|
||||
|
||||
const cluster: Cluster = new Cluster({
|
||||
id: "foo",
|
||||
contextName: "minikube",
|
||||
kubeConfigPath: "minikube-config.yml",
|
||||
workspace: workspaceStore.currentWorkspaceId
|
||||
workspace: workspaceStore.currentWorkspaceId,
|
||||
});
|
||||
|
||||
describe("<MainLayoutHeader />", () => {
|
||||
@ -33,22 +36,67 @@ describe("<MainLayoutHeader />", () => {
|
||||
expect(icon).toHaveTextContent("more_vert");
|
||||
});
|
||||
|
||||
it("navigates to cluster settings", () => {
|
||||
const { container } = render(<MainLayoutHeader cluster={cluster} />);
|
||||
const icon = container.querySelector(".Icon");
|
||||
|
||||
fireEvent.click(icon);
|
||||
|
||||
const settingsBtn = document.querySelectorAll("ul.ClusterActionsMenu > li > span")[0];
|
||||
|
||||
expect(settingsBtn.textContent).toBe("Settings");
|
||||
fireEvent.click(settingsBtn);
|
||||
expect(mockBroadcastIpc).toBeCalledWith("renderer:navigate", "/cluster/foo/settings");
|
||||
});
|
||||
|
||||
it("renders cluster name", () => {
|
||||
const { getByText } = render(<MainLayoutHeader cluster={cluster} />);
|
||||
|
||||
expect(getByText("minikube")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe("Cluster Actions Menu", () => {
|
||||
let settingsBtn: Element;
|
||||
let disconnectBtn: Element;
|
||||
let removeBtn: Element;
|
||||
|
||||
beforeEach(() => {
|
||||
const { container } = render(<div>
|
||||
<MainLayoutHeader cluster={cluster} />
|
||||
<ConfirmDialog />
|
||||
</div>);
|
||||
const icon = container.querySelector(".Icon");
|
||||
|
||||
cluster.online = true;
|
||||
fireEvent.click(icon);
|
||||
|
||||
[settingsBtn, disconnectBtn, removeBtn] = Array.from(document.querySelectorAll("ul.ClusterActionsMenu > li"))
|
||||
.map(el => el.querySelector("span"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cluster.online = false;
|
||||
});
|
||||
|
||||
it("renders cluster menu items", () => {
|
||||
expect(settingsBtn).toBeDefined();
|
||||
expect(settingsBtn.textContent).toBe("Settings");
|
||||
expect(disconnectBtn).toBeDefined();
|
||||
expect(disconnectBtn.textContent).toBe("Disconnect");
|
||||
expect(removeBtn).toBeDefined();
|
||||
expect(removeBtn.textContent).toBe("Remove");
|
||||
});
|
||||
|
||||
it("navigates to cluster settings", () => {
|
||||
fireEvent.click(settingsBtn);
|
||||
expect(mockBroadcastIpc).toBeCalledWith("renderer:navigate", "/cluster/foo/settings");
|
||||
});
|
||||
|
||||
it("disconnects from cluster", () => {
|
||||
fireEvent.click(disconnectBtn);
|
||||
expect(mockRequestMain).toBeCalledWith(clusterDisconnectHandler, cluster.id);
|
||||
});
|
||||
|
||||
it("opens 'Remove cluster' dialog", async () => {
|
||||
fireEvent.click(removeBtn);
|
||||
|
||||
const dialog = document.querySelector(".ConfirmDialog");
|
||||
|
||||
expect(dialog).toBeDefined();
|
||||
expect(dialog).not.toBe(null);
|
||||
|
||||
const okBtn = dialog.querySelector("button.ok");
|
||||
|
||||
expect(okBtn.textContent).toBe("Remove");
|
||||
// console.log(dialog);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user