@@ -74,6 +74,122 @@ describe('formUtil', function () {
7474 expect ( component ?. key ) . to . equal ( writtenNumber ( n ) ) ;
7575 }
7676 } ) ;
77+
78+ it ( 'Should return correct component when the form has 2 components with the same key' , function ( ) {
79+ const component = getComponent (
80+ [
81+ {
82+ label : 'Tabs' ,
83+ components : [
84+ {
85+ label : 'Tab1' ,
86+ key : 'tab1' ,
87+ components : [
88+ {
89+ label : 'Text Field' ,
90+ tableView : true ,
91+ validateWhenHidden : false ,
92+ key : 'someDuplicatedKey' ,
93+ type : 'textfield' ,
94+ input : true ,
95+ } ,
96+ ] ,
97+ } ,
98+ {
99+ label : 'Tab2' ,
100+ key : 'tab2' ,
101+ components : [
102+ {
103+ label : 'Another container' ,
104+ tableView : false ,
105+ key : 'anotherContainerKey' ,
106+ type : 'container' ,
107+ input : true ,
108+ components : [
109+ {
110+ label :
111+ "A select with the same key of a container in tab1. Select the option 'more'" ,
112+ widget : 'choicesjs' ,
113+ tableView : true ,
114+ data : {
115+ values : [
116+ {
117+ label : 'less' ,
118+ value : 'less' ,
119+ } ,
120+ {
121+ label : 'more' ,
122+ value : 'more' ,
123+ } ,
124+ ] ,
125+ } ,
126+ validateWhenHidden : false ,
127+ key : 'someDuplicatedKey' ,
128+ type : 'select' ,
129+ input : true ,
130+ } ,
131+ {
132+ label : 'Here select yes, value will disappear' ,
133+ tableView : false ,
134+ validateWhenHidden : false ,
135+ key : 'additionalContainer' ,
136+ conditional : {
137+ show : true ,
138+ conjunction : 'all' ,
139+ conditions : [
140+ {
141+ component : 'someDuplicatedKey' ,
142+ operator : 'isEqual' ,
143+ value : 'more' ,
144+ } ,
145+ ] ,
146+ } ,
147+ type : 'container' ,
148+ input : true ,
149+ components : [
150+ {
151+ label : 'Select yes here, the value will disappear upon save' ,
152+ labelPosition : 'left-left' ,
153+ optionsLabelPosition : 'right' ,
154+ inline : true ,
155+ tableView : false ,
156+ values : [
157+ {
158+ label : 'yes' ,
159+ value : 'yes' ,
160+ shortcut : '' ,
161+ } ,
162+ {
163+ label : 'no' ,
164+ value : 'no' ,
165+ shortcut : '' ,
166+ } ,
167+ ] ,
168+ validateWhenHidden : false ,
169+ key : 'aradiobutton' ,
170+ type : 'radio' ,
171+ input : true ,
172+ } ,
173+ ] ,
174+ } ,
175+ ] ,
176+ } ,
177+ ] ,
178+ } ,
179+ ] ,
180+ key : 'tabs' ,
181+ type : 'tabs' ,
182+ input : false ,
183+ tableView : false ,
184+ } ,
185+ ] ,
186+ 'someDuplicatedKey' ,
187+ ) ;
188+ expect ( component ) . not . to . equal ( null ) ;
189+ expect ( component ) . not . to . equal ( undefined ) ;
190+ expect ( component ) . to . be . an ( 'object' ) ;
191+ expect ( ( component as any ) . type ) . to . equal ( 'textfield' ) ;
192+ } ) ;
77193 } ) ;
78194
79195 describe ( 'flattenComponents' , function ( ) {
0 commit comments