1
+ import React from 'react' ;
2
+ import { mount } from 'enzyme' ;
3
+ import Card from './Card' ;
4
+ import Section from './Section' ;
1
5
import {
2
6
parse ,
3
7
stringify ,
@@ -7,6 +11,7 @@ import {
7
11
generateSchemaFromElementProps ,
8
12
generateUiSchemaFromElementProps ,
9
13
generateCategoryHash ,
14
+ generateElementComponentsFromSchemas ,
10
15
} from './utils' ;
11
16
import DEFAULT_FORM_INPUTS from './defaults/defaultFormInputs' ;
12
17
@@ -380,3 +385,84 @@ describe('generateUiSchemaFromElementProps', () => {
380
385
} ) ;
381
386
} ) ;
382
387
} ) ;
388
+
389
+ describe ( 'generateElementComponentsFromSchemas' , ( ) => {
390
+ it ( 'propagates mods to Section component' , ( ) => {
391
+ const MockComponent = jest . fn ( ( ) => < div /> ) ;
392
+ const mods = {
393
+ customFormInputs : {
394
+ test : {
395
+ displayName : 'Test' ,
396
+ matchIf : [
397
+ {
398
+ types : [ 'number' ] ,
399
+ widget : 'test' ,
400
+ } ,
401
+ ] ,
402
+ defaultDataSchema : { } ,
403
+ defaultUiSchema : { 'ui:widget' : 'test' } ,
404
+ type : 'number' ,
405
+ cardBody : MockComponent ,
406
+ } ,
407
+ } ,
408
+ } ;
409
+ const allFormInputs = {
410
+ ...DEFAULT_FORM_INPUTS ,
411
+ ...mods . customFormInputs ,
412
+ } ;
413
+ const categoryHash = generateCategoryHash ( allFormInputs ) ;
414
+
415
+ const TestComponent = ( ) => (
416
+ < React . Fragment >
417
+ { generateElementComponentsFromSchemas ( {
418
+ schemaData : {
419
+ type : 'object' ,
420
+ properties : {
421
+ section1 : {
422
+ title : 'Section 1' ,
423
+ type : 'object' ,
424
+ properties : {
425
+ newInput1 : {
426
+ items : {
427
+ type : 'number' ,
428
+ } ,
429
+ title : 'New Input 1' ,
430
+ type : 'array' ,
431
+ } ,
432
+ } ,
433
+ dependencies : { } ,
434
+ required : [ ] ,
435
+ } ,
436
+ } ,
437
+ dependencies : { } ,
438
+ required : [ ] ,
439
+ } ,
440
+ uiSchemaData : {
441
+ section1 : {
442
+ newInput1 : {
443
+ items : {
444
+ 'ui:widget' : 'test' ,
445
+ } ,
446
+ } ,
447
+ 'ui:order' : [ 'newInput1' ] ,
448
+ } ,
449
+ 'ui:order' : [ 'section1' ] ,
450
+ } ,
451
+ onChange : ( ) => { } ,
452
+ path : '' ,
453
+ cardOpenArray : [ true ] ,
454
+ setCardOpenArray : ( ) => { } ,
455
+ allFormInputs,
456
+ mods,
457
+ categoryHash,
458
+ Card,
459
+ Section,
460
+ } ) }
461
+ </ React . Fragment >
462
+ ) ;
463
+ const div = document . createElement ( 'div' ) ;
464
+ document . body . appendChild ( div ) ;
465
+ mount ( < TestComponent /> , { attachTo : div } ) ;
466
+ expect ( MockComponent . mock . calls [ 0 ] [ 0 ] . mods ) . toEqual ( mods ) ;
467
+ } ) ;
468
+ } ) ;
0 commit comments