npm package diff

Package: @forge/react

Versions: 10.10.0 - 10.10.1-next.0

File: package/out/__test__/components/dynamic-table.test.js

Index: package/out/__test__/components/dynamic-table.test.js
===================================================================
--- package/out/__test__/components/dynamic-table.test.js
+++ package/out/__test__/components/dynamic-table.test.js
@@ -0,0 +1,88 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const tslib_1 = require("tslib");
+const jsx_runtime_1 = require("react/jsx-runtime");
+const react_1 = tslib_1.__importDefault(require("react"));
+const components_1 = require("../../components");
+const reconcilerTestRenderer_1 = tslib_1.__importDefault(require("../reconcilerTestRenderer"));
+const testUtils_1 = require("../testUtils");
+const get_1 = tslib_1.__importDefault(require("lodash/get"));
+describe('DynamicTable', () => {
+    let bridgeCalls = [];
+    beforeEach(async () => {
+        bridgeCalls = (0, testUtils_1.setupBridge)();
+        const Test = () => {
+            const head = {
+                cells: [
+                    {
+                        key: 'head-1',
+                        content: 'Name',
+                        colSpan: 2
+                    },
+                    {
+                        key: 'head-2',
+                        content: 'Category'
+                    }
+                ]
+            };
+            const rows = [
+                {
+                    key: 'row-1',
+                    cells: [
+                        {
+                            key: 'cell-1-1',
+                            content: 'Hello world',
+                            colSpan: 2
+                        },
+                        {
+                            key: 'cell-1-2',
+                            content: (0, jsx_runtime_1.jsx)(components_1.Textfield, { name: "textfield" })
+                        }
+                    ]
+                },
+                {
+                    key: 'row-2',
+                    cells: [
+                        {
+                            key: 'cell-2-1',
+                            content: 'Bar',
+                            colSpan: 2
+                        },
+                        {
+                            key: 'cell-2-2',
+                            content: 'Foo'
+                        }
+                    ]
+                }
+            ];
+            return ((0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: (0, jsx_runtime_1.jsx)(components_1.DynamicTable, { head: head, rows: rows }) }));
+        };
+        await reconcilerTestRenderer_1.default.create((0, jsx_runtime_1.jsx)(Test, {}));
+    });
+    it('should convert the head prop to head children in forgeDoc', () => {
+        const forgeDoc = (0, testUtils_1.getLastBridgeCallForgeDoc)(bridgeCalls);
+        const headWrapper = (0, get_1.default)(forgeDoc, 'children[0].children[0]');
+        const firstCellComponent = (0, get_1.default)(headWrapper, 'children[0].type');
+        const firstCellContent = (0, get_1.default)(headWrapper, 'children[0].children[0].props.text');
+        const firstCellKey = (0, get_1.default)(headWrapper, 'children[0].props.cellKey');
+        const firstColSpan = (0, get_1.default)(headWrapper, 'children[0].props.colSpan');
+        expect(firstCellComponent).toBe('Cell');
+        expect(firstCellContent).toBe('Name');
+        expect(firstCellKey).toBe('head-1');
+        expect(firstColSpan).toBe(2);
+    });
+    it('should convert the rows prop to row children in forgeDoc', () => {
+        const forgeDoc = (0, testUtils_1.getLastBridgeCallForgeDoc)(bridgeCalls);
+        const rowsWrapper = (0, get_1.default)(forgeDoc, 'children[0].children[1]');
+        const firstRowComponent = (0, get_1.default)(rowsWrapper, 'children[0].type');
+        const firstRowKey = (0, get_1.default)(rowsWrapper, 'children[0].props.rowKey');
+        const firstCellComponent = (0, get_1.default)(rowsWrapper, 'children[0].children[0].type');
+        const firstCellContent = (0, get_1.default)(rowsWrapper, 'children[0].children[0].children[0].props.text');
+        const secondCellContent = (0, get_1.default)(rowsWrapper, 'children[0].children[1].children[0].type');
+        expect(firstRowComponent).toBe('Row');
+        expect(firstRowKey).toBe('row-1');
+        expect(firstCellComponent).toBe('Cell');
+        expect(firstCellContent).toBe('Hello world');
+        expect(secondCellContent).toBe('Textfield');
+    });
+});