From db02990d2991e0f615457f09a282bdf16cdaafa1 Mon Sep 17 00:00:00 2001 From: mikekotikov Date: Fri, 20 Dec 2024 10:58:14 +0300 Subject: [PATCH 1/2] FIO-9467: Fix rendering table component in wizard --- .../formUtil/__tests__/eachComponent.test.ts | 648 +----------------- src/utils/formUtil/eachComponent.ts | 3 +- src/utils/formUtil/fixtures/components.js | 92 +++ src/utils/formUtil/fixtures/components2.js | 512 ++++++++++++++ src/utils/formUtil/fixtures/components3.js | 29 + src/utils/formUtil/fixtures/index.js | 5 + .../fixtures/tableInsideWizardComponents.js | 68 ++ 7 files changed, 723 insertions(+), 634 deletions(-) create mode 100644 src/utils/formUtil/fixtures/components.js create mode 100644 src/utils/formUtil/fixtures/components2.js create mode 100644 src/utils/formUtil/fixtures/components3.js create mode 100644 src/utils/formUtil/fixtures/index.js create mode 100644 src/utils/formUtil/fixtures/tableInsideWizardComponents.js diff --git a/src/utils/formUtil/__tests__/eachComponent.test.ts b/src/utils/formUtil/__tests__/eachComponent.test.ts index d5446490..dbbfb46e 100644 --- a/src/utils/formUtil/__tests__/eachComponent.test.ts +++ b/src/utils/formUtil/__tests__/eachComponent.test.ts @@ -1,4 +1,5 @@ import { expect } from 'chai'; +import {components, components2, components3, tableInsideWizardComp} from '../fixtures' import { eachComponent } from '../eachComponent'; import { isLayoutComponent } from '../index'; @@ -6,639 +7,6 @@ import { isLayoutComponent } from '../index'; import { Component, TableComponent, HasChildComponents } from 'types'; describe('eachComponent', function () { - const components = [ - { - type: 'textfield', - key: 'one', - order: 1, - input: true, - }, - { - input: false, - key: 'parent1', - components: [ - { - type: 'textfield', - key: 'two', - order: 2, - }, - { - input: false, - key: 'parent2', - columns: [ - { - components: [ - { - type: 'textfield', - key: 'three', - order: 3, - }, - ], - }, - { - components: [ - { - rows: [ - [ - { - components: [ - { - key: 'four', - order: 4, - type: 'textfield', - }, - ], - }, - { - components: [ - { - key: 'five', - order: 5, - type: 'textfield', - }, - ], - }, - ], - [ - { - components: [ - { - key: 'six', - order: 6, - type: 'textfield', - }, - ], - }, - { - components: [ - { - key: 'seven', - order: 7, - type: 'textarea', - rows: 3, - }, - ], - }, - ], - ], - type: 'table', - }, - ], - }, - ], - type: 'columns', - }, - ], - type: 'well', - }, - { - key: 'eight', - order: 8, - type: 'button', - input: true, - }, - ]; - const components2 = [ - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'a', - label: 'A', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - { - lockKey: true, - key: 'b', - conditional: { - eq: '', - when: null, - show: null, - }, - type: 'fieldset', - components: [ - { - lockKey: true, - key: 'c', - conditional: { - eq: '', - when: null, - show: null, - }, - type: 'columns', - columns: [ - { - components: [ - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'd', - label: 'D', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - { - conditional: { - eq: '', - when: null, - show: null, - }, - type: 'container', - persistent: true, - protected: false, - key: 'f', - label: 'F', - tableView: true, - components: [ - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'g', - label: 'G', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'h', - label: 'H', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'i', - label: 'I', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - ], - tree: true, - input: true, - }, - ], - }, - { - components: [ - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'e', - label: 'E', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - ], - }, - ], - input: false, - }, - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'j', - label: 'J', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - ], - legend: 'B', - tableView: true, - input: false, - }, - { - conditional: { - eq: '', - when: null, - show: null, - }, - type: 'datagrid', - persistent: true, - protected: false, - key: 'k', - label: 'K', - tableView: true, - components: [ - { - conditional: { - eq: '', - when: null, - show: null, - }, - hideLabel: true, - type: 'container', - persistent: true, - protected: false, - key: 'n', - label: 'N', - tableView: true, - components: [ - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'o', - label: 'O', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'p', - label: 'P', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'q', - label: 'Q', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - ], - tree: true, - input: true, - }, - { - hideLabel: true, - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'm', - label: 'M', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - { - hideLabel: true, - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'l', - label: 'L', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - ], - tree: true, - input: true, - }, - { - type: 'textfield', - conditional: { - eq: '', - when: null, - show: null, - }, - validate: { - customPrivate: false, - custom: '', - pattern: '', - maxLength: '', - minLength: '', - required: false, - }, - persistent: true, - unique: false, - protected: false, - defaultValue: '', - multiple: false, - suffix: '', - prefix: '', - placeholder: '', - key: 'r', - label: 'R', - inputMask: '', - inputType: 'text', - tableView: true, - input: true, - }, - { - type: 'button', - theme: 'primary', - disableOnInvalid: true, - action: 'submit', - block: false, - rightIcon: '', - leftIcon: '', - size: 'md', - key: 'submit', - tableView: false, - label: 'Submit', - input: true, - }, - { - label: 'Tagpad', - tableView: false, - key: 'tagpad', - type: 'tagpad', - input: true, - components: [ - { - label: 'Text Field', - tableView: true, - key: 'a', - type: 'textfield', - input: true, - }, - ], - }, - ]; - const components3 = [ - { - label: 'HTML', - tag: 'p', - content: '', - key: 'html', - type: 'htmlelement', - input: false, - }, - { - html: '

some text

', - label: 'Content', - key: 'content', - type: 'content', - input: false, - }, - { - label: 'Text Field', - key: 'textField', - type: 'textfield', - input: true, - }, - { - label: 'Number', - key: 'number', - type: 'number', - input: true, - }, - ]; it('should iterate through nested components in the right order', function () { let n = 1; @@ -1082,4 +450,18 @@ describe('eachComponent', function () { }, ); }); + + it('should iterate through table components inside wizard form', function () { + let isExistUrlComponentInTable; + eachComponent( + tableInsideWizardComp, + (component: Component) => { + if (component.key === 'url1') { + isExistUrlComponentInTable = true; + } + }, + true, + ); + expect(isExistUrlComponentInTable).to.be.equal(true); + }); }); diff --git a/src/utils/formUtil/eachComponent.ts b/src/utils/formUtil/eachComponent.ts index e46ec4ea..081e56f9 100644 --- a/src/utils/formUtil/eachComponent.ts +++ b/src/utils/formUtil/eachComponent.ts @@ -43,7 +43,8 @@ export function eachComponent( eachComponent(column.components, fn, includeAll, compPaths, component), ); } else if (info.hasRows) { - component.rows.forEach((row: any) => { + const comp = component.component || component; + comp.rows.forEach((row: any) => { if (Array.isArray(row)) { row.forEach((column) => eachComponent(column.components, fn, includeAll, compPaths, component), diff --git a/src/utils/formUtil/fixtures/components.js b/src/utils/formUtil/fixtures/components.js new file mode 100644 index 00000000..ccba3148 --- /dev/null +++ b/src/utils/formUtil/fixtures/components.js @@ -0,0 +1,92 @@ +export default [ + { + type: 'textfield', + key: 'one', + order: 1, + input: true, + }, + { + input: false, + key: 'parent1', + components: [ + { + type: 'textfield', + key: 'two', + order: 2, + }, + { + input: false, + key: 'parent2', + columns: [ + { + components: [ + { + type: 'textfield', + key: 'three', + order: 3, + }, + ], + }, + { + components: [ + { + rows: [ + [ + { + components: [ + { + key: 'four', + order: 4, + type: 'textfield', + }, + ], + }, + { + components: [ + { + key: 'five', + order: 5, + type: 'textfield', + }, + ], + }, + ], + [ + { + components: [ + { + key: 'six', + order: 6, + type: 'textfield', + }, + ], + }, + { + components: [ + { + key: 'seven', + order: 7, + type: 'textarea', + rows: 3, + }, + ], + }, + ], + ], + type: 'table', + }, + ], + }, + ], + type: 'columns', + }, + ], + type: 'well', + }, + { + key: 'eight', + order: 8, + type: 'button', + input: true, + }, +]; \ No newline at end of file diff --git a/src/utils/formUtil/fixtures/components2.js b/src/utils/formUtil/fixtures/components2.js new file mode 100644 index 00000000..07461e35 --- /dev/null +++ b/src/utils/formUtil/fixtures/components2.js @@ -0,0 +1,512 @@ +export default [ + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'a', + label: 'A', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + { + lockKey: true, + key: 'b', + conditional: { + eq: '', + when: null, + show: null, + }, + type: 'fieldset', + components: [ + { + lockKey: true, + key: 'c', + conditional: { + eq: '', + when: null, + show: null, + }, + type: 'columns', + columns: [ + { + components: [ + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'd', + label: 'D', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + { + conditional: { + eq: '', + when: null, + show: null, + }, + type: 'container', + persistent: true, + protected: false, + key: 'f', + label: 'F', + tableView: true, + components: [ + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'g', + label: 'G', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'h', + label: 'H', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'i', + label: 'I', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + ], + tree: true, + input: true, + }, + ], + }, + { + components: [ + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'e', + label: 'E', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + ], + }, + ], + input: false, + }, + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'j', + label: 'J', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + ], + legend: 'B', + tableView: true, + input: false, + }, + { + conditional: { + eq: '', + when: null, + show: null, + }, + type: 'datagrid', + persistent: true, + protected: false, + key: 'k', + label: 'K', + tableView: true, + components: [ + { + conditional: { + eq: '', + when: null, + show: null, + }, + hideLabel: true, + type: 'container', + persistent: true, + protected: false, + key: 'n', + label: 'N', + tableView: true, + components: [ + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'o', + label: 'O', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'p', + label: 'P', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'q', + label: 'Q', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + ], + tree: true, + input: true, + }, + { + hideLabel: true, + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'm', + label: 'M', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + { + hideLabel: true, + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'l', + label: 'L', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + ], + tree: true, + input: true, + }, + { + type: 'textfield', + conditional: { + eq: '', + when: null, + show: null, + }, + validate: { + customPrivate: false, + custom: '', + pattern: '', + maxLength: '', + minLength: '', + required: false, + }, + persistent: true, + unique: false, + protected: false, + defaultValue: '', + multiple: false, + suffix: '', + prefix: '', + placeholder: '', + key: 'r', + label: 'R', + inputMask: '', + inputType: 'text', + tableView: true, + input: true, + }, + { + type: 'button', + theme: 'primary', + disableOnInvalid: true, + action: 'submit', + block: false, + rightIcon: '', + leftIcon: '', + size: 'md', + key: 'submit', + tableView: false, + label: 'Submit', + input: true, + }, + { + label: 'Tagpad', + tableView: false, + key: 'tagpad', + type: 'tagpad', + input: true, + components: [ + { + label: 'Text Field', + tableView: true, + key: 'a', + type: 'textfield', + input: true, + }, + ], + }, +]; \ No newline at end of file diff --git a/src/utils/formUtil/fixtures/components3.js b/src/utils/formUtil/fixtures/components3.js new file mode 100644 index 00000000..9610021d --- /dev/null +++ b/src/utils/formUtil/fixtures/components3.js @@ -0,0 +1,29 @@ +export default [ + { + label: 'HTML', + tag: 'p', + content: '', + key: 'html', + type: 'htmlelement', + input: false, + }, + { + html: '

some text

', + label: 'Content', + key: 'content', + type: 'content', + input: false, + }, + { + label: 'Text Field', + key: 'textField', + type: 'textfield', + input: true, + }, + { + label: 'Number', + key: 'number', + type: 'number', + input: true, + }, +] diff --git a/src/utils/formUtil/fixtures/index.js b/src/utils/formUtil/fixtures/index.js new file mode 100644 index 00000000..236266cc --- /dev/null +++ b/src/utils/formUtil/fixtures/index.js @@ -0,0 +1,5 @@ +import tableInsideWizardComp from './tableInsideWizardComponents'; +import components from './components'; +import components2 from './components2'; +import components3 from './components3'; +export { tableInsideWizardComp, components, components2, components3 }; diff --git a/src/utils/formUtil/fixtures/tableInsideWizardComponents.js b/src/utils/formUtil/fixtures/tableInsideWizardComponents.js new file mode 100644 index 00000000..b6fe5547 --- /dev/null +++ b/src/utils/formUtil/fixtures/tableInsideWizardComponents.js @@ -0,0 +1,68 @@ +export default [ + { + title: "Page 1", + breadcrumbClickable: false, + buttonSettings: { + previous: true, + cancel: true, + next: true + }, + + key: "page1", + type: "panel", + label: "Page 1", + tableView: false, + components: [ + { + label: "Text Field", + tableView: true, + key: "textField", + type: "textfield", + input: true + }, + ], + input: false, + allowPrevious: false + }, + { + title: "Page 2", + breadcrumbClickable: false, + buttonSettings: { + previous: true, + cancel: true, + next: true + }, + key: "page2", + type: "panel", + label: "Page 2", + allowPrevious: false, + input: false, + tableView: false, + components: [ + { + label: "Component", + cellAlignment: "left", + key: "table", + type: "components", + component: { + type: "table", + rows: [ + [ + { + components: [ + { + label: "Url", + tableView: true, + key: "url1", + type: "url", + input: true + } + ] + }, + ] + ] + } + } + ] + }, +] \ No newline at end of file From e1f4d0a3a5c9b94b8120956401f225f5a3d66c20 Mon Sep 17 00:00:00 2001 From: mikekotikov Date: Tue, 7 Jan 2025 18:39:45 +0100 Subject: [PATCH 2/2] FIO-9467: rename fixture files --- .../formUtil/__tests__/eachComponent.test.ts | 28 +++++++++++-------- src/utils/formUtil/fixtures/index.js | 13 ++++++--- ...ts3.js => mixedLayoutAndDataComponents.js} | 2 +- ...nents2.js => nestedArrayDataComponents.js} | 2 +- ... => textFieldsNestedInLayoutComponents.js} | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) rename src/utils/formUtil/fixtures/{components3.js => mixedLayoutAndDataComponents.js} (99%) rename src/utils/formUtil/fixtures/{components2.js => nestedArrayDataComponents.js} (99%) rename src/utils/formUtil/fixtures/{components.js => textFieldsNestedInLayoutComponents.js} (99%) diff --git a/src/utils/formUtil/__tests__/eachComponent.test.ts b/src/utils/formUtil/__tests__/eachComponent.test.ts index dbbfb46e..4cb86fea 100644 --- a/src/utils/formUtil/__tests__/eachComponent.test.ts +++ b/src/utils/formUtil/__tests__/eachComponent.test.ts @@ -1,5 +1,10 @@ import { expect } from 'chai'; -import {components, components2, components3, tableInsideWizardComp} from '../fixtures' +import { + textFieldsNestedInLayoutComponents, + nestedArrayDataComponents, + mixedLayoutAndDataComponents, + tableInsideWizardComp, +} from '../fixtures'; import { eachComponent } from '../eachComponent'; import { isLayoutComponent } from '../index'; @@ -7,10 +12,9 @@ import { isLayoutComponent } from '../index'; import { Component, TableComponent, HasChildComponents } from 'types'; describe('eachComponent', function () { - it('should iterate through nested components in the right order', function () { let n = 1; - eachComponent(components, (component: Component) => { + eachComponent(textFieldsNestedInLayoutComponents, (component: Component) => { expect((component as any).order).to.equal(n); n += 1; }); @@ -20,7 +24,7 @@ describe('eachComponent', function () { let numComps = 0; let numLayout = 0; eachComponent( - components, + textFieldsNestedInLayoutComponents, (component: Component) => { if (isLayoutComponent(component)) { numLayout++; @@ -50,7 +54,7 @@ describe('eachComponent', function () { ]; const testPaths: string[] = []; eachComponent( - components, + textFieldsNestedInLayoutComponents, (component: Component, path: string) => { testPaths.push(path); }, @@ -292,7 +296,7 @@ describe('eachComponent', function () { ]; const testPaths: string[] = []; eachComponent( - components2, + nestedArrayDataComponents, (component: Component, path: string) => { testPaths.push(path); }, @@ -324,7 +328,7 @@ describe('eachComponent', function () { 'tagpad.a', ]; const testPaths: string[] = []; - eachComponent(components2, (component: Component, path: string) => { + eachComponent(nestedArrayDataComponents, (component: Component, path: string) => { testPaths.push(path); }); expect(paths).to.deep.equal(testPaths); @@ -334,7 +338,7 @@ describe('eachComponent', function () { let numComps = 0; let numLayout = 0; eachComponent( - components, + textFieldsNestedInLayoutComponents, (component: Component) => { if (isLayoutComponent(component)) { numLayout++; @@ -364,7 +368,7 @@ describe('eachComponent', function () { it('should not include `htmlelement` components when `includeAll` is not provided', function () { let htmlComponentsAmount = 0; - eachComponent(components3, (component: Component) => { + eachComponent(mixedLayoutAndDataComponents, (component: Component) => { if (component.type === 'htmlelement') { htmlComponentsAmount++; } @@ -375,7 +379,7 @@ describe('eachComponent', function () { it('should include `htmlelement` components when `includeAll` is provided', function () { let htmlComponentsAmount = 0; eachComponent( - components3, + mixedLayoutAndDataComponents, (component: Component) => { if (component.type === 'htmlelement') { htmlComponentsAmount++; @@ -388,7 +392,7 @@ describe('eachComponent', function () { it('should not include `content` components when `includeAll` is not provided', function () { let contentComponentsAmount = 0; - eachComponent(components3, (component: Component) => { + eachComponent(mixedLayoutAndDataComponents, (component: Component) => { if (component.type === 'content') { contentComponentsAmount++; } @@ -399,7 +403,7 @@ describe('eachComponent', function () { it('should include `content` components when `includeAll` is provided', function () { let contentComponentsAmount = 0; eachComponent( - components3, + mixedLayoutAndDataComponents, (component: Component) => { if (component.type === 'content') { contentComponentsAmount++; diff --git a/src/utils/formUtil/fixtures/index.js b/src/utils/formUtil/fixtures/index.js index 236266cc..b671296b 100644 --- a/src/utils/formUtil/fixtures/index.js +++ b/src/utils/formUtil/fixtures/index.js @@ -1,5 +1,10 @@ import tableInsideWizardComp from './tableInsideWizardComponents'; -import components from './components'; -import components2 from './components2'; -import components3 from './components3'; -export { tableInsideWizardComp, components, components2, components3 }; +import textFieldsNestedInLayoutComponents from './textFieldsNestedInLayoutComponents'; +import nestedArrayDataComponents from './nestedArrayDataComponents'; +import mixedLayoutAndDataComponents from './mixedLayoutAndDataComponents'; +export { + tableInsideWizardComp, + textFieldsNestedInLayoutComponents, + nestedArrayDataComponents, + mixedLayoutAndDataComponents, +}; diff --git a/src/utils/formUtil/fixtures/components3.js b/src/utils/formUtil/fixtures/mixedLayoutAndDataComponents.js similarity index 99% rename from src/utils/formUtil/fixtures/components3.js rename to src/utils/formUtil/fixtures/mixedLayoutAndDataComponents.js index 9610021d..884dec62 100644 --- a/src/utils/formUtil/fixtures/components3.js +++ b/src/utils/formUtil/fixtures/mixedLayoutAndDataComponents.js @@ -26,4 +26,4 @@ export default [ type: 'number', input: true, }, -] +]; diff --git a/src/utils/formUtil/fixtures/components2.js b/src/utils/formUtil/fixtures/nestedArrayDataComponents.js similarity index 99% rename from src/utils/formUtil/fixtures/components2.js rename to src/utils/formUtil/fixtures/nestedArrayDataComponents.js index 07461e35..f0b099c8 100644 --- a/src/utils/formUtil/fixtures/components2.js +++ b/src/utils/formUtil/fixtures/nestedArrayDataComponents.js @@ -509,4 +509,4 @@ export default [ }, ], }, -]; \ No newline at end of file +]; diff --git a/src/utils/formUtil/fixtures/components.js b/src/utils/formUtil/fixtures/textFieldsNestedInLayoutComponents.js similarity index 99% rename from src/utils/formUtil/fixtures/components.js rename to src/utils/formUtil/fixtures/textFieldsNestedInLayoutComponents.js index ccba3148..15e5493a 100644 --- a/src/utils/formUtil/fixtures/components.js +++ b/src/utils/formUtil/fixtures/textFieldsNestedInLayoutComponents.js @@ -89,4 +89,4 @@ export default [ type: 'button', input: true, }, -]; \ No newline at end of file +];