From da9ec7ddf9d86198c7d4b24590972eec4405031d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Thu, 2 May 2024 12:57:21 +0200 Subject: [PATCH] Update unit test --- web/src/components/core/Popup.test.jsx | 32 +++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/web/src/components/core/Popup.test.jsx b/web/src/components/core/Popup.test.jsx index 2184396eb8..db924b33ad 100644 --- a/web/src/components/core/Popup.test.jsx +++ b/web/src/components/core/Popup.test.jsx @@ -27,8 +27,10 @@ import { installerRender } from "~/test-utils"; import { Popup } from "~/components/core"; let isOpen; +let isLoading; const confirmFn = jest.fn(); const cancelFn = jest.fn(); +const loadingText = "Loading text"; const TestingPopup = (props) => { const [isMounted, setIsMounted] = useState(true); @@ -39,6 +41,8 @@ const TestingPopup = (props) => {

The Popup Content

@@ -55,6 +59,7 @@ describe("Popup", () => { describe("when it is not open", () => { beforeEach(() => { isOpen = false; + isLoading = false; }); it("renders nothing", async () => { @@ -65,9 +70,10 @@ describe("Popup", () => { }); }); - describe("when it is open", () => { + describe("when it is open and not loading", () => { beforeEach(() => { isOpen = true; + isLoading = false; }); it("renders the popup content inside a PF/Modal", async () => { @@ -79,6 +85,14 @@ describe("Popup", () => { within(dialog).getByText("The Popup Content"); }); + it("does not display a progress message", async () => { + installerRender(); + + const dialog = await screen.findByRole("dialog"); + + expect(within(dialog).queryByText(loadingText)).toBeNull(); + }); + it("renders the popup actions inside a PF/Modal footer", async () => { installerRender(); @@ -92,6 +106,22 @@ describe("Popup", () => { within(footer).getByText("Cancel"); }); }); + + describe("when it is open and loading", () => { + beforeEach(() => { + isOpen = true; + isLoading = true; + }); + + it("displays progress message instead of the content", async () => { + installerRender(); + + const dialog = await screen.findByRole("dialog"); + + expect(within(dialog).queryByText("The Popup Content")).toBeNull(); + within(dialog).getByText(loadingText); + }); + }); }); describe("Popup.PrimaryAction", () => {