xonecas.io
4828
Sr

stream-together / files

stream-together / __tests__ / modal.test.tsx

1023 bytes
1import { render, screen } from "@testing-library/react";
2
3import { Modal } from "@/components/modal";
4
5describe("Modal component", () => {
6  it("renders the modal", async () => {
7    render(
8      <Modal openButton={<button>open</button>} showModal={true}>
9        <p>Modal content should be visible</p>
10      </Modal>,
11    );
12
13    const openButton = await screen.findByText("open");
14    expect(openButton).toBeInTheDocument();
15
16    const modalContent = await screen.findByText(
17      "Modal content should be visible",
18    );
19    expect(modalContent).toBeInTheDocument();
20  });
21
22  it("renders only the button", async () => {
23    render(
24      <Modal openButton={<button>open</button>} showModal={false}>
25        <p>Modal content should be visible</p>
26      </Modal>,
27    );
28
29    const openButton = await screen.findByText("open");
30    expect(openButton).toBeInTheDocument();
31
32    const modalContent = await screen.queryByText(
33      "Modal content should be visible",
34    );
35    expect(modalContent).toBeNull();
36  });
37});