Skip to content

Commit

Permalink
test(Modal): add tests for component
Browse files Browse the repository at this point in the history
  • Loading branch information
YossiSaadi committed Sep 24, 2024
1 parent 8cfe5c9 commit 29b4ff9
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from "react";
import { render, fireEvent } from "@testing-library/react";
import Modal from "../Modal";

describe("Modal", () => {
const closeButtonAriaLabel = "Close modal";
const childrenContent = <span>My content</span>;

it("renders the modal with the correct role", () => {
const { getByTestId } = render(
<Modal show data-testid="modal">
{childrenContent}
</Modal>
);

expect(getByTestId("modal")).toHaveAttribute("role", "dialog");
});

it("renders the modal with the correct aria-modal", () => {
const { getByTestId } = render(
<Modal show data-testid="modal">
{childrenContent}
</Modal>
);

expect(getByTestId("modal")).toHaveAttribute("aria-modal", "true");
});

it("renders the children content correctly", () => {
const { getByText } = render(
<Modal show closeButtonAriaLabel={closeButtonAriaLabel}>
{childrenContent}
</Modal>
);

expect(getByText("My content")).toBeInTheDocument();
});

it("calls onClose when the close button is clicked", () => {
const mockOnClose = jest.fn();
const { getByLabelText } = render(
<Modal show onClose={mockOnClose} closeButtonAriaLabel={closeButtonAriaLabel}>
{childrenContent}
</Modal>
);

fireEvent.click(getByLabelText(closeButtonAriaLabel));
expect(mockOnClose).toHaveBeenCalled();
});

it.todo("does not render when 'show' is false");

it.todo("renders the correct aria-labelledby");

it.todo("renders the correct aria-describedby");
});

0 comments on commit 29b4ff9

Please sign in to comment.