File tree Expand file tree Collapse file tree 1 file changed +72
-0
lines changed
src/utils/formUtil/__tests__ Expand file tree Collapse file tree 1 file changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { expect } from 'chai' ;
2
+
3
+ import { eachComponentData } from '../eachComponentData' ;
4
+
5
+ describe ( 'eachComponentData' , function ( ) {
6
+ it ( 'Should not iterate over each component in a nested component if includeAll=false and there is no data associated with the component' , function ( ) {
7
+ const components = [
8
+ {
9
+ type : 'datagrid' ,
10
+ key : 'dataGrid' ,
11
+ label : 'Data Grid' ,
12
+ input : true ,
13
+ components : [
14
+ {
15
+ key : 'textField' ,
16
+ type : 'textfield' ,
17
+ label : 'Text Field' ,
18
+ input : true ,
19
+ } ,
20
+ ] ,
21
+ } ,
22
+ ] ;
23
+
24
+ const data = { } ;
25
+
26
+ const rowResults : Map < string , any > = new Map ( ) ;
27
+ eachComponentData (
28
+ components ,
29
+ data ,
30
+ ( component , data , row , path ) => {
31
+ rowResults . set ( path , component . key ) ;
32
+ } ,
33
+ false ,
34
+ ) ;
35
+ expect ( rowResults . size ) . to . equal ( 1 ) ;
36
+ expect ( rowResults . get ( 'dataGrid' ) ) . to . deep . equal ( 'dataGrid' ) ;
37
+ } ) ;
38
+
39
+ it ( 'Should iterate over each component in a nested component if includeAll=true and there is no data associated with the component' , function ( ) {
40
+ const components = [
41
+ {
42
+ type : 'datagrid' ,
43
+ key : 'dataGrid' ,
44
+ label : 'Data Grid' ,
45
+ input : true ,
46
+ components : [
47
+ {
48
+ key : 'textField' ,
49
+ type : 'textfield' ,
50
+ label : 'Text Field' ,
51
+ input : true ,
52
+ } ,
53
+ ] ,
54
+ } ,
55
+ ] ;
56
+
57
+ const data = { } ;
58
+
59
+ const rowResults : Map < string , any > = new Map ( ) ;
60
+ eachComponentData (
61
+ components ,
62
+ data ,
63
+ ( component , data , row , path ) => {
64
+ rowResults . set ( path , component . key ) ;
65
+ } ,
66
+ true ,
67
+ ) ;
68
+ expect ( rowResults . size ) . to . equal ( 2 ) ;
69
+ expect ( rowResults . get ( 'dataGrid' ) ) . to . deep . equal ( 'dataGrid' ) ;
70
+ expect ( rowResults . get ( 'dataGrid[0].textField' ) ) . to . deep . equal ( 'textField' ) ;
71
+ } ) ;
72
+ } ) ;
You can’t perform that action at this time.
0 commit comments