import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__ from "@tachybase/test/client";
import * as __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__ from "../../collection-record/index.mjs";
describe('CollectionRecordProvider', ()=>{
    describe('record and parentRecord', ()=>{
        test('record parameter is a `Record` instance', ()=>{
            const Demo = ()=>{
                const record = (0, __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.useCollectionRecord)();
                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            const record = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                }
            });
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Demo, {})
            }));
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                id: 1,
                name: 'foo'
            }));
        });
        test('record parameter is a `plain object`', ()=>{
            const Demo = ()=>{
                const record = (0, __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.useCollectionRecord)();
                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecordProvider, {
                record: {
                    id: 1,
                    name: 'foo'
                },
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Demo, {})
            }));
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                id: 1,
                name: 'foo'
            }));
        });
        test('record parameter is a `Record` instance with parent record', ()=>{
            const Demo = ()=>{
                const record = (0, __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.useCollectionRecord)();
                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            const parentRecord = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord
            });
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Demo, {})
            }));
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord: {
                    data: {
                        id: 1,
                        role: 'admin'
                    }
                }
            }));
        });
        test('record parameter is a `Record` instance, parent record is passed through parentRecord parameter', ()=>{
            const Demo = ()=>{
                const record = (0, __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.useCollectionRecord)();
                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            const parentRecord = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                }
            });
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecordProvider, {
                record: record,
                parentRecord: parentRecord,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Demo, {})
            }));
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord: {
                    data: {
                        id: 1,
                        role: 'admin'
                    }
                }
            }));
        });
        test('record parameter is a `plain object`, parent record is also a `plain object`', ()=>{
            const Demo = ()=>{
                const record = (0, __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.useCollectionRecord)();
                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecordProvider, {
                record: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord: {
                    id: 1,
                    role: 'admin'
                },
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Demo, {})
            }));
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord: {
                    data: {
                        id: 1,
                        role: 'admin'
                    }
                }
            }));
        });
    });
    describe('hooks', ()=>{
        test('useCollectionRecordData()', ()=>{
            const Demo = ()=>{
                const data = (0, __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.useCollectionRecordData)();
                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(data)
                });
            };
            const parentRecord = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord
            });
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Demo, {})
            }));
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                id: 1,
                name: 'foo'
            }));
        });
        test('useCollectionParentRecord()', ()=>{
            const Demo = ()=>{
                const data = (0, __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.useCollectionParentRecord)();
                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(data)
                });
            };
            const parentRecord = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord
            });
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Demo, {})
            }));
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                data: {
                    id: 1,
                    role: 'admin'
                }
            }));
        });
        test('useCollectionParentRecordData()', ()=>{
            const Demo = ()=>{
                const data = (0, __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.useCollectionParentRecordData)();
                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(data)
                });
            };
            const parentRecord = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new __WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord
            });
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_record_index_mjs__.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Demo, {})
            }));
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                id: 1,
                role: 'admin'
            }));
        });
    });
});
