@@ -34,6 +34,7 @@ import {
34
34
RuleEffect ,
35
35
SchemaBasedCondition ,
36
36
ValidateFunctionCondition ,
37
+ ValidateFunctionContext ,
37
38
} from '../../src' ;
38
39
import { evalEnablement , evalVisibility } from '../../src/util/runtime' ;
39
40
@@ -496,7 +497,7 @@ test('evalEnablement disable valid case', (t) => {
496
497
test ( 'evalEnablement enable valid case based on ValidateFunctionCondition' , ( t ) => {
497
498
const condition : ValidateFunctionCondition = {
498
499
scope : '#/properties/ruleValue' ,
499
- validate : ( data ) => data === 'bar' ,
500
+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
500
501
} ;
501
502
const uischema : ControlElement = {
502
503
type : 'Control' ,
@@ -517,7 +518,7 @@ test('evalEnablement enable valid case based on ValidateFunctionCondition', (t)
517
518
test ( 'evalEnablement enable invalid case based on ValidateFunctionCondition' , ( t ) => {
518
519
const condition : ValidateFunctionCondition = {
519
520
scope : '#/properties/ruleValue' ,
520
- validate : ( data ) => data === 'bar' ,
521
+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
521
522
} ;
522
523
const uischema : ControlElement = {
523
524
type : 'Control' ,
@@ -538,7 +539,7 @@ test('evalEnablement enable invalid case based on ValidateFunctionCondition', (t
538
539
test ( 'evalEnablement disable valid case based on ValidateFunctionCondition' , ( t ) => {
539
540
const condition : ValidateFunctionCondition = {
540
541
scope : '#/properties/ruleValue' ,
541
- validate : ( data ) => data === 'bar' ,
542
+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
542
543
} ;
543
544
const uischema : ControlElement = {
544
545
type : 'Control' ,
@@ -559,7 +560,7 @@ test('evalEnablement disable valid case based on ValidateFunctionCondition', (t)
559
560
test ( 'evalEnablement disable invalid case based on ValidateFunctionCondition' , ( t ) => {
560
561
const condition : ValidateFunctionCondition = {
561
562
scope : '#/properties/ruleValue' ,
562
- validate : ( data ) => data === 'bar' ,
563
+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
563
564
} ;
564
565
const uischema : ControlElement = {
565
566
type : 'Control' ,
@@ -576,6 +577,35 @@ test('evalEnablement disable invalid case based on ValidateFunctionCondition', (
576
577
t . is ( evalEnablement ( uischema , data , undefined , createAjv ( ) ) , true ) ;
577
578
} ) ;
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
+
579
609
test ( 'evalEnablement disable invalid case' , ( t ) => {
580
610
const leafCondition : LeafCondition = {
581
611
type : 'LEAF' ,
0 commit comments