@@ -4,9 +4,9 @@ import { setInitialGlobalState } from '@/test/__mocks__/store';
44
55import { RouterProvider , createMemoryRouter } from 'react-router-dom' ;
66
7- import { fireEvent , render , screen , waitFor } from '@testing-library/react' ;
7+ import { cleanup , fireEvent , render , screen , waitFor } from '@testing-library/react' ;
88
9- import { useConfigStore } from '@/store' ;
9+ import { useConfigStore , useLoadingStateStore } from '@/store' ;
1010
1111import { Prompt } from './Prompt' ;
1212
@@ -15,6 +15,7 @@ const mockedUseBlocker = {
1515 proceed : jest . fn ( ) ,
1616} ;
1717
18+ const mockResetIsLoading = jest . fn ( ) ;
1819const setIsModalOpen = jest . fn ( ) ;
1920const openModal = jest . fn ( ) ;
2021const dispatchEvent = jest . fn ( ) ;
@@ -60,6 +61,10 @@ const renderPrompt = (isBlocking = true) => {
6061 store : useConfigStore ,
6162 state : { customEvents : { TRIGGER_MODAL : 'triggermodal' } } ,
6263 } ,
64+ {
65+ store : useLoadingStateStore ,
66+ state : { resetIsLoading : mockResetIsLoading } ,
67+ } ,
6368 ] ) ;
6469
6570 return render (
@@ -102,4 +107,16 @@ describe('Prompt', () => {
102107
103108 expect ( addEventListener ) . toHaveBeenCalled ( ) ;
104109 } ) ;
110+
111+ test ( 'calls resetIsLoading when navigation is blocked' , ( ) => {
112+ expect ( mockResetIsLoading ) . toHaveBeenCalled ( ) ;
113+ } ) ;
114+
115+ test ( 'does not call resetIsLoading when "when" prop is false' , ( ) => {
116+ cleanup ( ) ;
117+ mockResetIsLoading . mockClear ( ) ;
118+ renderPrompt ( false ) ;
119+
120+ expect ( mockResetIsLoading ) . not . toHaveBeenCalled ( ) ;
121+ } ) ;
105122} ) ;
0 commit comments