-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
psp-7100 hide the management tab if user does not have management vie…
…w permission.
- Loading branch information
1 parent
22874b1
commit c28a12e
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
source/frontend/src/features/mapSideBar/property/PropertyContainer.test.tsx
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,55 @@ | ||
import { createMemoryHistory } from 'history'; | ||
|
||
import { Claims } from '@/constants'; | ||
import { mockLookups } from '@/mocks/lookups.mock'; | ||
import { lookupCodesSlice } from '@/store/slices/lookupCodes'; | ||
import { cleanup, getByText, render, RenderOptions } from '@/utils/test-utils'; | ||
|
||
import PropertyContainer, { IPropertyContainerProps } from './PropertyContainer'; | ||
|
||
// mock keycloak auth library | ||
jest.mock('@react-keycloak/web'); | ||
|
||
describe('PropertyContainer component', () => { | ||
const history = createMemoryHistory(); | ||
const storeState = { | ||
[lookupCodesSlice.name]: { lookupCodes: mockLookups }, | ||
}; | ||
|
||
const setup = (renderOptions: RenderOptions & IPropertyContainerProps) => { | ||
// render component under test | ||
const utils = render(<PropertyContainer {...renderOptions} />, { | ||
...renderOptions, | ||
history, | ||
store: { ...renderOptions.store, ...storeState }, | ||
claims: renderOptions.claims ?? [], | ||
}); | ||
|
||
return { ...utils }; | ||
}; | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
cleanup(); | ||
}); | ||
|
||
it('hides the management tab if the user does not have permission', async () => { | ||
const { queryByText } = setup({ | ||
claims: [], | ||
composedPropertyState: { apiWrapper: { response: {} }, id: 1 } as any, | ||
setEditManagementState: jest.fn(), | ||
}); | ||
|
||
expect(queryByText('Management')).toBeNull(); | ||
}); | ||
|
||
it('displays the management tab if the user has permission', async () => { | ||
const { getByText } = setup({ | ||
claims: [Claims.MANAGEMENT_VIEW], | ||
composedPropertyState: { apiWrapper: { response: {} }, id: 1 } as any, | ||
setEditManagementState: jest.fn(), | ||
}); | ||
|
||
expect(getByText('Management')).toBeVisible(); | ||
}); | ||
}); |
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