-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor how call to action buttons on homepage are generated * Fix test regressions * Add comments and fix typo
- Loading branch information
1 parent
4ced953
commit a0ee1a7
Showing
6 changed files
with
236 additions
and
555 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,90 @@ | ||
import { mount } from 'enzyme'; | ||
import toJson from 'enzyme-to-json'; | ||
import { history } from '@onaio/connected-reducer-registry'; | ||
import React from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
import { Router } from 'react-router'; | ||
import { Home } from '../Home'; | ||
import { store } from '@opensrp/store'; | ||
import { Provider } from 'react-redux'; | ||
import { | ||
URL_LOCATION_UNIT, | ||
URL_LOCATION_UNIT_GROUP, | ||
URL_TEAMS, | ||
URL_USER, | ||
} from '../../../../constants'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import { authenticateUser } from '@onaio/session-reducer'; | ||
import React from 'react'; | ||
|
||
jest.mock('../../../../configs/env'); | ||
jest.mock('../../../../configs/settings'); | ||
|
||
describe('containers/pages/Home', () => { | ||
it('renders Home correctly & changes Title of page', () => { | ||
const wrapper = mount( | ||
<Router history={history}> | ||
<Home /> | ||
</Router> | ||
); | ||
|
||
const helmet = Helmet.peek(); | ||
expect(helmet.title).toEqual('OpenSRP Web'); | ||
wrapper.find('.admin-link').forEach((adminLink) => { | ||
expect(toJson(adminLink)).toMatchSnapshot('links on home page'); | ||
}); | ||
wrapper.unmount(); | ||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
it('displays links for user management module', () => { | ||
const envModule = require('../../../../configs/env'); | ||
envModule.ENABLE_USER_MANAGEMENT = true; | ||
|
||
const wrapper = mount( | ||
it('renders Home correctly & changes Title of page', () => { | ||
render( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<Home /> | ||
</Router> | ||
</Provider> | ||
); | ||
|
||
expect(wrapper.find(`Link[to="${URL_USER}"]`)).toHaveLength(1); | ||
const helmet = Helmet.peek(); | ||
expect(helmet.title).toEqual('OpenSRP Web'); | ||
screen.getByText(/Missing the required permissions to view data on this page/i); | ||
}); | ||
|
||
it('displays links for location unit module', () => { | ||
const envModule = require('../../../../configs/env'); | ||
envModule.ENABLE_LOCATIONS = true; | ||
|
||
const wrapper = mount( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<Home /> | ||
</Router> | ||
</Provider> | ||
it('renders Home correctly & changes Title of page 2', () => { | ||
store.dispatch( | ||
authenticateUser( | ||
true, | ||
{ email: '[email protected]', name: 'Bobbie', username: 'RobertBaratheon' }, | ||
{ | ||
roles: ['ROLE_VIEW_KEYCLOAK_USERS'], | ||
username: 'superset-user', | ||
user_id: 'cab07278-c77b-4bc7-b154-bcbf01b7d35b', | ||
} | ||
) | ||
); | ||
|
||
expect(wrapper.find(`Link[to="${URL_LOCATION_UNIT}"]`)).toHaveLength(1); | ||
expect(wrapper.find(`Link[to="${URL_LOCATION_UNIT_GROUP}"]`)).toHaveLength(0); | ||
}); | ||
|
||
it('displays links for teams module', () => { | ||
const envModule = require('../../../../configs/env'); | ||
envModule.ENABLE_LOCATIONS = true; | ||
envModule.ENABLE_TEAMS = true; | ||
|
||
const wrapper = mount( | ||
envModule.ENABLE_INVENTORY = true; | ||
envModule.ENABLE_FORM_CONFIGURATION = true; | ||
envModule.ENABLE_TEAMS_ASSIGNMENT_MODULE = true; | ||
envModule.ENABLE_PRODUCT_CATALOGUE = true; | ||
envModule.ENABLE_PLANS = true; | ||
envModule.ENABLE_CARD_SUPPORT = true; | ||
envModule.ENABLE_USER_MANAGEMENT = true; | ||
envModule.ENABLE_LOCATIONS = true; | ||
envModule.ENABLE_TEAMS = true; | ||
envModule.OPENSRP_ROLES = { | ||
USERS: 'ROLE_EDIT_KEYCLOAK_USERS', | ||
PLANS: 'ROLE_VIEW_KEYCLOAK_USERS', | ||
CARD_SUPPORT: 'ROLE_VIEW_KEYCLOAK_USERS', | ||
PRODUCT_CATALOGUE: 'ROLE_VIEW_KEYCLOAK_USERS', | ||
FORM_CONFIGURATION: 'ROLE_VIEW_KEYCLOAK_USERS', | ||
LOCATIONS: 'ROLE_VIEW_KEYCLOAK_USERS', | ||
INVENTORY: 'ROLE_VIEW_KEYCLOAK_USERS', | ||
TEAMS: 'ROLE_VIEW_KEYCLOAK_USERS', | ||
}; | ||
render( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<Home /> | ||
</Router> | ||
</Provider> | ||
); | ||
|
||
expect(wrapper.find(`Link[to="${URL_TEAMS}"]`)).toHaveLength(1); | ||
const helmet = Helmet.peek(); | ||
expect(helmet.title).toEqual('OpenSRP Web'); | ||
const links = [...screen.queryAllByRole('link')]; | ||
expect(links.map((x) => x.textContent)).toEqual([ | ||
'Card Support', | ||
'Form Configuration', | ||
'Inventory', | ||
'Location Management', | ||
'Plans', | ||
'Product Catalogue', | ||
'Team Management', | ||
]); | ||
links.forEach((link) => { | ||
expect(link).toMatchSnapshot(link.textContent ?? undefined); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.