"use strict";
var __webpack_exports__ = {};
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const client_namespaceObject = require("@tachybase/client");
const react_namespaceObject = require("@testing-library/react");
const DataSourceProvider_js_namespaceObject = require("../../data-source/DataSourceProvider.js");
describe('ExtendCollectionsProvider', ()=>{
    const app = new client_namespaceObject.Application({
        dataSourceManager: {
            dataSources: [
                {
                    key: 'test',
                    displayName: 'test'
                }
            ]
        }
    });
    const TestComponent = ()=>{
        const cm = (0, client_namespaceObject.useCollectionManager)();
        const dataSourceKey = (0, DataSourceProvider_js_namespaceObject.useDataSourceKey)();
        const collections = cm.getCollections();
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    "data-testid": "data-source",
                    children: dataSourceKey
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    "data-testid": "collections",
                    children: collections.map((collection)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                            children: collection.name
                        }, collection.name))
                })
            ]
        });
    };
    const App = (param)=>{
        let { children } = param;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.DataSourceManagerProvider, {
            dataSourceManager: app.dataSourceManager,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.CollectionManagerProvider, {
                dataSource: "test",
                children: children
            })
        });
    };
    test('should provide extend collections', ()=>{
        const collections = [
            {
                name: 'collection1'
            },
            {
                name: 'collection2'
            }
        ];
        (0, react_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.ExtendCollectionsProvider, {
                collections: collections,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TestComponent, {})
            })
        }));
        expect(react_namespaceObject.screen.getByTestId('collections')).toHaveTextContent('collection1');
        expect(react_namespaceObject.screen.getByTestId('collections')).toHaveTextContent('collection2');
        expect(react_namespaceObject.screen.getByTestId('data-source')).toHaveTextContent('test');
    });
    it('extends parent collections with the given ones', ()=>{
        (0, react_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.ExtendCollectionsProvider, {
                collections: [
                    {
                        name: 'collection1'
                    }
                ],
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.ExtendCollectionsProvider, {
                    collections: [
                        {
                            name: 'collection2'
                        }
                    ],
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TestComponent, {})
                })
            })
        }));
        expect(react_namespaceObject.screen.getByTestId('collections')).toHaveTextContent('collection1');
        expect(react_namespaceObject.screen.getByTestId('collections')).toHaveTextContent('collection2');
        expect(react_namespaceObject.screen.getByTestId('data-source')).toHaveTextContent('test');
    });
});
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
});
