@@ -33,6 +33,8 @@ import {
33
33
OrCondition ,
34
34
RuleEffect ,
35
35
SchemaBasedCondition ,
36
+ ValidateFunctionCondition ,
37
+ ValidateFunctionContext ,
36
38
} from '../../src' ;
37
39
import { evalEnablement , evalVisibility } from '../../src/util/runtime' ;
38
40
@@ -491,6 +493,119 @@ test('evalEnablement disable valid case', (t) => {
491
493
t . is ( evalEnablement ( uischema , data , undefined , createAjv ( ) ) , false ) ;
492
494
} ) ;
493
495
496
+ // Add test case for ValidateFunctionCondition with evalEnablement (valid enable case)
497
+ test ( 'evalEnablement enable valid case based on ValidateFunctionCondition' , ( t ) => {
498
+ const condition : ValidateFunctionCondition = {
499
+ scope : '#/properties/ruleValue' ,
500
+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
501
+ } ;
502
+ const uischema : ControlElement = {
503
+ type : 'Control' ,
504
+ scope : '#/properties/value' ,
505
+ rule : {
506
+ effect : RuleEffect . ENABLE ,
507
+ condition : condition ,
508
+ } ,
509
+ } ;
510
+ const data = {
511
+ value : 'foo' ,
512
+ ruleValue : 'bar' ,
513
+ } ;
514
+ t . is ( evalEnablement ( uischema , data , undefined , createAjv ( ) ) , true ) ;
515
+ } ) ;
516
+
517
+ // Add test case for ValidateFunctionCondition with evalEnablement (invalid enable case)
518
+ test ( 'evalEnablement enable invalid case based on ValidateFunctionCondition' , ( t ) => {
519
+ const condition : ValidateFunctionCondition = {
520
+ scope : '#/properties/ruleValue' ,
521
+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
522
+ } ;
523
+ const uischema : ControlElement = {
524
+ type : 'Control' ,
525
+ scope : '#/properties/value' ,
526
+ rule : {
527
+ effect : RuleEffect . ENABLE ,
528
+ condition : condition ,
529
+ } ,
530
+ } ;
531
+ const data = {
532
+ value : 'foo' ,
533
+ ruleValue : 'foobar' ,
534
+ } ;
535
+ t . is ( evalEnablement ( uischema , data , undefined , createAjv ( ) ) , false ) ;
536
+ } ) ;
537
+
538
+ // Add test case for ValidateFunctionCondition with evalEnablement (valid disable case)
539
+ test ( 'evalEnablement disable valid case based on ValidateFunctionCondition' , ( t ) => {
540
+ const condition : ValidateFunctionCondition = {
541
+ scope : '#/properties/ruleValue' ,
542
+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
543
+ } ;
544
+ const uischema : ControlElement = {
545
+ type : 'Control' ,
546
+ scope : '#/properties/value' ,
547
+ rule : {
548
+ effect : RuleEffect . DISABLE ,
549
+ condition : condition ,
550
+ } ,
551
+ } ;
552
+ const data = {
553
+ value : 'foo' ,
554
+ ruleValue : 'bar' ,
555
+ } ;
556
+ t . is ( evalEnablement ( uischema , data , undefined , createAjv ( ) ) , false ) ;
557
+ } ) ;
558
+
559
+ // Add test case for ValidateFunctionCondition with evalEnablement (invalid disable case)
560
+ test ( 'evalEnablement disable invalid case based on ValidateFunctionCondition' , ( t ) => {
561
+ const condition : ValidateFunctionCondition = {
562
+ scope : '#/properties/ruleValue' ,
563
+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
564
+ } ;
565
+ const uischema : ControlElement = {
566
+ type : 'Control' ,
567
+ scope : '#/properties/value' ,
568
+ rule : {
569
+ effect : RuleEffect . DISABLE ,
570
+ condition : condition ,
571
+ } ,
572
+ } ;
573
+ const data = {
574
+ value : 'foo' ,
575
+ ruleValue : 'foobar' ,
576
+ } ;
577
+ t . is ( evalEnablement ( uischema , data , undefined , createAjv ( ) ) , true ) ;
578
+ } ) ;
579
+
580
+ // Test context properties for ValidateFunctionCondition
581
+ test ( 'ValidateFunctionCondition correctly passes context parameters' , ( t ) => {
582
+ const condition : ValidateFunctionCondition = {
583
+ scope : '#/properties/ruleValue' ,
584
+ validate : ( context : ValidateFunctionContext ) => {
585
+ // Verify all context properties are passed correctly
586
+ return (
587
+ context . data === 'bar' &&
588
+ ( context . fullData as any ) . value === 'foo' &&
589
+ context . path === undefined &&
590
+ ( context . uischemaElement as any ) . scope === '#/properties/value'
591
+ ) ;
592
+ } ,
593
+ } ;
594
+ const uischema : ControlElement = {
595
+ type : 'Control' ,
596
+ scope : '#/properties/value' ,
597
+ rule : {
598
+ effect : RuleEffect . ENABLE ,
599
+ condition : condition ,
600
+ } ,
601
+ } ;
602
+ const data = {
603
+ value : 'foo' ,
604
+ ruleValue : 'bar' ,
605
+ } ;
606
+ t . is ( evalEnablement ( uischema , data , undefined , createAjv ( ) ) , true ) ;
607
+ } ) ;
608
+
494
609
test ( 'evalEnablement disable invalid case' , ( t ) => {
495
610
const leafCondition : LeafCondition = {
496
611
type : 'LEAF' ,
0 commit comments