import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_client__ from "@tachybase/client";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__ from "@tachybase/test/client";
import * as __WEBPACK_EXTERNAL_MODULE__application_AppSchemaComponentProvider_mjs__ from "../../../application/AppSchemaComponentProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_DataSourceProvider_mjs__ from "../../data-source/DataSourceProvider.mjs";
describe('DataSourceProvider', ()=>{
    function renderComponent(dataSource, status) {
        const app = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Application({
            dataSourceManager: {
                collections: [
                    {
                        name: 'a'
                    }
                ]
            }
        });
        const Demo = ()=>{
            const dataSourceKey = (0, __WEBPACK_EXTERNAL_MODULE__data_source_DataSourceProvider_mjs__.useDataSourceKey)();
            return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                "data-testid": "demo",
                children: dataSourceKey
            });
        };
        const dataSourceOptions = {
            key: 'test',
            displayName: 'Test',
            status: status
        };
        class TestDataSource extends __WEBPACK_EXTERNAL_MODULE__tachybase_client__.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, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_AppSchemaComponentProvider_mjs__.AppSchemaComponentProvider, {
            designable: true,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.DataSourceManagerProvider, {
                dataSourceManager: app.dataSourceManager,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponent, {
                    schema: schema,
                    components: {
                        Demo,
                        DataSourceProvider: __WEBPACK_EXTERNAL_MODULE__data_source_DataSourceProvider_mjs__.DataSourceProvider
                    }
                })
            })
        }));
    }
    it('should render default dataSource', ()=>{
        renderComponent();
        expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('demo')).toHaveTextContent(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.DEFAULT_DATA_SOURCE_KEY);
    });
    it('should render children when data source is available', ()=>{
        renderComponent('test');
        expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.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(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByText('Test data source loading...')).toBeInTheDocument();
    });
    it('should render error state when data source loading fails', ()=>{
        renderComponent('test', 'loading-failed');
        expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByText('DataSource "Test" loading failed')).toBeInTheDocument();
    });
});
