"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 external_Form_js_namespaceObject = require("./Form.js");
var external_Form_js_default = /*#__PURE__*/ __webpack_require__.n(external_Form_js_namespaceObject);
const external_yup_namespaceObject = require("yup");
const external_FormProvider_js_namespaceObject = require("./FormProvider.js");
var external_FormProvider_js_default = /*#__PURE__*/ __webpack_require__.n(external_FormProvider_js_namespaceObject);
const FormField_js_namespaceObject = require("../FormField/FormField.js");
var FormField_js_default = /*#__PURE__*/ __webpack_require__.n(FormField_js_namespaceObject);
const external_chakra_ui_react_namespaceObject = require("@chakra-ui/react");
describe('Form', ()=>{
    test('should render a form and display errors conditionally for each missing field', async ()=>{
        (0, react_namespaceObject.render)(/*#__PURE__*/ React.createElement(external_FormProvider_js_default(), null, /*#__PURE__*/ React.createElement(external_Form_js_default(), {
            mode: "all",
            autofocus: true,
            onValid: ()=>{
            // no op
            },
            onInvalid: ()=>{
            // no op
            },
            fields: [
                {
                    name: 'name',
                    fieldType: 'text',
                    label: 'Name',
                    placeholder: 'Name',
                    schema: external_yup_namespaceObject.string().required('Provide a name')
                },
                {
                    name: 'someField',
                    fieldType: 'hidden',
                    label: 'Hidden',
                    placeholder: 'This should not be visible',
                    schema: external_yup_namespaceObject.string()
                },
                {
                    name: 'description',
                    fieldType: 'textarea',
                    label: 'Description',
                    placeholder: 'Description',
                    schema: external_yup_namespaceObject.string().required('Provide a description')
                },
                {
                    name: 'someNumber',
                    fieldType: 'number',
                    label: 'Number',
                    placeholder: '12345',
                    schema: external_yup_namespaceObject.number().required('Provide a number')
                },
                {
                    name: 'deploymentType',
                    fieldType: 'toggle',
                    label: 'Deployment',
                    defaultValue: 'false',
                    placeholder: 'Deployment type',
                    schema: external_yup_namespaceObject.string().required('Provide BYOC/FMC deployment type')
                },
                {
                    name: 'maxThroughput',
                    fieldType: 'radio',
                    label: 'Throughput',
                    placeholder: 'Max throughput',
                    defaultValue: '1',
                    schema: external_yup_namespaceObject.string().required('Provide max throughput'),
                    options: [
                        {
                            value: '1',
                            label: 'Option 1'
                        },
                        {
                            value: '2',
                            label: 'Option 2',
                            disabled: true
                        },
                        {
                            value: '3',
                            label: 'Option 3',
                            invalid: true
                        },
                        {
                            value: '4',
                            label: 'Option 4',
                            invalid: true,
                            disabled: true
                        }
                    ]
                }
            ],
            button: {
                label: 'confirm_some_form',
                text: 'Create'
            },
            developerView: true
        })));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByTestId('name_field')).toBeVisible();
            expect(react_namespaceObject.screen.queryByText('someField_field')).not.toBeInTheDocument();
            expect(react_namespaceObject.screen.getByTestId('description_field')).toBeVisible();
            expect(react_namespaceObject.screen.getByTestId('someNumber_field')).toBeVisible();
            expect(react_namespaceObject.screen.getByTestId('deploymentType_field')).toBeVisible();
            expect(react_namespaceObject.screen.getByTestId('maxThroughput_field')).toBeVisible();
            // expect(screen.getByTestId('region_field')).toBeVisible();
            expect(react_namespaceObject.screen.queryByTestId('confirm_some_form')).toBeVisible();
            expect(react_namespaceObject.screen.queryByTestId('confirm_some_form')).toBeEnabled();
        });
        react_namespaceObject.fireEvent.click(react_namespaceObject.screen.getByTestId('confirm_some_form'));
        react_namespaceObject.fireEvent.blur(react_namespaceObject.screen.getByTestId('name_field'));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByText('Provide a name')).toBeVisible();
            expect(react_namespaceObject.screen.queryByTestId('confirm_some_form')).toBeDisabled();
        });
        react_namespaceObject.fireEvent.focus(react_namespaceObject.screen.getByTestId('description_field'));
        react_namespaceObject.fireEvent.blur(react_namespaceObject.screen.getByTestId('description_field'));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByText('Provide a description')).toBeVisible();
        });
        react_namespaceObject.fireEvent.focus(react_namespaceObject.screen.getByTestId('someNumber_field'));
        react_namespaceObject.fireEvent.blur(react_namespaceObject.screen.getByTestId('someNumber_field'));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByText('Provide a number')).toBeVisible();
        });
        react_namespaceObject.fireEvent.focus(react_namespaceObject.screen.getByTestId('deploymentType_field'));
        react_namespaceObject.fireEvent.blur(react_namespaceObject.screen.getByTestId('deploymentType_field'));
        await (0, react_namespaceObject.waitFor)(()=>{
            // Value is already provided
            expect(react_namespaceObject.screen.queryByText('Provide BYOC/FMC deployment type')).not.toBeInTheDocument();
        });
        react_namespaceObject.fireEvent.focus(react_namespaceObject.screen.getByTestId('maxThroughput_field'));
        react_namespaceObject.fireEvent.blur(react_namespaceObject.screen.getByTestId('maxThroughput_field'));
        await (0, react_namespaceObject.waitFor)(()=>{
            // Value is already provided
            expect(react_namespaceObject.screen.queryByText('Provide max throughput')).not.toBeInTheDocument();
        });
    // fireEvent.focus(screen.getByTestId('region_field'));
    // fireEvent.blur(screen.getByTestId('region_field'));
    // await waitFor(() => {
    //   expect(screen.getByText('Provide a region')).toBeVisible();
    // });
    });
    test('should allow filling in the form with correct values', async ()=>{
        (0, react_namespaceObject.render)(/*#__PURE__*/ React.createElement(external_FormProvider_js_default(), null, /*#__PURE__*/ React.createElement(external_Form_js_default(), {
            mode: "all",
            autofocus: true,
            onValid: ()=>{},
            onInvalid: ()=>{},
            fields: [
                {
                    name: 'name',
                    fieldType: 'text',
                    label: 'Name',
                    placeholder: 'Name',
                    schema: external_yup_namespaceObject.string().required('Provide a name')
                },
                {
                    name: 'someField',
                    fieldType: 'hidden',
                    label: 'Hidden',
                    placeholder: 'This should not be visible',
                    schema: external_yup_namespaceObject.string()
                },
                {
                    name: 'description',
                    fieldType: 'textarea',
                    label: 'Description',
                    placeholder: 'Description',
                    schema: external_yup_namespaceObject.string().required('Provide a description')
                },
                {
                    name: 'someNumber',
                    fieldType: 'number',
                    label: 'Number',
                    placeholder: '12345',
                    schema: external_yup_namespaceObject.number().required('Provide a number')
                },
                {
                    name: 'deploymentType',
                    fieldType: 'toggle',
                    label: 'Deployment',
                    placeholder: 'Deployment type',
                    schema: external_yup_namespaceObject.string().required('Provide BYOC/FMC deployment type')
                },
                {
                    name: 'maxThroughput',
                    fieldType: 'radio',
                    label: 'Throughput',
                    placeholder: 'Max throughput',
                    schema: external_yup_namespaceObject.string().required('Provide max throughput'),
                    options: [
                        {
                            value: '1',
                            label: 'Option 1'
                        },
                        {
                            value: '2',
                            label: 'Option 2',
                            disabled: true
                        },
                        {
                            value: '3',
                            label: 'Option 3',
                            invalid: true
                        },
                        {
                            value: '4',
                            label: 'Option 4',
                            invalid: true,
                            disabled: true
                        }
                    ]
                }
            ],
            button: {
                label: 'confirm_some_form',
                text: 'Create'
            },
            developerView: true
        })));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByTestId('confirm_some_form')).toBeEnabled();
        });
        react_namespaceObject.fireEvent.change(react_namespaceObject.screen.getByTestId('name_field'), {
            target: {
                value: 'asdf'
            }
        });
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByTestId('name_field')).toHaveValue('asdf');
        });
        react_namespaceObject.fireEvent.change(react_namespaceObject.screen.getByTestId('description_field'), {
            target: {
                value: 'desc'
            }
        });
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByTestId('description_field')).toHaveValue('desc');
        });
        react_namespaceObject.fireEvent.change(react_namespaceObject.screen.getByTestId('someNumber_field'), {
            target: {
                value: 12345
            }
        });
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByTestId('someNumber_field')).toHaveValue('12345');
        });
        react_namespaceObject.fireEvent.change((0, react_namespaceObject.within)(react_namespaceObject.screen.getByTestId('deploymentType_field')).getByRole('checkbox'), {
            target: {
                checked: true
            }
        });
        await (0, react_namespaceObject.waitFor)(()=>{
            expect((0, react_namespaceObject.within)(react_namespaceObject.screen.getByTestId('deploymentType_field')).getByRole('checkbox')).toBeChecked();
        });
        react_namespaceObject.fireEvent.click(react_namespaceObject.screen.getByText('Option 1'));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByText('Option 1')).toHaveAttribute('data-checked');
        });
        react_namespaceObject.fireEvent.click(react_namespaceObject.screen.getByTestId('confirm_some_form'));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByTestId('confirm_some_form')).toBeEnabled();
        });
    });
    test('should render a form with custom section and display errors conditionally for each missing field', async ()=>{
        const CustomFormSectionComponent = ({ form, setValidationContext })=>{
            const { register, formState: { errors } } = form;
            return /*#__PURE__*/ React.createElement(FormField_js_default(), {
                description: 'custom description...',
                label: 'custom label',
                showRequiredIndicator: false,
                isInvalid: !!errors.customText,
                errorText: errors.customText?.message
            }, /*#__PURE__*/ React.createElement(external_chakra_ui_react_namespaceObject.Input, {
                placeholder: "custom field placeholder",
                type: "text",
                "data-testid": "customText_field",
                ...register('customText')
            }));
        };
        (0, react_namespaceObject.render)(/*#__PURE__*/ React.createElement(external_FormProvider_js_default(), null, /*#__PURE__*/ React.createElement(external_Form_js_default(), {
            mode: "all",
            autofocus: true,
            onValid: ()=>{
            // no op
            },
            onInvalid: ()=>{
            // no op
            },
            fields: [
                {
                    name: 'name',
                    fieldType: 'text',
                    label: 'Name',
                    placeholder: 'Name',
                    schema: external_yup_namespaceObject.string().required('Provide a name')
                },
                {
                    fieldType: 'custom',
                    name: 'customField',
                    label: 'customField',
                    component: CustomFormSectionComponent,
                    fields: [
                        {
                            fieldType: 'text',
                            label: 'Custom Text Field',
                            name: 'customText',
                            schema: external_yup_namespaceObject.string().required('Provide a custom field value')
                        }
                    ]
                }
            ],
            button: {
                label: 'confirm_some_form',
                text: 'Create'
            },
            developerView: true
        })));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByTestId('name_field')).toBeVisible();
            expect(react_namespaceObject.screen.getByTestId('customText_field')).toBeVisible();
            expect(react_namespaceObject.screen.queryByTestId('confirm_some_form')).toBeVisible();
            expect(react_namespaceObject.screen.queryByTestId('confirm_some_form')).toBeEnabled();
        });
        react_namespaceObject.fireEvent.click(react_namespaceObject.screen.getByTestId('confirm_some_form'));
        react_namespaceObject.fireEvent.blur(react_namespaceObject.screen.getByTestId('name_field'));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByText('Provide a name')).toBeVisible();
            expect(react_namespaceObject.screen.queryByTestId('confirm_some_form')).toBeDisabled();
        });
        react_namespaceObject.fireEvent.focus(react_namespaceObject.screen.getByTestId('customText_field'));
        react_namespaceObject.fireEvent.blur(react_namespaceObject.screen.getByTestId('customText_field'));
        await (0, react_namespaceObject.waitFor)(()=>{
            expect(react_namespaceObject.screen.getByText('Provide a custom field value')).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
});
