Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call miqCheckForChanges in breadcrumbs
- Loading branch information
Showing
5 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/javascript/components/breadcrumbs/on-click-functions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const onClickTree = (controllerName, item) => ( | ||
window.miqCheckForChanges() | ||
? sendDataWithRx({ breadcrumbSelect: { path: `/${controllerName}/tree_select`, key: item.key } }) : null | ||
); | ||
|
||
export const onClick = (e, url) => { | ||
e.preventDefault(); | ||
if (window.miqCheckForChanges()) { | ||
window.location.assign(url); | ||
} | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/javascript/spec/breadcrumbs/on-click-functions.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { onClickTree, onClick } from '../../components/breadcrumbs/on-click-functions'; | ||
|
||
describe('Breadcrumbs onClick functions', () => { | ||
describe('onClick', () => { | ||
it('calls e.prevent default', () => { | ||
const mockFn = jest.fn(); | ||
window.miqCheckForChanges = jest.fn(() => false); | ||
|
||
const result = onClick({ preventDefault: mockFn }, '/url'); | ||
|
||
expect(mockFn).toHaveBeenCalled(); | ||
expect(window.miqCheckForChanges).toHaveBeenCalled(); | ||
expect(result).toEqual(null); | ||
|
||
window.miqCheckForChanges.mockClear(); | ||
}); | ||
|
||
it('change location', () => { | ||
const mockFn = jest.fn(); | ||
window.miqCheckForChanges = () => true; | ||
window.location.assign = jest.fn(); | ||
|
||
onClick({ preventDefault: mockFn }, '/url'); | ||
|
||
expect(window.location.assign).toHaveBeenCalledWith('/url'); | ||
|
||
window.location.assign.mockClear(); | ||
}); | ||
}); | ||
|
||
describe('onClickTree', () => { | ||
it('returns null if no changes', () => { | ||
window.miqCheckForChanges = () => false; | ||
jest.spyOn(window, 'sendDataWithRx'); | ||
|
||
const result = onClickTree(); | ||
|
||
expect(result).toEqual(null); | ||
expect(window.sendDataWithRx).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('calls rxjs', () => { | ||
window.miqCheckForChanges = () => true; | ||
jest.spyOn(window, 'sendDataWithRx'); | ||
|
||
onClickTree('pxe', { key: 'xx-11' }); | ||
|
||
expect(window.sendDataWithRx).toHaveBeenCalledWith({ | ||
breadcrumbSelect: { | ||
key: 'xx-11', | ||
path: '/pxe/tree_select', | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |