Close the release announcement when a dialog is opened (#12559)

* Fire `ModalManagerEvent.Closed` when a dialog is closed

* Listen to modal events in the RA

* Fix first RA test
This commit is contained in:
Florian Duros 2024-05-29 09:22:50 +02:00 committed by GitHub
parent 17ab522942
commit 679b170bc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 63 additions and 5 deletions

View file

@ -17,11 +17,19 @@
*/
import React from "react";
import { render, screen, waitFor } from "@testing-library/react";
import { act, render, screen, waitFor } from "@testing-library/react";
import { ReleaseAnnouncement } from "../../../src/components/structures/ReleaseAnnouncement";
import Modal, { ModalManagerEvent } from "../../../src/Modal";
import { ReleaseAnnouncementStore } from "../../../src/stores/ReleaseAnnouncementStore";
describe("ReleaseAnnouncement", () => {
beforeEach(async () => {
// Reset the singleton instance of the ReleaseAnnouncementStore
// @ts-ignore
ReleaseAnnouncementStore.internalInstance = new ReleaseAnnouncementStore();
});
function renderReleaseAnnouncement() {
return render(
<ReleaseAnnouncement
@ -39,10 +47,30 @@ describe("ReleaseAnnouncement", () => {
renderReleaseAnnouncement();
// The release announcement is displayed
expect(screen.queryByRole("dialog", { name: "header" })).toBeDefined();
expect(screen.queryByRole("dialog", { name: "header" })).toBeVisible();
// Click on the close button in the release announcement
screen.getByRole("button", { name: "close" }).click();
// The release announcement should be hidden after the close button is clicked
await waitFor(() => expect(screen.queryByRole("dialog", { name: "header" })).toBeNull());
});
test("when a dialog is opened, the release announcement should not be displayed", async () => {
renderReleaseAnnouncement();
// The release announcement is displayed
expect(screen.queryByRole("dialog", { name: "header" })).toBeVisible();
// Open a dialog
act(() => {
Modal.emit(ModalManagerEvent.Opened);
});
// The release announcement should be hidden after the dialog is opened
expect(screen.queryByRole("dialog", { name: "header" })).toBeNull();
// Close the dialog
act(() => {
Modal.emit(ModalManagerEvent.Closed);
});
// The release announcement should be displayed after the dialog is closed
expect(screen.queryByRole("dialog", { name: "header" })).toBeVisible();
});
});