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__testing_library_react__ from "@testing-library/react";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_DataSourceProvider_mjs__ from "../../data-source/DataSourceProvider.mjs";
describe('ExtendCollectionsProvider', ()=>{
    const app = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Application({
        dataSourceManager: {
            dataSources: [
                {
                    key: 'test',
                    displayName: 'test'
                }
            ]
        }
    });
    const TestComponent = ()=>{
        const cm = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useCollectionManager)();
        const dataSourceKey = (0, __WEBPACK_EXTERNAL_MODULE__data_source_DataSourceProvider_mjs__.useDataSourceKey)();
        const collections = cm.getCollections();
        return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
            children: [
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                    "data-testid": "data-source",
                    children: dataSourceKey
                }),
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                    "data-testid": "collections",
                    children: collections.map((collection)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                            children: collection.name
                        }, collection.name))
                })
            ]
        });
    };
    const App = (param)=>{
        let { children } = param;
        return /*#__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__.CollectionManagerProvider, {
                dataSource: "test",
                children: children
            })
        });
    };
    test('should provide extend collections', ()=>{
        const collections = [
            {
                name: 'collection1'
            },
            {
                name: 'collection2'
            }
        ];
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(App, {
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.ExtendCollectionsProvider, {
                collections: collections,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(TestComponent, {})
            })
        }));
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('collections')).toHaveTextContent('collection1');
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('collections')).toHaveTextContent('collection2');
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('data-source')).toHaveTextContent('test');
    });
    it('extends parent collections with the given ones', ()=>{
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(App, {
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.ExtendCollectionsProvider, {
                collections: [
                    {
                        name: 'collection1'
                    }
                ],
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.ExtendCollectionsProvider, {
                    collections: [
                        {
                            name: 'collection2'
                        }
                    ],
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(TestComponent, {})
                })
            })
        }));
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('collections')).toHaveTextContent('collection1');
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('collections')).toHaveTextContent('collection2');
        expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('data-source')).toHaveTextContent('test');
    });
});
