"use strict";
var __webpack_exports__ = {};
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const client_namespaceObject = require("@tachybase/test/client");
const index_js_namespaceObject = require("../../collection-record/index.js");
describe('CollectionRecordProvider', ()=>{
    describe('record and parentRecord', ()=>{
        test('record parameter is a `Record` instance', ()=>{
            const Demo = ()=>{
                const record = (0, index_js_namespaceObject.useCollectionRecord)();
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            const record = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                }
            });
            (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {})
            }));
            expect(client_namespaceObject.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                id: 1,
                name: 'foo'
            }));
        });
        test('record parameter is a `plain object`', ()=>{
            const Demo = ()=>{
                const record = (0, index_js_namespaceObject.useCollectionRecord)();
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.CollectionRecordProvider, {
                record: {
                    id: 1,
                    name: 'foo'
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {})
            }));
            expect(client_namespaceObject.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, index_js_namespaceObject.useCollectionRecord)();
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            const parentRecord = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord
            });
            (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {})
            }));
            expect(client_namespaceObject.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, index_js_namespaceObject.useCollectionRecord)();
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            const parentRecord = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                }
            });
            (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.CollectionRecordProvider, {
                record: record,
                parentRecord: parentRecord,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {})
            }));
            expect(client_namespaceObject.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, index_js_namespaceObject.useCollectionRecord)();
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(record)
                });
            };
            (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.CollectionRecordProvider, {
                record: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord: {
                    id: 1,
                    role: 'admin'
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {})
            }));
            expect(client_namespaceObject.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, index_js_namespaceObject.useCollectionRecordData)();
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(data)
                });
            };
            const parentRecord = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord
            });
            (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {})
            }));
            expect(client_namespaceObject.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                id: 1,
                name: 'foo'
            }));
        });
        test('useCollectionParentRecord()', ()=>{
            const Demo = ()=>{
                const data = (0, index_js_namespaceObject.useCollectionParentRecord)();
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(data)
                });
            };
            const parentRecord = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord
            });
            (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {})
            }));
            expect(client_namespaceObject.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                data: {
                    id: 1,
                    role: 'admin'
                }
            }));
        });
        test('useCollectionParentRecordData()', ()=>{
            const Demo = ()=>{
                const data = (0, index_js_namespaceObject.useCollectionParentRecordData)();
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
                    "data-testid": "content",
                    children: JSON.stringify(data)
                });
            };
            const parentRecord = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    role: 'admin'
                }
            });
            const record = new index_js_namespaceObject.CollectionRecord({
                data: {
                    id: 1,
                    name: 'foo'
                },
                parentRecord
            });
            (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.CollectionRecordProvider, {
                record: record,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {})
            }));
            expect(client_namespaceObject.screen.getByTestId('content')).toHaveTextContent(JSON.stringify({
                id: 1,
                role: 'admin'
            }));
        });
    });
});
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
});
