@@ -596,6 +596,74 @@ describe('Conditional with anyOf', () => {
596
596
} ) ;
597
597
} ) ;
598
598
599
+ describe ( 'Conditional with fieldsets' , ( ) => {
600
+ const schema = {
601
+ additionalProperties : false ,
602
+ type : 'object' ,
603
+ properties : {
604
+ field_a : {
605
+ type : 'object' ,
606
+ properties : {
607
+ min : { type : 'number' } ,
608
+ max : { type : 'number' } ,
609
+ } ,
610
+ } ,
611
+ field_b : { type : 'string' } ,
612
+ } ,
613
+ allOf : [
614
+ {
615
+ if : {
616
+ properties : {
617
+ field_a : {
618
+ properties : {
619
+ min : {
620
+ minimum : 10 ,
621
+ } ,
622
+ } ,
623
+ required : [ 'min' ] ,
624
+ } ,
625
+ } ,
626
+ required : [ 'field_a' ] ,
627
+ } ,
628
+ then : {
629
+ required : [ 'field_b' ] ,
630
+ } ,
631
+ else : {
632
+ properties : {
633
+ field_b : false ,
634
+ } ,
635
+ } ,
636
+ } ,
637
+ ] ,
638
+ } ;
639
+
640
+ it ( 'handles true case' , ( ) => {
641
+ const { fields, handleValidation } = createHeadlessForm ( schema , { strictInputType : false } ) ;
642
+
643
+ expect ( fields [ 1 ] . isVisible ) . toBe ( false ) ;
644
+ expect ( handleValidation ( { field_a : { min : 100 } } ) . formErrors ) . toEqual ( {
645
+ field_b : 'Required field' ,
646
+ } ) ;
647
+ expect ( fields [ 1 ] . isVisible ) . toBe ( true ) ;
648
+ } ) ;
649
+
650
+ it ( 'handles false case' , ( ) => {
651
+ const { fields, handleValidation } = createHeadlessForm ( schema , { strictInputType : false } ) ;
652
+
653
+ expect ( fields [ 1 ] . isVisible ) . toBe ( false ) ;
654
+ expect ( handleValidation ( { field_a : { min : 1 } } ) . formErrors ) . toBeUndefined ( ) ;
655
+ expect ( fields [ 1 ] . isVisible ) . toBe ( false ) ;
656
+ } ) ;
657
+
658
+ it ( 'handles undefined fieldset case' , ( ) => {
659
+ const { fields, handleValidation } = createHeadlessForm ( schema , { strictInputType : false } ) ;
660
+
661
+ expect ( fields [ 1 ] . isVisible ) . toBe ( false ) ;
662
+ expect ( handleValidation ( { } ) . formErrors ) . toBeUndefined ( ) ;
663
+ expect ( fields [ 1 ] . isVisible ) . toBe ( false ) ;
664
+ } ) ;
665
+ } ) ;
666
+
599
667
describe ( 'Conditionals - bugs and code-smells' , ( ) => {
600
668
// Why do we have these bugs?
601
669
// To be honest we never realized it much later later.
0 commit comments