"use strict";
// The require scope
var __webpack_require__ = {};
/************************************************************************/ // webpack/runtime/compat_get_default_export
(()=>{
    // getDefaultExport function for compatibility with non-ESM modules
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
// webpack/runtime/define_property_getters
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
// webpack/runtime/has_own_property
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
/************************************************************************/ var __webpack_exports__ = {};
const react_namespaceObject = require("@testing-library/react");
const user_event_namespaceObject = require("@testing-library/user-event");
var user_event_default = /*#__PURE__*/ __webpack_require__.n(user_event_namespaceObject);
const external_ConfirmItemDeleteModal_js_namespaceObject = require("./ConfirmItemDeleteModal.js");
var external_ConfirmItemDeleteModal_js_default = /*#__PURE__*/ __webpack_require__.n(external_ConfirmItemDeleteModal_js_namespaceObject);
describe('ConfirmItemDeleteModal', ()=>{
    test('should render modal trigger button', async ()=>{
        (0, react_namespaceObject.render)(/*#__PURE__*/ React.createElement(external_ConfirmItemDeleteModal_js_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, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByTestId('trigger-delete-button')).toBeVisible();
        });
    });
    test('should display modal with default confirmation text and actions buttons after clicking trigger button', async ()=>{
        user_event_default().setup();
        (0, react_namespaceObject.render)(/*#__PURE__*/ React.createElement(external_ConfirmItemDeleteModal_js_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 user_event_default().click(react_namespaceObject.screen.getByTestId('trigger-delete-button'));
        const modalHeading = react_namespaceObject.screen.getByText(/Delete cluster/i);
        const modalContent = react_namespaceObject.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(react_namespaceObject.screen.getByTestId('test-cancel-item')).toBeVisible();
        expect(react_namespaceObject.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, react_namespaceObject.render)(/*#__PURE__*/ React.createElement(external_ConfirmItemDeleteModal_js_default(), {
            itemType: "cluster",
            trigger: "Trigger",
            onConfirm: mockOnConfirm
        }));
        await user_event_default().click(react_namespaceObject.screen.getByTestId('trigger-delete-button'));
        await user_event_default().click(react_namespaceObject.screen.getByTestId('test-delete-item'));
        expect(react_namespaceObject.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, react_namespaceObject.render)(/*#__PURE__*/ React.createElement(external_ConfirmItemDeleteModal_js_default(), {
            itemType: "cluster",
            trigger: "Trigger",
            onConfirm: mockOnConfirm
        }));
        // show modal
        await user_event_default().click(react_namespaceObject.screen.getByTestId('trigger-delete-button'));
        const modalInputField = react_namespaceObject.screen.getByPlaceholderText(/Type \"delete\" to confirm/i);
        expect(modalInputField).toBeVisible();
        // type "delete" into the input field
        react_namespaceObject.fireEvent.focus(modalInputField);
        react_namespaceObject.fireEvent.change(modalInputField, {
            target: {
                value: 'delete'
            }
        });
        await user_event_default().tab();
        expect(modalInputField).toHaveValue('delete');
        // confirm deletion
        await user_event_default().click(react_namespaceObject.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 ()=>{
        user_event_default().setup();
        (0, react_namespaceObject.render)(/*#__PURE__*/ React.createElement(external_ConfirmItemDeleteModal_js_default(), {
            itemType: "cluster",
            trigger: "Delete",
            inputMatchText: "monday",
            onConfirm: (dismiss)=>{
                dismiss();
            }
        }));
        await user_event_default().click(react_namespaceObject.screen.getByTestId('trigger-delete-button'));
        const modalContent = react_namespaceObject.screen.queryByText(/This action will cause data loss. To confirm, type "monday" into the confirmation box below/i);
        expect(modalContent).toBeVisible();
        const textInput = react_namespaceObject.screen.getByTestId('txt-confirmation-delete');
        expect(textInput).toHaveAttribute('placeholder', 'Type "monday" to confirm');
        expect(react_namespaceObject.screen.getByTestId('test-delete-item')).toBeDisabled();
        // type text to enable delete
        await user_event_default().type(textInput, 'monday');
        expect(react_namespaceObject.screen.getByTestId('test-delete-item')).toBeEnabled();
    });
    test('should display error message when invalid input match text is entered', async ()=>{
        user_event_default().setup();
        (0, react_namespaceObject.render)(/*#__PURE__*/ React.createElement(external_ConfirmItemDeleteModal_js_default(), {
            inputMatchText: "tuesday",
            itemType: "cluster",
            trigger: "Delete",
            onConfirm: (dismiss)=>{
                dismiss();
            }
        }));
        await user_event_default().click(react_namespaceObject.screen.getByTestId('trigger-delete-button'));
        const modalContent = react_namespaceObject.screen.queryByText(/This action will cause data loss. To confirm, type "tuesday" into the confirmation box below/i);
        expect(modalContent).toBeVisible();
        const textInput = react_namespaceObject.screen.getByTestId('txt-confirmation-delete');
        expect(textInput).toHaveAttribute('placeholder', 'Type "tuesday" to confirm');
        expect(react_namespaceObject.screen.getByTestId('test-delete-item')).toBeDisabled();
        // type inccorect text into input field
        await user_event_default().type(textInput, 'dlete');
        await user_event_default().tab();
        expect(react_namespaceObject.screen.getByText(/Text must match "tuesday"/i)).toBeVisible();
    });
});
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
