@@ -387,4 +387,58 @@ describe("useModalForm Hook", () => {
387387 title : "default-title" ,
388388 } ) ;
389389 } ) ;
390+
391+ it ( "should handle action switching correctly - modal should show after switching from edit to create" , async ( ) => {
392+ // This test reproduces the bug described in the issue
393+ const { result, rerender } = renderHook (
394+ ( { action } : { action : "create" | "edit" } ) =>
395+ useModalForm ( {
396+ refineCoreProps : {
397+ resource : "posts" ,
398+ action,
399+ } ,
400+ } ) ,
401+ {
402+ wrapper : TestWrapper ( { } ) ,
403+ initialProps : { action : "create" as const } ,
404+ } ,
405+ ) ;
406+
407+ // Step 1: Open create modal - should work
408+ await act ( async ( ) => {
409+ result . current . modal . show ( ) ;
410+ } ) ;
411+ expect ( result . current . modal . visible ) . toBe ( true ) ;
412+
413+ // Step 2: Close modal
414+ await act ( async ( ) => {
415+ result . current . modal . close ( ) ;
416+ } ) ;
417+ expect ( result . current . modal . visible ) . toBe ( false ) ;
418+
419+ // Step 3: Switch to edit action
420+ rerender ( { action : "edit" } ) ;
421+
422+ // Step 4: Open edit modal with ID - should work
423+ await act ( async ( ) => {
424+ result . current . modal . show ( "5" ) ;
425+ } ) ;
426+ expect ( result . current . modal . visible ) . toBe ( true ) ;
427+
428+ // Step 5: Close modal
429+ await act ( async ( ) => {
430+ result . current . modal . close ( ) ;
431+ } ) ;
432+ expect ( result . current . modal . visible ) . toBe ( false ) ;
433+
434+ // Step 6: Switch back to create action
435+ rerender ( { action : "create" } ) ;
436+
437+ // Step 7: Try to open create modal again
438+ await act ( async ( ) => {
439+ result . current . modal . show ( ) ;
440+ } ) ;
441+
442+ expect ( result . current . modal . visible ) . toBe ( true ) ;
443+ } ) ;
390444} ) ;
0 commit comments