/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from "react";
import { EuiButton, EuiOverlayMask, EuiModal } from "@elastic/eui";
import { render, fireEvent } from "@testing-library/react";
import ModalRoot from "./ModalRoot";
import { ModalConsumer, ModalProvider } from "./Modal";
import { ServicesConsumer, ServicesContext } from "../../services/Services";
import { browserServicesMock } from "../../../test/mocks";
describe(" spec", () => {
it("renders nothing when not used", () => {
const { container } = render(
{services => services && }
);
expect(container.firstChild).toBeNull();
});
it("renders a modal that can close and open", () => {
const Modal = ({ onClose, text }: { onClose: () => {}; text: string }) => (
A modal that has {text}
);
const { queryByText, getByTestId, getByLabelText } = render(
{services => services && }
{({ onShow }) => (
onShow(Modal, { text: "interesting text" })}>
Show Modal
)}
);
expect(queryByText("A modal that has interesting text")).toBeNull();
fireEvent.click(getByTestId("showModal"));
expect(queryByText("A modal that has interesting text")).not.toBeNull();
fireEvent.click(getByLabelText("Closes this modal window"));
expect(queryByText("A modal that has interesting text")).toBeNull();
});
});