import * as __WEBPACK_EXTERNAL_MODULE__testing_library_react__ from "@testing-library/react";
import * as __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__ from "@testing-library/user-event";
import * as __WEBPACK_EXTERNAL_MODULE__ConfirmModal_mjs__ from "./ConfirmModal.mjs";
describe('ConfirmModal', ()=>{
    test('should render modal trigger button', async ()=>{
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmModal_mjs__["default"], {
            trigger: "Confirm button",
            heading: "Confirm",
            onConfirm: ()=>{
                console.log('yes, you confirmed!');
            },
            onClose: ()=>{
                console.log('modal cancelled...');
            }
        }, "Are you sure?"));
        const triggerButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByRole('button');
        expect(triggerButton).toBeVisible();
        expect(triggerButton?.textContent).toBe('Confirm button');
    });
    test('should display modal with title after clicking trigger button', async ()=>{
        __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].setup();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmModal_mjs__["default"], {
            trigger: "Confirm",
            heading: "Confirm Heading",
            onConfirm: ()=>{
                console.log('yes, you confirmed!');
            },
            onClose: ()=>{
                console.log('modal cancelled...');
            }
        }, "Are you sure?"));
        const triggerButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByRole('button', {
            name: 'Confirm'
        });
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(triggerButton);
        const modalHeading = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText(/Confirm heading/i);
        const modalContent = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText(/are you sure\?/i);
        expect(modalHeading).toBeVisible();
        expect(modalContent).toBeVisible();
    });
    test('should display modal with custom action button labels after clicking trigger button', async ()=>{
        const mockOnConfirm = jest.fn();
        const mockOnClose = jest.fn();
        __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].setup();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmModal_mjs__["default"], {
            trigger: "Confirm",
            heading: "Confirm Heading",
            primaryActionLabel: "Do it",
            secondaryActionLabel: "Forget it",
            onConfirm: mockOnConfirm,
            onClose: mockOnClose
        }, "Are you sure?"));
        const triggerButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByRole('button', {
            name: 'Confirm'
        });
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(triggerButton);
        const modalCancelButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByRole('button', {
            name: 'Do it'
        });
        const modalConfirmButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByRole('button', {
            name: 'Forget it'
        });
        expect(modalCancelButton).toBeVisible();
        expect(modalConfirmButton).toBeVisible();
    });
    test('should trigger onConfirm function when clicking the confirm button', async ()=>{
        const mockOnConfirm = jest.fn();
        const mockOnClose = jest.fn();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmModal_mjs__["default"], {
            trigger: "Confirm trigger",
            heading: "Confirm Heading",
            onConfirm: mockOnConfirm,
            onClose: mockOnClose
        }, "Are you sure?"));
        const triggerButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByRole('button', {
            name: 'Confirm trigger'
        });
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(triggerButton);
        const modalConfirmButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByRole('button', {
            name: 'Confirm'
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.click(modalConfirmButton);
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(mockOnConfirm).toHaveBeenCalled();
            expect(mockOnClose).not.toHaveBeenCalled();
        });
    });
    test('should trigger onClose function when clicking cancel button', async ()=>{
        const mockOnConfirm = jest.fn();
        const mockOnClose = jest.fn();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmModal_mjs__["default"], {
            trigger: "Confirm",
            heading: "Confirm Heading",
            onConfirm: mockOnConfirm,
            onClose: mockOnClose
        }, "Are you sure?"));
        const triggerButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByRole('button', {
            name: 'Confirm'
        });
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(triggerButton);
        const modalCancelButton = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByRole('button', {
            name: 'Cancel'
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.click(modalCancelButton);
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(mockOnClose).toHaveBeenCalled();
            expect(mockOnConfirm).not.toHaveBeenCalled();
        });
    });
});
