"use strict";
var __webpack_exports__ = {};
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const client_namespaceObject = require("@tachybase/client");
const test_client_namespaceObject = require("@tachybase/test/client");
const AppSchemaComponentProvider_js_namespaceObject = require("../../../application/AppSchemaComponentProvider.js");
const DataSourceProvider_js_namespaceObject = require("../../data-source/DataSourceProvider.js");
describe('DataSourceProvider', ()=>{
    function renderComponent(dataSource, status) {
        const app = new client_namespaceObject.Application({
            dataSourceManager: {
                collections: [
                    {
                        name: 'a'
                    }
                ]
            }
        });
        const Demo = ()=>{
            const dataSourceKey = (0, DataSourceProvider_js_namespaceObject.useDataSourceKey)();
            return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                "data-testid": "demo",
                children: dataSourceKey
            });
        };
        const dataSourceOptions = {
            key: 'test',
            displayName: 'Test',
            status: status
        };
        class TestDataSource extends client_namespaceObject.DataSource {
            async getDataSource() {
                return dataSourceOptions;
            }
        }
        app.dataSourceManager.addDataSource(TestDataSource, dataSourceOptions);
        const schema = {
            name: 'root',
            type: 'void',
            'x-decorator': 'DataSourceProvider',
            'x-decorator-props': {
                dataSource
            },
            'x-component': 'Demo'
        };
        (0, test_client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(AppSchemaComponentProvider_js_namespaceObject.AppSchemaComponentProvider, {
            designable: true,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.DataSourceManagerProvider, {
                dataSourceManager: app.dataSourceManager,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.SchemaComponent, {
                    schema: schema,
                    components: {
                        Demo,
                        DataSourceProvider: DataSourceProvider_js_namespaceObject.DataSourceProvider
                    }
                })
            })
        }));
    }
    it('should render default dataSource', ()=>{
        renderComponent();
        expect(test_client_namespaceObject.screen.getByTestId('demo')).toHaveTextContent(client_namespaceObject.DEFAULT_DATA_SOURCE_KEY);
    });
    it('should render children when data source is available', ()=>{
        renderComponent('test');
        expect(test_client_namespaceObject.screen.getByTestId('demo')).toHaveTextContent('test');
    });
    it('should render error state when data source is not found', ()=>{
        renderComponent('non-existent');
        expect(document.querySelector('.ant-result')).toBeInTheDocument();
    });
    it('should render loading state when data source is loading', ()=>{
        renderComponent('test', 'loading');
        expect(test_client_namespaceObject.screen.getByText('Test data source loading...')).toBeInTheDocument();
    });
    it('should render error state when data source loading fails', ()=>{
        renderComponent('test', 'loading-failed');
        expect(test_client_namespaceObject.screen.getByText('DataSource "Test" loading failed')).toBeInTheDocument();
    });
});
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
});
