mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Fleet] Fix history block to support hash param (#141081)
This commit is contained in:
parent
01b604eeb6
commit
0af26e2ab9
2 changed files with 50 additions and 1 deletions
|
@ -102,4 +102,50 @@ describe('useHistoryBlock', () => {
|
|||
expect(renderer.startServices.application.navigateToUrl).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with hash params', () => {
|
||||
it('should not block if not edited', () => {
|
||||
const renderer = createFleetTestRendererMock();
|
||||
|
||||
renderer.renderHook(() => useHistoryBlock(false));
|
||||
|
||||
act(() => renderer.mountHistory.push('/test#/hash'));
|
||||
|
||||
const { location } = renderer.mountHistory;
|
||||
expect(location.pathname).toBe('/test');
|
||||
expect(location.hash).toBe('#/hash');
|
||||
expect(renderer.startServices.overlays.openConfirm).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should block if edited and navigate on confirm', async () => {
|
||||
const renderer = createFleetTestRendererMock();
|
||||
|
||||
renderer.startServices.overlays.openConfirm.mockResolvedValue(true);
|
||||
renderer.renderHook(() => useHistoryBlock(true));
|
||||
|
||||
act(() => renderer.mountHistory.push('/test#/hash'));
|
||||
// needed because we have an async useEffect
|
||||
await act(() => new Promise((resolve) => resolve()));
|
||||
|
||||
expect(renderer.startServices.overlays.openConfirm).toBeCalled();
|
||||
expect(renderer.startServices.application.navigateToUrl).toBeCalledWith(
|
||||
'/mock/test#/hash',
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
||||
it('should block if edited and not navigate on cancel', async () => {
|
||||
const renderer = createFleetTestRendererMock();
|
||||
|
||||
renderer.startServices.overlays.openConfirm.mockResolvedValue(false);
|
||||
renderer.renderHook(() => useHistoryBlock(true));
|
||||
|
||||
act(() => renderer.mountHistory.push('/test#/hash'));
|
||||
// needed because we have an async useEffect
|
||||
await act(() => new Promise((resolve) => resolve()));
|
||||
|
||||
expect(renderer.startServices.overlays.openConfirm).toBeCalled();
|
||||
expect(renderer.startServices.application.navigateToUrl).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -35,7 +35,10 @@ export function useHistoryBlock(isEdited: boolean) {
|
|||
|
||||
if (confirmRes) {
|
||||
unblock();
|
||||
application.navigateToUrl(state.pathname + state.search, { state: state.state });
|
||||
|
||||
application.navigateToUrl(state.pathname + state.hash + state.search, {
|
||||
state: state.state,
|
||||
});
|
||||
}
|
||||
}
|
||||
confirmAsync();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue