mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(explore): close unsaved changes modal when discarding changes (#35307)
This commit is contained in:
@@ -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?.();
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user