"use strict";
var __webpack_exports__ = {};
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const client_namespaceObject = require("@tachybase/client");
const schema_namespaceObject = require("@tachybase/schema");
const test_client_namespaceObject = require("@tachybase/test/client");
const index_js_namespaceObject = require("../../schema-component/index.js");
const external_schema_toolbar_index_js_namespaceObject = require("../schema-toolbar/index.js");
describe('SchemaToolbar', ()=>{
    test('SchemaToolbarProvider & useSchemaToolbar', ()=>{
        const Demo = ()=>{
            const context = (0, external_schema_toolbar_index_js_namespaceObject.useSchemaToolbar)();
            return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                "data-testid": "content",
                children: context.test
            });
        };
        const Root = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_toolbar_index_js_namespaceObject.SchemaToolbarProvider, {
                test: '123',
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {})
            });
        (0, test_client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Root, {}));
        expect(test_client_namespaceObject.screen.getByTestId('content')).toHaveTextContent('123');
    });
    describe('useSchemaToolbarRender()', ()=>{
        const renderApp = function(demoSchema) {
            let designable = !(arguments.length > 1) || void 0 === arguments[1] || arguments[1];
            const Demo = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    "data-testid": "demo",
                    children: "Demo"
                });
            const CustomToolbar = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                            "data-testid": "custom-toolbar",
                            children: "CustomToolbar"
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                            "data-testid": "custom-toolbar-props",
                            children: JSON.stringify(props)
                        })
                    ]
                });
            const schema = {
                name: 'root',
                type: 'object',
                'x-decorator': 'Wrapper',
                'x-component': 'Demo',
                ...demoSchema
            };
            const Wrapper = (param)=>{
                let { children } = param;
                const schema = (0, schema_namespaceObject.useFieldSchema)();
                const context = (0, external_schema_toolbar_index_js_namespaceObject.useSchemaToolbarRender)(schema);
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                            "data-testid": "toolbar",
                            children: context.render({
                                customProps: '123'
                            })
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                            "data-testid": "toolbar-exists",
                            children: JSON.stringify(context.exists)
                        }),
                        children
                    ]
                });
            };
            const app = new client_namespaceObject.Application({});
            (0, test_client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.ApplicationContext.Provider, {
                value: app,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.SortableProvider, {
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.SchemaComponentProvider, {
                        designable: designable,
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.SchemaComponent, {
                            schema: schema,
                            components: {
                                Demo,
                                Wrapper,
                                CustomToolbar
                            }
                        })
                    })
                })
            }));
        };
        test('Render x-designer if x-designer has a value', ()=>{
            renderApp({
                'x-designer': 'CustomToolbar'
            });
            expect(test_client_namespaceObject.screen.getByTestId('custom-toolbar')).toHaveTextContent('CustomToolbar');
            expect(test_client_namespaceObject.screen.getByTestId('custom-toolbar-props')).toHaveTextContent('{"customProps":"123"}');
            expect(test_client_namespaceObject.screen.getByTestId('toolbar-exists')).toHaveTextContent('true');
        });
        test('Render x-toolbar if it has a value', ()=>{
            renderApp({
                'x-toolbar': 'CustomToolbar'
            });
            expect(test_client_namespaceObject.screen.getByTestId('custom-toolbar')).toHaveTextContent('CustomToolbar');
        });
        test('Render x-toolbar if both x-toolbar and x-designer have values', ()=>{
            renderApp({
                'x-toolbar': 'CustomToolbar',
                'x-designer': 'CustomToolbar'
            });
            expect(test_client_namespaceObject.screen.getByTestId('custom-toolbar')).toHaveTextContent('CustomToolbar');
        });
        test('Render the default SchemaToolbar component if x-toolbar and x-designer have no values and x-settings has a value', ()=>{
            renderApp({
                'x-settings': 'DemoSettings'
            });
            expect(test_client_namespaceObject.screen.getByTestId('toolbar').innerHTML.length > 0).toBe(true);
            expect(test_client_namespaceObject.screen.getByTestId('toolbar-exists')).toHaveTextContent('true');
        });
        test('Do not render if x-toolbar and x-designer have no values and x-settings also has no value', ()=>{
            renderApp({});
            expect(test_client_namespaceObject.screen.getByTestId('toolbar')).toHaveTextContent('');
            expect(test_client_namespaceObject.screen.getByTestId('toolbar-exists')).toHaveTextContent('false');
        });
        test('Do not render if the component corresponding to x-toolbar cannot be found', ()=>{
            renderApp({
                'x-toolbar': 'NotFound'
            });
            expect(test_client_namespaceObject.screen.getByTestId('toolbar')).toHaveTextContent('');
        });
        test('Do not render if designable is false', ()=>{
            renderApp({
                'x-designer': 'CustomToolbar'
            }, false);
            expect(test_client_namespaceObject.screen.getByTestId('toolbar')).toHaveTextContent('');
        });
        test('x-toolbar-props and custom Props', ()=>{
            renderApp({
                'x-toolbar': 'CustomToolbar',
                'x-toolbar-props': {
                    test: '123'
                }
            });
            expect(test_client_namespaceObject.screen.getByTestId('custom-toolbar-props')).toHaveTextContent('{"test":"123","customProps":"123"}');
        });
    });
});
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
});
