@@ -390,6 +390,49 @@ describe('<SelectArrayInput />', () => {
390
390
} ) ;
391
391
} ) ;
392
392
393
+ it ( 'should support creation of a new choice with nested optionText' , async ( ) => {
394
+ const choices = [
395
+ { id : 'programming' , name : { en : 'Programming' } } ,
396
+ { id : 'lifestyle' , name : { en : 'Lifestyle' } } ,
397
+ { id : 'photography' , name : { en : 'Photography' } } ,
398
+ ] ;
399
+ const newChoice = {
400
+ id : 'js_fatigue' ,
401
+ name : { en : 'New Kid On The Block' } ,
402
+ } ;
403
+
404
+ const { getByLabelText, getByRole, getByText, queryAllByText } = render (
405
+ < Form
406
+ validateOnBlur
407
+ onSubmit = { jest . fn ( ) }
408
+ render = { ( ) => (
409
+ < SelectArrayInput
410
+ { ...defaultProps }
411
+ choices = { choices }
412
+ onCreate = { ( ) => {
413
+ choices . push ( newChoice ) ;
414
+ return newChoice ;
415
+ } }
416
+ optionText = "name.en"
417
+ />
418
+ ) }
419
+ />
420
+ ) ;
421
+
422
+ const input = getByLabelText (
423
+ 'resources.posts.fields.categories'
424
+ ) as HTMLInputElement ;
425
+ input . focus ( ) ;
426
+ const select = getByRole ( 'button' ) ;
427
+ fireEvent . mouseDown ( select ) ;
428
+
429
+ fireEvent . click ( getByText ( 'ra.action.create' ) ) ;
430
+ await new Promise ( resolve => setTimeout ( resolve ) ) ;
431
+ input . blur ( ) ;
432
+ // 2 because there is both the chip for the new selected item and the option (event if hidden)
433
+ expect ( queryAllByText ( newChoice . name . en ) . length ) . toEqual ( 2 ) ;
434
+ } ) ;
435
+
393
436
it ( 'should support creation of a new choice through the create element' , async ( ) => {
394
437
const choices = [ ...defaultProps . choices ] ;
395
438
const newChoice = { id : 'js_fatigue' , name : 'New Kid On The Block' } ;
0 commit comments