Skip to content

Commit

Permalink
Update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed May 2, 2024
1 parent db04da1 commit da9ec7d
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion web/src/components/core/Popup.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -39,6 +41,8 @@ const TestingPopup = (props) => {
<Popup
title="Testing Popup component"
isOpen={isOpen}
isLoading={isLoading}
loadingText={loadingText}
{...props}
>
<p>The Popup Content</p>
Expand All @@ -55,6 +59,7 @@ describe("Popup", () => {
describe("when it is not open", () => {
beforeEach(() => {
isOpen = false;
isLoading = false;
});

it("renders nothing", async () => {
Expand All @@ -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 () => {
Expand All @@ -79,6 +85,14 @@ describe("Popup", () => {
within(dialog).getByText("The Popup Content");
});

it("does not display a progress message", async () => {
installerRender(<TestingPopup />);

const dialog = await screen.findByRole("dialog");

expect(within(dialog).queryByText(loadingText)).toBeNull();
});

it("renders the popup actions inside a PF/Modal footer", async () => {
installerRender(<TestingPopup />);

Expand All @@ -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(<TestingPopup />);

const dialog = await screen.findByRole("dialog");

expect(within(dialog).queryByText("The Popup Content")).toBeNull();
within(dialog).getByText(loadingText);
});
});
});

describe("Popup.PrimaryAction", () => {
Expand Down

0 comments on commit da9ec7d

Please sign in to comment.