import * as __WEBPACK_EXTERNAL_MODULE__testing_library_react__ from "@testing-library/react";
import * as __WEBPACK_EXTERNAL_MODULE__Modal_mjs__ from "./Modal.mjs";
describe('Modal', ()=>{
    test('should render modal heading, content, and close button if open', async ()=>{
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__Modal_mjs__["default"], {
            heading: "Modal heading",
            isOpen: true,
            onClose: ()=>{}
        }, /*#__PURE__*/ React.createElement("div", null, "Modal content")));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            const modalHeading = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText('Modal heading');
            const modalContent = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText('Modal content');
            const modalCloseButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByLabelText('Close');
            expect(modalHeading).toBeVisible();
            expect(modalContent).toBeVisible();
            expect(modalCloseButton).toBeVisible();
        });
    });
    test('should not render modal if closed', async ()=>{
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__Modal_mjs__["default"], {
            heading: "Modal heading",
            isOpen: false,
            onClose: ()=>{}
        }, /*#__PURE__*/ React.createElement("div", null, "Modal content")));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            const modalHeading = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText('Modal heading');
            const modalContent = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText('Modal content');
            const modalCloseButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByLabelText('Close');
            expect(modalHeading).toBeNull();
            expect(modalContent).toBeNull();
            expect(modalCloseButton).toBeNull();
        });
    });
    test('should trigger onClose function when clicking close button, and isClosable is true', async ()=>{
        const mockOnClose = jest.fn();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__Modal_mjs__["default"], {
            heading: "Modal heading",
            isOpen: true,
            onClose: mockOnClose,
            isClosable: true
        }, /*#__PURE__*/ React.createElement("div", null, "Modal content")));
        const modalCloseButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByLabelText('Close');
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.click(modalCloseButton);
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(mockOnClose).toHaveBeenCalled();
        });
    });
    test('should not be closable if isClosable is false, and should not trigger onClose function', async ()=>{
        const mockOnClose = jest.fn();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__Modal_mjs__["default"], {
            heading: "Modal heading",
            isOpen: true,
            onClose: mockOnClose,
            isClosable: false
        }, /*#__PURE__*/ React.createElement("div", null, "Modal content")));
        const modalCloseButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByLabelText('Close');
        if (modalCloseButton) __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.click(modalCloseButton);
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(modalCloseButton).toBeNull();
            expect(mockOnClose).not.toHaveBeenCalled();
        });
    });
});
