From b7b25fb1ff8aa2ec06ac5a6c9fe5d4f50e910bcb Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Tue, 26 Apr 2022 11:22:03 +0300 Subject: [PATCH] Introduce tests Signed-off-by: Alex Andreev --- .../__tests__/preferences-navigation.test.tsx | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 src/renderer/components/+preferences/preferences-navigation/__tests__/preferences-navigation.test.tsx diff --git a/src/renderer/components/+preferences/preferences-navigation/__tests__/preferences-navigation.test.tsx b/src/renderer/components/+preferences/preferences-navigation/__tests__/preferences-navigation.test.tsx new file mode 100644 index 0000000000..bfa370f192 --- /dev/null +++ b/src/renderer/components/+preferences/preferences-navigation/__tests__/preferences-navigation.test.tsx @@ -0,0 +1,182 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import React from "react"; +import "@testing-library/jest-dom/extend-expect"; +import type { DiContainer } from "@ogre-tools/injectable"; +import { getDiForUnitTesting } from "../../../../getDiForUnitTesting"; +import { type DiRender, renderFor } from "../../../test-utils/renderFor"; +import { PreferencesNavigation } from "../preferences-navigation"; +import type { PreferenceNavigationItem } from "../preference-navigation-items.injectable"; +import preferenceNavigationItemsInjectable from "../preference-navigation-items.injectable"; +import { computed } from "mobx"; +import { noop } from "../../../../utils"; +import type { IComputedValue } from "mobx/dist/internal"; +import { screen } from "@testing-library/dom"; + +describe("", () => { + let di: DiContainer; + let render: DiRender; + + beforeEach(async () => { + di = getDiForUnitTesting({ doGeneralOverrides: true }); + render = renderFor(di); + }); + + it("renders", () => { + const { container } = render(); + + expect(container).toBeInTheDocument(); + }); + + describe("when general navigation items passed", () => { + beforeEach(() => { + const generalNavItems: IComputedValue = computed(() => [ + { + id: "general", + label: "General", + isActive: computed(() => false), + isVisible: computed(() => true), + navigate: () => noop, + orderNumber: 0, + }, + { + id: "proxy", + label: "Proxy", + isActive: computed(() => false), + isVisible: computed(() => true), + navigate: () => noop, + orderNumber: 1, + }, + { + id: "kube", + label: "Kube", + isActive: computed(() => false), + isVisible: computed(() => false), + navigate: () => noop, + orderNumber: 2, + }, + ]); + + di.override(preferenceNavigationItemsInjectable, () => generalNavItems); + }); + + it("renders them", () => { + const { container } = render( + , + ); + + expect(container).toHaveTextContent("General"); + expect(container).toHaveTextContent("Proxy"); + }); + + it("does not show custom settings block", () => { + const { container } = render( + , + ); + + expect(container).not.toHaveTextContent("Custom Settings"); + }); + + it("does not render hidden navigation items", () => { + const { container } = render( + , + ); + + screen.debug(); + + expect(container).not.toHaveTextContent("Kube"); + }); + }); + + describe("when general + extension navigation items passed", () => { + beforeEach(() => { + const generalNavItems: IComputedValue = computed(() => [ + { + id: "general", + label: "General", + isActive: computed(() => false), + isVisible: computed(() => true), + navigate: () => noop, + orderNumber: 0, + }, + { + id: "proxy", + label: "Proxy", + isActive: computed(() => false), + isVisible: computed(() => true), + navigate: () => noop, + orderNumber: 1, + }, + // Extension navigation items + { + id: "extension-preferences-navigation-item-lensapp-node-menu", + label: "lensapp-node-menu", + isActive: computed(() => false), + isVisible: computed(() => true), + navigate: () => noop, + orderNumber: 0, + fromExtension: true, + }, + { + id: "extension-preferences-navigation-item-lensapp-pod-menu-id", + label: "lensapp-pod-menu", + isActive: computed(() => false), + isVisible: computed(() => true), + navigate: () => noop, + orderNumber: 0, + fromExtension: true, + }, + { + id: "extension-preferences-navigation-item-metrics-plugin-id", + label: "metrics-plugin", + isActive: computed(() => false), + isVisible: computed(() => false), + navigate: () => noop, + orderNumber: 0, + fromExtension: true, + }, + ]); + + di.override(preferenceNavigationItemsInjectable, () => generalNavItems); + }); + + it("renders general navigation items", () => { + const { container } = render( + , + ); + + expect(container).toHaveTextContent("General"); + expect(container).toHaveTextContent("Proxy"); + }); + + it("shows custom settings block", () => { + const { container } = render( + , + ); + + expect(container).toHaveTextContent("Custom Settings"); + }); + + it("renders extension navigation items", () => { + const { container } = render( + , + ); + + expect(container).toHaveTextContent("lensapp-node-menu"); + expect(container).toHaveTextContent("lensapp-pod-menu"); + }); + + it("does not render hidden extension navigation items", () => { + const { container } = render( + , + ); + + screen.debug(); + + expect(container).not.toHaveTextContent("metrics-plugin"); + }); + }); +});