/*
* 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 '../Modal/ModalRoot';
import { ModalConsumer, ModalProvider } from '../Modal/Modal';
import { ServicesConsumer, ServicesContext } from '../../services/services';
import { notificationServiceMock } from '../../../test/mocks/serviceMock';
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();
});
});