@@ -482,6 +482,230 @@ describe('AgentflowContext - duplicateNode', () => {
482482 } )
483483} )
484484
485+ describe ( 'AgentflowContext - openEditDialog & closeEditDialog' , ( ) => {
486+ it ( 'should open edit dialog with node data and input params' , ( ) => {
487+ const initialFlow : FlowData = {
488+ nodes : [ makeNode ( 'node-1' ) ] ,
489+ edges : [ ]
490+ }
491+
492+ const { result } = renderHook ( ( ) => useAgentflowContext ( ) , {
493+ wrapper : createWrapper ( initialFlow )
494+ } )
495+
496+ // Initial state should have no editing node
497+ expect ( result . current . state . editingNodeId ) . toBeNull ( )
498+ expect ( result . current . state . editDialogProps ) . toBeNull ( )
499+
500+ const nodeData = {
501+ id : 'node-1' ,
502+ name : 'testNode' ,
503+ label : 'Test Node' ,
504+ outputAnchors : [ ]
505+ }
506+
507+ const inputParams = [
508+ {
509+ id : 'param-1' ,
510+ name : 'param1' ,
511+ label : 'Parameter 1' ,
512+ type : 'string'
513+ }
514+ ]
515+
516+ // Open edit dialog
517+ act ( ( ) => {
518+ result . current . openEditDialog ( 'node-1' , nodeData , inputParams )
519+ } )
520+
521+ // Should set editingNodeId
522+ expect ( result . current . state . editingNodeId ) . toBe ( 'node-1' )
523+
524+ // Should set editDialogProps
525+ expect ( result . current . state . editDialogProps ) . toEqual ( {
526+ inputParams : inputParams ,
527+ data : nodeData ,
528+ disabled : false
529+ } )
530+ } )
531+
532+ it ( 'should close edit dialog and clear state' , ( ) => {
533+ const initialFlow : FlowData = {
534+ nodes : [ makeNode ( 'node-1' ) ] ,
535+ edges : [ ]
536+ }
537+
538+ const { result } = renderHook ( ( ) => useAgentflowContext ( ) , {
539+ wrapper : createWrapper ( initialFlow )
540+ } )
541+
542+ const nodeData = {
543+ id : 'node-1' ,
544+ name : 'testNode' ,
545+ label : 'Test Node' ,
546+ outputAnchors : [ ]
547+ }
548+
549+ const inputParams = [
550+ {
551+ id : 'param-1' ,
552+ name : 'param1' ,
553+ label : 'Parameter 1' ,
554+ type : 'string'
555+ }
556+ ]
557+
558+ // First open the dialog
559+ act ( ( ) => {
560+ result . current . openEditDialog ( 'node-1' , nodeData , inputParams )
561+ } )
562+
563+ // Verify dialog is open
564+ expect ( result . current . state . editingNodeId ) . toBe ( 'node-1' )
565+ expect ( result . current . state . editDialogProps ) . not . toBeNull ( )
566+
567+ // Close the dialog
568+ act ( ( ) => {
569+ result . current . closeEditDialog ( )
570+ } )
571+
572+ // Should clear editingNodeId
573+ expect ( result . current . state . editingNodeId ) . toBeNull ( )
574+
575+ // Should clear editDialogProps
576+ expect ( result . current . state . editDialogProps ) . toBeNull ( )
577+ } )
578+
579+ it ( 'should handle opening dialog for different nodes' , ( ) => {
580+ const initialFlow : FlowData = {
581+ nodes : [ makeNode ( 'node-1' ) , makeNode ( 'node-2' ) ] ,
582+ edges : [ ]
583+ }
584+
585+ const { result } = renderHook ( ( ) => useAgentflowContext ( ) , {
586+ wrapper : createWrapper ( initialFlow )
587+ } )
588+
589+ const nodeData1 = {
590+ id : 'node-1' ,
591+ name : 'testNode1' ,
592+ label : 'Test Node 1' ,
593+ outputAnchors : [ ]
594+ }
595+
596+ const nodeData2 = {
597+ id : 'node-2' ,
598+ name : 'testNode2' ,
599+ label : 'Test Node 2' ,
600+ outputAnchors : [ ]
601+ }
602+
603+ const inputParams = [
604+ {
605+ id : 'param-1' ,
606+ name : 'param1' ,
607+ label : 'Parameter 1' ,
608+ type : 'string'
609+ }
610+ ]
611+
612+ // Open dialog for node-1
613+ act ( ( ) => {
614+ result . current . openEditDialog ( 'node-1' , nodeData1 , inputParams )
615+ } )
616+
617+ expect ( result . current . state . editingNodeId ) . toBe ( 'node-1' )
618+ expect ( result . current . state . editDialogProps ) . not . toBeNull ( )
619+ expect ( result . current . state . editDialogProps ! . data ) . toBeDefined ( )
620+ expect ( result . current . state . editDialogProps ! . data ! . label ) . toBe ( 'Test Node 1' )
621+
622+ // Open dialog for node-2 (should replace node-1)
623+ act ( ( ) => {
624+ result . current . openEditDialog ( 'node-2' , nodeData2 , inputParams )
625+ } )
626+
627+ expect ( result . current . state . editingNodeId ) . toBe ( 'node-2' )
628+ expect ( result . current . state . editDialogProps ) . not . toBeNull ( )
629+ expect ( result . current . state . editDialogProps ! . data ) . toBeDefined ( )
630+ expect ( result . current . state . editDialogProps ! . data ! . label ) . toBe ( 'Test Node 2' )
631+ } )
632+
633+ it ( 'should set disabled to false in dialog props' , ( ) => {
634+ const initialFlow : FlowData = {
635+ nodes : [ makeNode ( 'node-1' ) ] ,
636+ edges : [ ]
637+ }
638+
639+ const { result } = renderHook ( ( ) => useAgentflowContext ( ) , {
640+ wrapper : createWrapper ( initialFlow )
641+ } )
642+
643+ const nodeData = {
644+ id : 'node-1' ,
645+ name : 'testNode' ,
646+ label : 'Test Node' ,
647+ outputAnchors : [ ]
648+ }
649+
650+ act ( ( ) => {
651+ result . current . openEditDialog ( 'node-1' , nodeData , [ ] )
652+ } )
653+
654+ // disabled should always be false
655+ expect ( result . current . state . editDialogProps ?. disabled ) . toBe ( false )
656+ } )
657+
658+ it ( 'should preserve inputParams in dialog props' , ( ) => {
659+ const initialFlow : FlowData = {
660+ nodes : [ makeNode ( 'node-1' ) ] ,
661+ edges : [ ]
662+ }
663+
664+ const { result } = renderHook ( ( ) => useAgentflowContext ( ) , {
665+ wrapper : createWrapper ( initialFlow )
666+ } )
667+
668+ const nodeData = {
669+ id : 'node-1' ,
670+ name : 'testNode' ,
671+ label : 'Test Node' ,
672+ outputAnchors : [ ]
673+ }
674+
675+ const inputParams = [
676+ {
677+ id : 'param-1' ,
678+ name : 'param1' ,
679+ label : 'Parameter 1' ,
680+ type : 'string' ,
681+ optional : true
682+ } ,
683+ {
684+ id : 'param-2' ,
685+ name : 'param2' ,
686+ label : 'Parameter 2' ,
687+ type : 'number' ,
688+ default : 42
689+ }
690+ ]
691+
692+ act ( ( ) => {
693+ result . current . openEditDialog ( 'node-1' , nodeData , inputParams )
694+ } )
695+
696+ // Should preserve all input params with their properties
697+ expect ( result . current . state . editDialogProps ) . not . toBeNull ( )
698+ expect ( result . current . state . editDialogProps ! . inputParams ) . toEqual ( inputParams )
699+ expect ( result . current . state . editDialogProps ! . inputParams ) . toHaveLength ( 2 )
700+
701+ const params = result . current . state . editDialogProps ! . inputParams !
702+ expect ( params [ 0 ] ) . toBeDefined ( )
703+ expect ( params [ 0 ] ! . optional ) . toBe ( true )
704+ expect ( params [ 1 ] ) . toBeDefined ( )
705+ expect ( params [ 1 ] ! . default ) . toBe ( 42 )
706+ } )
707+ } )
708+
485709describe ( 'AgentflowContext - state synchronization' , ( ) => {
486710 it ( 'should call local state setters for setNodes' , ( ) => {
487711 const initialFlow : FlowData = {
0 commit comments