@@ -34,6 +34,7 @@ import {
3434 RuleEffect ,
3535 SchemaBasedCondition ,
3636 ValidateFunctionCondition ,
37+ ValidateFunctionContext ,
3738} from '../../src' ;
3839import { evalEnablement , evalVisibility } from '../../src/util/runtime' ;
3940
@@ -496,7 +497,7 @@ test('evalEnablement disable valid case', (t) => {
496497test ( 'evalEnablement enable valid case based on ValidateFunctionCondition' , ( t ) => {
497498 const condition : ValidateFunctionCondition = {
498499 scope : '#/properties/ruleValue' ,
499- validate : ( data ) => data === 'bar' ,
500+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
500501 } ;
501502 const uischema : ControlElement = {
502503 type : 'Control' ,
@@ -517,7 +518,7 @@ test('evalEnablement enable valid case based on ValidateFunctionCondition', (t)
517518test ( 'evalEnablement enable invalid case based on ValidateFunctionCondition' , ( t ) => {
518519 const condition : ValidateFunctionCondition = {
519520 scope : '#/properties/ruleValue' ,
520- validate : ( data ) => data === 'bar' ,
521+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
521522 } ;
522523 const uischema : ControlElement = {
523524 type : 'Control' ,
@@ -538,7 +539,7 @@ test('evalEnablement enable invalid case based on ValidateFunctionCondition', (t
538539test ( 'evalEnablement disable valid case based on ValidateFunctionCondition' , ( t ) => {
539540 const condition : ValidateFunctionCondition = {
540541 scope : '#/properties/ruleValue' ,
541- validate : ( data ) => data === 'bar' ,
542+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
542543 } ;
543544 const uischema : ControlElement = {
544545 type : 'Control' ,
@@ -559,7 +560,7 @@ test('evalEnablement disable valid case based on ValidateFunctionCondition', (t)
559560test ( 'evalEnablement disable invalid case based on ValidateFunctionCondition' , ( t ) => {
560561 const condition : ValidateFunctionCondition = {
561562 scope : '#/properties/ruleValue' ,
562- validate : ( data ) => data === 'bar' ,
563+ validate : ( context : ValidateFunctionContext ) => context . data === 'bar' ,
563564 } ;
564565 const uischema : ControlElement = {
565566 type : 'Control' ,
@@ -576,6 +577,35 @@ test('evalEnablement disable invalid case based on ValidateFunctionCondition', (
576577 t . is ( evalEnablement ( uischema , data , undefined , createAjv ( ) ) , true ) ;
577578} ) ;
578579
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+
579609test ( 'evalEnablement disable invalid case' , ( t ) => {
580610 const leafCondition : LeafCondition = {
581611 type : 'LEAF' ,
0 commit comments