@@ -18,6 +18,42 @@ const uischema = {
18
18
} ,
19
19
} ;
20
20
21
+ const schemaWithNameAndRate = {
22
+ type : 'array' ,
23
+ title : 'My Array' ,
24
+ maxItems : 3 ,
25
+ minItems : 1 ,
26
+ items : {
27
+ type : 'object' ,
28
+ properties : {
29
+ name : {
30
+ type : 'string' ,
31
+ } ,
32
+ rate : {
33
+ type : 'number' ,
34
+ } ,
35
+ } ,
36
+ } ,
37
+ } ;
38
+
39
+ const schemaWithCountAndName = {
40
+ type : 'array' ,
41
+ title : 'My Array' ,
42
+ maxItems : 3 ,
43
+ minItems : 1 ,
44
+ items : {
45
+ type : 'object' ,
46
+ properties : {
47
+ count : {
48
+ type : 'number' ,
49
+ } ,
50
+ name : {
51
+ type : 'string' ,
52
+ } ,
53
+ } ,
54
+ } ,
55
+ } ;
56
+
21
57
describe ( 'ArrayListRenderer.vue' , ( ) => {
22
58
it ( 'renders a fieldset' , ( ) => {
23
59
const wrapper = mountJsonForms ( [ 'a' ] , schema , uischema ) ;
@@ -88,4 +124,44 @@ describe('ArrayListRenderer.vue', () => {
88
124
expect ( type ) . to . equal ( 'button' ) ;
89
125
}
90
126
} ) ;
127
+
128
+ it ( 'compute default label' , async ( ) => {
129
+ const wrapper = mountJsonForms (
130
+ [ { name : 'name1' , rate : 5 } ] ,
131
+ schemaWithNameAndRate ,
132
+ uischema
133
+ ) ;
134
+ const labels = wrapper . findAll ( '.array-list-item-label' ) ;
135
+ const labelText = labels [ 0 ] . text ( ) ;
136
+ expect ( labelText ) . to . equal ( 'name1' ) ;
137
+ } ) ;
138
+
139
+ it ( 'compute default label with undefined' , async ( ) => {
140
+ const wrapper = mountJsonForms ( [ { } ] , schemaWithNameAndRate , uischema ) ;
141
+ const labels = wrapper . findAll ( '.array-list-item-label' ) ;
142
+ const labelText = labels [ 0 ] . text ( ) ;
143
+ expect ( labelText ) . to . equal ( '' ) ;
144
+ } ) ;
145
+
146
+ it ( 'compute default label with number' , async ( ) => {
147
+ const wrapper = mountJsonForms (
148
+ [ { count : 1 , name : 'name1' } ] ,
149
+ schemaWithCountAndName ,
150
+ uischema
151
+ ) ;
152
+ const labels = wrapper . findAll ( '.array-list-item-label' ) ;
153
+ const labelText = labels [ 0 ] . text ( ) ;
154
+ expect ( labelText ) . to . equal ( '1' ) ;
155
+ } ) ;
156
+
157
+ it ( 'compute default label with NaN' , async ( ) => {
158
+ const wrapper = mountJsonForms (
159
+ [ { count : Number ( undefined ) , name : 'name1' } ] ,
160
+ schemaWithCountAndName ,
161
+ uischema
162
+ ) ;
163
+ const labels = wrapper . findAll ( '.array-list-item-label' ) ;
164
+ const labelText = labels [ 0 ] . text ( ) ;
165
+ expect ( labelText ) . to . equal ( '' ) ;
166
+ } ) ;
91
167
} ) ;
0 commit comments