-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
916 Adds unit tests for menuItemIsAllowed
- Loading branch information
1 parent
0ce09d1
commit fa49270
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...r-ui-components/src/components/WfoPageTemplate/WfoSidebar/utils/menuItemIsAllowed.spec.ts
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,52 @@ | ||
import { menuItemIsAllowed } from './menuItemIsAllowed'; | ||
|
||
const isAllowedHandlerMock = jest.fn(); | ||
const testUrlMap = new Map<string, string>([ | ||
['/testUrl1', '/testPolicyResource1'], | ||
['/testUrl2', '/testPolicyResource2'], | ||
]); | ||
|
||
describe('menuItemIsAllowed', () => { | ||
beforeEach(() => { | ||
isAllowedHandlerMock.mockClear(); | ||
}); | ||
|
||
it('returns true when url is undefined', () => { | ||
const url = undefined; | ||
|
||
const result = menuItemIsAllowed(url, testUrlMap, isAllowedHandlerMock); | ||
|
||
expect(result).toEqual(true); | ||
expect(isAllowedHandlerMock).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('returns true when url is an empty string', () => { | ||
const url = ''; | ||
|
||
const result = menuItemIsAllowed(url, testUrlMap, isAllowedHandlerMock); | ||
|
||
expect(result).toEqual(true); | ||
expect(isAllowedHandlerMock).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('returns the result of the isAllowedHandler when url is in the url-map', () => { | ||
const url = '/testUrl1'; | ||
isAllowedHandlerMock.mockReturnValue(false); | ||
|
||
const result = menuItemIsAllowed(url, testUrlMap, isAllowedHandlerMock); | ||
|
||
expect(result).toEqual(false); | ||
expect(isAllowedHandlerMock).toHaveBeenCalledWith( | ||
'/testPolicyResource1', | ||
); | ||
}); | ||
|
||
it('returns true url is not in the url-map', () => { | ||
const url = '/does-not-exist'; | ||
|
||
const result = menuItemIsAllowed(url, testUrlMap, isAllowedHandlerMock); | ||
|
||
expect(result).toEqual(true); | ||
expect(isAllowedHandlerMock).not.toHaveBeenCalled(); | ||
}); | ||
}); |