fix(explore): close unsaved changes modal when discarding changes (#35307)

This commit is contained in:
Rafael Benitez
2025-10-01 11:43:02 -03:00
committed by GitHub
parent 40378afbf8
commit d8688cf8b1
2 changed files with 30 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ export const useUnsavedChangesPrompt = ({
const manualSaveRef = useRef(false); // Track if save was user-initiated (not via navigation)
const handleConfirmNavigation = useCallback(() => {
setShowModal(false);
confirmNavigationRef.current?.();
}, []);

View File

@@ -104,4 +104,33 @@ describe('useUnsavedChangesPrompt', () => {
expect(onSave).toHaveBeenCalled();
expect(result.current.showModal).toBe(false);
});
it('should close modal when handleConfirmNavigation is called', () => {
const onSave = jest.fn();
const { result } = renderHook(
() =>
useUnsavedChangesPrompt({
hasUnsavedChanges: true,
onSave,
}),
{ wrapper },
);
// First, trigger navigation to show the modal
act(() => {
const unblock = history.block((tx: any) => tx);
unblock();
history.push('/another-page');
});
expect(result.current.showModal).toBe(true);
// Then call handleConfirmNavigation to discard changes
act(() => {
result.current.handleConfirmNavigation();
});
expect(result.current.showModal).toBe(false);
});
});