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__ConfirmItemDeleteModal_mjs__ from "./ConfirmItemDeleteModal.mjs";
describe('ConfirmItemDeleteModal', ()=>{
    test('should render modal trigger button', async ()=>{
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmItemDeleteModal_mjs__["default"], {
            itemType: "cluster",
            trigger: "Delete",
            onConfirm: (dismiss)=>{
                // 1. perform delete operation
                console.log('Simulating HTTP request...');
                setTimeout(()=>{
                    // 2. call dismiss() on success or onError() on error
                    console.log('calling dismiss...');
                    dismiss();
                }, 1000);
            }
        }));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('trigger-delete-button')).toBeVisible();
        });
    });
    test('should display modal with default confirmation text and actions buttons 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__ConfirmItemDeleteModal_mjs__["default"], {
            itemType: "cluster",
            trigger: "Delete",
            onConfirm: (dismiss)=>{
                // 1. perform delete operation
                console.log('Simulating HTTP request...');
                setTimeout(()=>{
                    // 2. call dismiss() on success or onError() on error
                    console.log('calling dismiss...');
                    dismiss();
                }, 1000);
            }
        }));
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('trigger-delete-button'));
        const modalHeading = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText(/Delete cluster/i);
        const modalContent = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText(/This action will cause data loss. To confirm, type "delete" into the confirmation box below/i);
        expect(modalHeading).toBeVisible();
        expect(modalContent).toBeVisible();
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('test-cancel-item')).toBeVisible();
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('test-delete-item')).toBeVisible();
    });
    test('modal delete button should be disabled on initial display of modal', async ()=>{
        const mockOnConfirm = jest.fn();
        const mockOnClose = jest.fn();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmItemDeleteModal_mjs__["default"], {
            itemType: "cluster",
            trigger: "Trigger",
            onConfirm: mockOnConfirm
        }));
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('trigger-delete-button'));
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('test-delete-item'));
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('test-delete-item')).toBeDisabled();
        expect(mockOnConfirm).not.toHaveBeenCalled();
        expect(mockOnClose).not.toHaveBeenCalled();
    });
    test('should trigger onConfirm function when clicking the delete button after input', async ()=>{
        const mockOnConfirm = jest.fn();
        const mockOnClose = jest.fn();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmItemDeleteModal_mjs__["default"], {
            itemType: "cluster",
            trigger: "Trigger",
            onConfirm: mockOnConfirm
        }));
        // show modal
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('trigger-delete-button'));
        const modalInputField = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByPlaceholderText(/Type \"delete\" to confirm/i);
        expect(modalInputField).toBeVisible();
        // type "delete" into the input field
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.focus(modalInputField);
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.change(modalInputField, {
            target: {
                value: 'delete'
            }
        });
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].tab();
        expect(modalInputField).toHaveValue('delete');
        // confirm deletion
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('test-delete-item'));
        expect(mockOnConfirm).toHaveBeenCalled();
        expect(mockOnClose).not.toHaveBeenCalled();
    });
    test('should display modal with custom input match text to enable delete', async ()=>{
        __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].setup();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmItemDeleteModal_mjs__["default"], {
            itemType: "cluster",
            trigger: "Delete",
            inputMatchText: "monday",
            onConfirm: (dismiss)=>{
                dismiss();
            }
        }));
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('trigger-delete-button'));
        const modalContent = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText(/This action will cause data loss. To confirm, type "monday" into the confirmation box below/i);
        expect(modalContent).toBeVisible();
        const textInput = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('txt-confirmation-delete');
        expect(textInput).toHaveAttribute('placeholder', 'Type "monday" to confirm');
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('test-delete-item')).toBeDisabled();
        // type text to enable delete
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].type(textInput, 'monday');
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('test-delete-item')).toBeEnabled();
    });
    test('should display error message when invalid input match text is entered', async ()=>{
        __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].setup();
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__ConfirmItemDeleteModal_mjs__["default"], {
            inputMatchText: "tuesday",
            itemType: "cluster",
            trigger: "Delete",
            onConfirm: (dismiss)=>{
                dismiss();
            }
        }));
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('trigger-delete-button'));
        const modalContent = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText(/This action will cause data loss. To confirm, type "tuesday" into the confirmation box below/i);
        expect(modalContent).toBeVisible();
        const textInput = __WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('txt-confirmation-delete');
        expect(textInput).toHaveAttribute('placeholder', 'Type "tuesday" to confirm');
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('test-delete-item')).toBeDisabled();
        // type inccorect text into input field
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].type(textInput, 'dlete');
        await __WEBPACK_EXTERNAL_MODULE__testing_library_user_event__["default"].tab();
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText(/Text must match "tuesday"/i)).toBeVisible();
    });
});
