apply review feedback

This commit is contained in:
Half-Shot
2024-11-07 16:58:35 +00:00
parent 41b00bd518
commit f3f730976f
2 changed files with 16 additions and 14 deletions

View File

@@ -5,11 +5,18 @@ SPDX-License-Identifier: AGPL-3.0-only
Please see LICENSE in the repository root for full details. Please see LICENSE in the repository root for full details.
*/ */
import { afterAll, expect, test } from "vitest"; import { expect, test } from "vitest";
import { render } from "@testing-library/react"; import { render } from "@testing-library/react";
import { act, ReactNode, useState } from "react"; import { act, ReactNode, useState } from "react";
import { Modal } from "./Modal"; import { Modal } from "./Modal";
import { afterEach } from "node:test";
import userEvent from "@testing-library/user-event";
const originalMatchMedia = window.matchMedia;
afterEach(() => {
window.matchMedia = originalMatchMedia;
});
test("that nothing is rendered when the modal is closed", () => { test("that nothing is rendered when the modal is closed", () => {
const { queryByRole } = render( const { queryByRole } = render(
@@ -29,7 +36,7 @@ test("the content is rendered when the modal is open", () => {
expect(queryByRole("dialog")).toMatchSnapshot(); expect(queryByRole("dialog")).toMatchSnapshot();
}); });
test("the modal can be closed by clicking the close button", () => { test("the modal can be closed by clicking the close button", async () => {
function ModalFn(): ReactNode { function ModalFn(): ReactNode {
const [isOpen, setOpen] = useState(true); const [isOpen, setOpen] = useState(true);
return ( return (
@@ -38,19 +45,14 @@ test("the modal can be closed by clicking the close button", () => {
</Modal> </Modal>
); );
} }
const { queryByRole, getByLabelText } = render(<ModalFn />); const user = userEvent.setup();
act(() => { const { queryByRole, getByRole } = render(<ModalFn />);
getByLabelText("action.close").click(); await act(async () => {
await user.click(getByRole("button", { name: "action.close" }));
}); });
expect(queryByRole("dialog")).toBeNull(); expect(queryByRole("dialog")).toBeNull();
}); });
const originalMatchMedia = window.matchMedia;
afterAll(() => {
window.matchMedia = originalMatchMedia;
});
test("the modal renders as a drawer in mobile viewports", () => { test("the modal renders as a drawer in mobile viewports", () => {
window.matchMedia = function (query): MediaQueryList { window.matchMedia = function (query): MediaQueryList {
return { return {

View File

@@ -89,9 +89,9 @@ export const Modal: FC<Props> = ({
styles.drawer, styles.drawer,
{ [styles.tabbed]: tabbed }, { [styles.tabbed]: tabbed },
)} )}
role="dialog"
// Suppress the warning about there being no description; the modal // Suppress the warning about there being no description; the modal
// has an accessible title // has an accessible title
role="dialog"
aria-describedby={undefined} aria-describedby={undefined}
{...rest} {...rest}
> >
@@ -115,10 +115,10 @@ export const Modal: FC<Props> = ({
<DialogOverlay <DialogOverlay
className={classNames(overlayStyles.bg, overlayStyles.animate)} className={classNames(overlayStyles.bg, overlayStyles.animate)}
/> />
{/* Suppress the warning about there being no description; the modal
has an accessible title */}
<DialogContent <DialogContent
asChild asChild
// Suppress the warning about there being no description; the modal
// has an accessible title
aria-describedby={undefined} aria-describedby={undefined}
role="dialog" role="dialog"
{...rest} {...rest}