Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { fireEvent, render, screen } from "@testing-library/react";
import { InstructionsModal } from "../InstructionsModal";
 
describe("InstructionsModal Component", () => {
  it("should render the title and children", () => {
    const title = "Test Title";
    const children = <p>Test Children</p>;
    const { getByText } = render(
      <InstructionsModal title={title} visible={true} onCancel={() => {}}>
        {children}
      </InstructionsModal>,
    );
 
    expect(document.body.contains(getByText(title))).toBe(true);
    expect(document.body.contains(getByText("Test Children"))).toBe(true);
  });
 
  it("should render html", () => {
    const title = "Test Title";
    const children = '<h1 style="color: red;">Test Children</h1>';
 
    render(
      <InstructionsModal title={title} visible={true} onCancel={() => {}}>
        {children}
      </InstructionsModal>,
    );
 
    expect(screen.queryByText("Test Children")).toBeTruthy();
    expect(screen.queryByText("color: red")).toBeNull();
  });
 
  it("should call onCancel when the modal is cancelled", () => {
    const onCancel = jest.fn();
    const { getByLabelText } = render(
      <InstructionsModal title="Test Title" visible={true} onCancel={onCancel}>
        <p>Test Children</p>
      </InstructionsModal>,
    );
 
    fireEvent.click(getByLabelText("Close"));
    expect(onCancel).toHaveBeenCalledTimes(1);
  });
});