Skip to content

Commit bfb8540

Browse files
committed
test added
1 parent bd1a770 commit bfb8540

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

superset-frontend/src/hooks/useUnsavedChangesPrompt/useUnsavedChangesPrompt.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,33 @@ describe('useUnsavedChangesPrompt', () => {
103103
expect(onSave).toHaveBeenCalled();
104104
expect(result.current.showModal).toBe(false);
105105
});
106+
107+
it('should close modal when handleConfirmNavigation is called', () => {
108+
const onSave = jest.fn();
109+
110+
const { result } = renderHook(
111+
() =>
112+
useUnsavedChangesPrompt({
113+
hasUnsavedChanges: true,
114+
onSave,
115+
}),
116+
{ wrapper },
117+
);
118+
119+
// First, trigger navigation to show the modal
120+
act(() => {
121+
const unblock = history.block((tx: any) => tx);
122+
unblock();
123+
history.push('/another-page');
124+
});
125+
126+
expect(result.current.showModal).toBe(true);
127+
128+
// Then call handleConfirmNavigation to discard changes
129+
act(() => {
130+
result.current.handleConfirmNavigation();
131+
});
132+
133+
expect(result.current.showModal).toBe(false);
134+
});
106135
});

0 commit comments

Comments
 (0)