@@ -192,73 +192,77 @@ describe("ArrayField", () => {
192
192
value : [ "foo" , "fuzz" ]
193
193
} ;
194
194
195
- it ( "should be possible to specify a custom widget" , ( ) => {
196
- const uiSchema = {
197
- "ui:widget" : "checkboxes"
198
- } ;
199
- const { node} = createFormComponent ( { schema, uiSchema} ) ;
200
- d ( node ) ;
195
+ describe ( "Select multiple widget" , ( ) => {
196
+ it ( "should render a select widget" , ( ) => {
197
+ const { node} = createFormComponent ( { schema} ) ;
201
198
202
- expect ( node . querySelectorAll ( "select" ) )
203
- . to . have . length . of ( 1 ) ;
204
- } ) ;
199
+ expect ( node . querySelectorAll ( "select" ) )
200
+ . to . have . length . of ( 1 ) ;
201
+ } ) ;
205
202
206
- it ( "should render a select widget" , ( ) => {
207
- const { node} = createFormComponent ( { schema} ) ;
203
+ it ( "should render a select widget with a label " , ( ) => {
204
+ const { node} = createFormComponent ( { schema} ) ;
208
205
209
- expect ( node . querySelectorAll ( "select" ) )
210
- . to . have . length . of ( 1 ) ;
211
- } ) ;
206
+ expect ( node . querySelector ( ".field label" ) . textContent )
207
+ . eql ( "My field" ) ;
208
+ } ) ;
212
209
213
- it ( "should render a select widget with a label " , ( ) => {
214
- const { node} = createFormComponent ( { schema} ) ;
210
+ it ( "should render a select widget with multiple attribute " , ( ) => {
211
+ const { node} = createFormComponent ( { schema} ) ;
215
212
216
- expect ( node . querySelector ( ".field label" ) . textContent )
217
- . eql ( "My field" ) ;
218
- } ) ;
219
-
220
- it ( "should render a select widget with multiple attribute" , ( ) => {
221
- const { node} = createFormComponent ( { schema} ) ;
213
+ expect ( node . querySelector ( ".field select" ) . getAttribute ( "multiple" ) )
214
+ . not . to . be . null ;
215
+ } ) ;
222
216
223
- expect ( node . querySelector ( ".field select" ) . getAttribute ( "multiple" ) )
224
- . not . to . be . null ;
225
- } ) ;
217
+ it ( "should render options" , ( ) => {
218
+ const { node} = createFormComponent ( { schema} ) ;
226
219
227
- it ( "should render options" , ( ) => {
228
- const { node} = createFormComponent ( { schema} ) ;
220
+ expect ( node . querySelectorAll ( "select option" ) )
221
+ . to . have . length . of ( 3 ) ;
222
+ } ) ;
229
223
230
- expect ( node . querySelectorAll ( "select option" ) )
231
- . to . have . length . of ( 3 ) ;
232
- } ) ;
224
+ it ( "should handle a change event" , ( ) => {
225
+ const { comp, node} = createFormComponent ( { schema} ) ;
233
226
234
- it ( "should handle a change event" , ( ) => {
235
- const { comp, node} = createFormComponent ( { schema} ) ;
227
+ Simulate . change ( node . querySelector ( ".field select" ) , {
228
+ target : { options : [
229
+ { selected : true , value : "foo" } ,
230
+ { selected : true , value : "bar" } ,
231
+ { selected : false , value : "fuzz" } ,
232
+ ] }
233
+ } ) ;
236
234
237
- Simulate . change ( node . querySelector ( ".field select" ) , {
238
- target : { options : [
239
- { selected : true , value : "foo" } ,
240
- { selected : true , value : "bar" } ,
241
- { selected : false , value : "fuzz" } ,
242
- ] }
235
+ expect ( comp . state . formData ) . eql ( [ "foo" , "bar" ] ) ;
243
236
} ) ;
244
237
245
- expect ( comp . state . formData ) . eql ( [ "foo ", "bar" ] ) ;
246
- } ) ;
238
+ it ( "should fill field with data ", ( ) => {
239
+ const { node } = createFormComponent ( { schema , formData : [ "foo" , "bar" ] } ) ;
247
240
248
- it ( "should fill field with data" , ( ) => {
249
- const { node} = createFormComponent ( { schema, formData : [ "foo" , "bar" ] } ) ;
241
+ const options = node . querySelectorAll ( ".field select option" ) ;
242
+ expect ( options ) . to . have . length . of ( 3 ) ;
243
+ expect ( options [ 0 ] . selected ) . eql ( true ) ; // foo
244
+ expect ( options [ 1 ] . selected ) . eql ( true ) ; // bar
245
+ expect ( options [ 2 ] . selected ) . eql ( false ) ; // fuzz
246
+ } ) ;
247
+
248
+ it ( "should render the select widget with the expected id" , ( ) => {
249
+ const { node} = createFormComponent ( { schema} ) ;
250
250
251
- const options = node . querySelectorAll ( ".field select option" ) ;
252
- expect ( options ) . to . have . length . of ( 3 ) ;
253
- expect ( options [ 0 ] . selected ) . eql ( true ) ; // foo
254
- expect ( options [ 1 ] . selected ) . eql ( true ) ; // bar
255
- expect ( options [ 2 ] . selected ) . eql ( false ) ; // fuzz
251
+ expect ( node . querySelector ( "select" ) . id ) . eql ( "root" ) ;
252
+ } ) ;
256
253
} ) ;
257
254
258
- it ( "should render the select widget with the expected id" , ( ) => {
259
- const { node} = createFormComponent ( { schema} ) ;
255
+ describe ( "CheckboxesWidget" , ( ) => {
256
+ const uiSchema = {
257
+ "ui:widget" : "checkboxes"
258
+ } ;
260
259
261
- expect ( node . querySelector ( "select" ) . id ) . eql ( "root" ) ;
260
+ it ( "should be possible to specify a custom widget" , ( ) => {
261
+ const { node} = createFormComponent ( { schema, uiSchema} ) ;
262
+
263
+ expect ( node . querySelectorAll ( "[type=checkbox]" ) )
264
+ . to . have . length . of ( 3 ) ;
265
+ } ) ;
262
266
} ) ;
263
267
} ) ;
264
268
0 commit comments