@@ -548,6 +548,54 @@ describe('Conditional with literal booleans', () => {
548
548
} ) ;
549
549
} ) ;
550
550
551
+ describe ( 'Conditional with anyOf' , ( ) => {
552
+ const schema = {
553
+ additionalProperties : false ,
554
+ type : 'object' ,
555
+ properties : {
556
+ field_a : { type : 'string' } ,
557
+ field_b : { type : 'string' } ,
558
+ field_c : { type : 'string' } ,
559
+ } ,
560
+ allOf : [
561
+ {
562
+ if : {
563
+ anyOf : [
564
+ { properties : { field_a : { const : '1' } } , required : [ 'field_a' ] } ,
565
+ { properties : { field_b : { const : '2' } } , required : [ 'field_b' ] } ,
566
+ ] ,
567
+ } ,
568
+ then : {
569
+ required : [ 'field_c' ] ,
570
+ } ,
571
+ else : {
572
+ properties : {
573
+ field_c : false ,
574
+ } ,
575
+ } ,
576
+ } ,
577
+ ] ,
578
+ } ;
579
+
580
+ it ( 'handles true case' , ( ) => {
581
+ const { fields, handleValidation } = createHeadlessForm ( schema , { strictInputType : false } ) ;
582
+
583
+ expect ( fields [ 2 ] . isVisible ) . toBe ( false ) ;
584
+ expect ( handleValidation ( { field_a : 'x' , field_b : '2' } ) . formErrors ) . toEqual ( {
585
+ field_c : 'Required field' ,
586
+ } ) ;
587
+ expect ( fields [ 2 ] . isVisible ) . toBe ( true ) ;
588
+ } ) ;
589
+
590
+ it ( 'handles false case' , ( ) => {
591
+ const { fields, handleValidation } = createHeadlessForm ( schema , { strictInputType : false } ) ;
592
+
593
+ expect ( fields [ 2 ] . isVisible ) . toBe ( false ) ;
594
+ expect ( handleValidation ( { field_a : 'x' , field_b : 'x' } ) . formErrors ) . toBeUndefined ( ) ;
595
+ expect ( fields [ 2 ] . isVisible ) . toBe ( false ) ;
596
+ } ) ;
597
+ } ) ;
598
+
551
599
describe ( 'Conditionals - bugs and code-smells' , ( ) => {
552
600
// Why do we have these bugs?
553
601
// To be honest we never realized it much later later.
0 commit comments