update the rest of the organizations tests

This commit is contained in:
John Mitchell
2019-04-22 15:11:28 -04:00
parent 54499dbf69
commit 667cbb0c20
9 changed files with 138 additions and 252 deletions

View File

@@ -1,12 +1,12 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { MemoryRouter } from 'react-router-dom'; import { MemoryRouter } from 'react-router-dom';
import { I18nProvider } from '@lingui/react'; import { I18nProvider } from '@lingui/react';
import { mountWithContexts } from '../../../enzymeHelpers';
import OrganizationListItem from '../../../../src/pages/Organizations/components/OrganizationListItem'; import OrganizationListItem from '../../../../src/pages/Organizations/components/OrganizationListItem';
describe('<OrganizationListItem />', () => { describe('<OrganizationListItem />', () => {
test('initially renders succesfully', () => { test('initially renders succesfully', () => {
mount( mountWithContexts(
<I18nProvider> <I18nProvider>
<MemoryRouter initialEntries={['/organizations']} initialIndex={0}> <MemoryRouter initialEntries={['/organizations']} initialIndex={0}>
<OrganizationListItem /> <OrganizationListItem />

View File

@@ -1,8 +1,6 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { MemoryRouter, Router } from 'react-router-dom';
import { createMemoryHistory } from 'history'; import { createMemoryHistory } from 'history';
import { I18nProvider } from '@lingui/react'; import { mountWithContexts } from '../../../enzymeHelpers';
import { sleep } from '../../../testUtils'; import { sleep } from '../../../testUtils';
import OrganizationTeamsList from '../../../../src/pages/Organizations/components/OrganizationTeamsList'; import OrganizationTeamsList from '../../../../src/pages/Organizations/components/OrganizationTeamsList';
@@ -20,9 +18,7 @@ describe('<OrganizationTeamsList />', () => {
}); });
test('initially renders succesfully', () => { test('initially renders succesfully', () => {
mount( mountWithContexts(
<I18nProvider>
<MemoryRouter>
<OrganizationTeamsList <OrganizationTeamsList
teams={mockData} teams={mockData}
itemCount={7} itemCount={7}
@@ -32,8 +28,6 @@ describe('<OrganizationTeamsList />', () => {
order_by: 'name', order_by: 'name',
}} }}
/> />
</MemoryRouter>
</I18nProvider>
); );
}); });
@@ -42,9 +36,7 @@ describe('<OrganizationTeamsList />', () => {
const history = createMemoryHistory({ const history = createMemoryHistory({
initialEntries: ['/organizations/1/teams'], initialEntries: ['/organizations/1/teams'],
}); });
const wrapper = mount( const wrapper = mountWithContexts(
<Router history={history}>
<I18nProvider>
<OrganizationTeamsList <OrganizationTeamsList
teams={mockData} teams={mockData}
itemCount={7} itemCount={7}
@@ -53,9 +45,7 @@ describe('<OrganizationTeamsList />', () => {
page_size: 5, page_size: 5,
order_by: 'name', order_by: 'name',
}} }}
/> />, { context: { router: { history } } }
</I18nProvider>
</Router>
); );
const toolbar = wrapper.find('DataListToolbar'); const toolbar = wrapper.find('DataListToolbar');
@@ -78,9 +68,7 @@ describe('<OrganizationTeamsList />', () => {
const history = createMemoryHistory({ const history = createMemoryHistory({
initialEntries: ['/organizations/1/teams'], initialEntries: ['/organizations/1/teams'],
}); });
const wrapper = mount( const wrapper = mountWithContexts(
<Router history={history}>
<I18nProvider>
<OrganizationTeamsList <OrganizationTeamsList
teams={mockData} teams={mockData}
itemCount={7} itemCount={7}
@@ -89,9 +77,7 @@ describe('<OrganizationTeamsList />', () => {
page_size: 5, page_size: 5,
order_by: 'name', order_by: 'name',
}} }}
/> />, { context: { router: { history } } }
</I18nProvider>
</Router>
); );
const pagination = wrapper.find('Pagination'); const pagination = wrapper.find('Pagination');

View File

@@ -1,7 +1,5 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme'; import { mountWithContexts } from '../../../../enzymeHelpers';
import { MemoryRouter } from 'react-router-dom';
import { I18nProvider } from '@lingui/react';
import OrganizationDetail from '../../../../../src/pages/Organizations/screens/Organization/OrganizationDetail'; import OrganizationDetail from '../../../../../src/pages/Organizations/screens/Organization/OrganizationDetail';
describe('<OrganizationDetail />', () => { describe('<OrganizationDetail />', () => {
@@ -14,33 +12,21 @@ describe('<OrganizationDetail />', () => {
}; };
test('initially renders succesfully', () => { test('initially renders succesfully', () => {
mount( mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/organizations/1']} initialIndex={0}>
<OrganizationDetail <OrganizationDetail
match={{ params: { id: '1' } }}
organization={mockDetails} organization={mockDetails}
/> />
</MemoryRouter>
</I18nProvider>
); );
}); });
test('should request instance groups from api', () => { test('should request instance groups from api', () => {
const getOrganizationInstanceGroups = jest.fn(); const getOrganizationInstanceGroups = jest.fn();
mount( mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/organizations/1']} initialIndex={0}>
<OrganizationDetail <OrganizationDetail
match={{ params: { id: '1' } }}
api={{
getOrganizationInstanceGroups
}}
handleHttpError={() => {}}
organization={mockDetails} organization={mockDetails}
/> />, { context: {
</MemoryRouter> network: { api: { getOrganizationInstanceGroups }, handleHttpError: () => {} }
</I18nProvider> } }
).find('OrganizationDetail'); ).find('OrganizationDetail');
expect(getOrganizationInstanceGroups).toHaveBeenCalledTimes(1); expect(getOrganizationInstanceGroups).toHaveBeenCalledTimes(1);
@@ -54,23 +40,12 @@ describe('<OrganizationDetail />', () => {
const getOrganizationInstanceGroups = jest.fn(() => ( const getOrganizationInstanceGroups = jest.fn(() => (
Promise.resolve({ data: { results: mockInstanceGroups } }) Promise.resolve({ data: { results: mockInstanceGroups } })
)); ));
const wrapper = mount( const wrapper = mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/organizations/1']} initialIndex={0}>
<OrganizationDetail <OrganizationDetail
match={{
path: '/organizations/:id',
url: '/organizations/1',
params: { id: '1' }
}}
organization={mockDetails} organization={mockDetails}
handleHttpError={() => {}} />, { context: {
api={{ network: { api: { getOrganizationInstanceGroups }, handleHttpError: () => {} }
getOrganizationInstanceGroups
} } } }
/>
</MemoryRouter>
</I18nProvider>
).find('OrganizationDetail'); ).find('OrganizationDetail');
await getOrganizationInstanceGroups(); await getOrganizationInstanceGroups();
@@ -78,19 +53,10 @@ describe('<OrganizationDetail />', () => {
}); });
test('should render Details', async () => { test('should render Details', async () => {
const wrapper = mount( const wrapper = mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/organizations/1']} initialIndex={0}>
<OrganizationDetail <OrganizationDetail
match={{
path: '/organizations/:id',
url: '/organizations/1',
params: { id: '1' }
}}
organization={mockDetails} organization={mockDetails}
/> />
</MemoryRouter>
</I18nProvider>
); );
const detailWrapper = wrapper.find('Detail'); const detailWrapper = wrapper.find('Detail');

View File

@@ -1,17 +1,12 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme'; import { mountWithContexts } from '../../../../enzymeHelpers';
import { MemoryRouter } from 'react-router-dom';
import { I18nProvider } from '@lingui/react';
import { NetworkProvider } from '../../../../../src/contexts/Network'; import OrganizationEdit from '../../../../../src/pages/Organizations/screens/Organization/OrganizationEdit';
import { _OrganizationEdit } from '../../../../../src/pages/Organizations/screens/Organization/OrganizationEdit';
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
describe('<OrganizationEdit />', () => { describe('<OrganizationEdit />', () => {
let api; let api;
let networkProviderValue;
const mockData = { const mockData = {
name: 'Foo', name: 'Foo',
@@ -30,26 +25,16 @@ describe('<OrganizationEdit />', () => {
associateInstanceGroup: jest.fn(), associateInstanceGroup: jest.fn(),
disassociate: jest.fn(), disassociate: jest.fn(),
}; };
networkProviderValue = {
api,
handleHttpError: () => {}
};
}); });
test('handleSubmit should call api update', () => { test('handleSubmit should call api update', () => {
const wrapper = mount( const wrapper = mountWithContexts(
<MemoryRouter> <OrganizationEdit
<I18nProvider>
<NetworkProvider value={networkProviderValue}>
<_OrganizationEdit
organization={mockData} organization={mockData}
api={api} />, { context: { network: {
handleHttpError={() => {}} api,
/> handleHttpError: () => {}
</NetworkProvider> } } }
</I18nProvider>
</MemoryRouter>
); );
const updatedOrgData = { const updatedOrgData = {
@@ -66,18 +51,13 @@ describe('<OrganizationEdit />', () => {
}); });
test('handleSubmit associates and disassociates instance groups', async () => { test('handleSubmit associates and disassociates instance groups', async () => {
const wrapper = mount( const wrapper = mountWithContexts(
<MemoryRouter> <OrganizationEdit
<I18nProvider>
<NetworkProvider value={networkProviderValue}>
<_OrganizationEdit
organization={mockData} organization={mockData}
api={api} />, { context: { network: {
handleHttpError={() => {}} api,
/> handleHttpError: () => {}
</NetworkProvider> } } }
</I18nProvider>
</MemoryRouter>
); );
const updatedOrgData = { const updatedOrgData = {
@@ -106,19 +86,16 @@ describe('<OrganizationEdit />', () => {
const history = { const history = {
push: jest.fn(), push: jest.fn(),
}; };
const wrapper = mount( const wrapper = mountWithContexts(
<MemoryRouter> <OrganizationEdit
<I18nProvider>
<NetworkProvider value={networkProviderValue}>
<_OrganizationEdit
organization={mockData} organization={mockData}
api={api} />, { context: {
handleHttpError={() => {}} network: {
history={history} api: { api },
/> handleHttpError: () => {}
</NetworkProvider> },
</I18nProvider> router: { history }
</MemoryRouter> } }
); );
expect(history.push).not.toHaveBeenCalled(); expect(history.push).not.toHaveBeenCalled();

View File

@@ -1,60 +1,45 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme'; import { mountWithContexts } from '../../../../enzymeHelpers';
import { MemoryRouter } from 'react-router-dom';
import { _OrganizationNotifications } from '../../../../../src/pages/Organizations/screens/Organization/OrganizationNotifications'; import OrganizationNotifications from '../../../../../src/pages/Organizations/screens/Organization/OrganizationNotifications';
describe('<OrganizationNotifications />', () => { describe('<OrganizationNotifications />', () => {
test('initially renders succesfully', () => { let api;
mount(
<MemoryRouter initialEntries={['/organizations/1']} initialIndex={0}> beforeEach(() => {
<_OrganizationNotifications api = {
match={{ path: '/organizations/:id/notifications', url: '/organizations/1/notifications' }}
location={{ search: '', pathname: '/organizations/1/notifications' }}
params={{}}
api={{
getOrganizationNotifications: jest.fn(), getOrganizationNotifications: jest.fn(),
getOrganizationNotificationSuccess: jest.fn(), getOrganizationNotificationSuccess: jest.fn(),
getOrganizationNotificationError: jest.fn(), getOrganizationNotificationError: jest.fn(),
createOrganizationNotificationSuccess: jest.fn(), createOrganizationNotificationSuccess: jest.fn(),
createOrganizationNotificationError: jest.fn() createOrganizationNotificationError: jest.fn()
}} };
handleHttpError={() => {}} });
/>
</MemoryRouter> test('initially renders succesfully', () => {
mountWithContexts(
<OrganizationNotifications />, { context: { network: {
api,
handleHttpError: () => {}
} } }
); );
}); });
test('handles api requests', () => { test('handles api requests', () => {
const getOrganizationNotifications = jest.fn(); const wrapper = mountWithContexts(
const getOrganizationNotificationSuccess = jest.fn(); <OrganizationNotifications />, { context: { network: {
const getOrganizationNotificationError = jest.fn(); api,
const createOrganizationNotificationSuccess = jest.fn(); handleHttpError: () => {}
const createOrganizationNotificationError = jest.fn(); } } }
const wrapper = mount(
<MemoryRouter initialEntries={['/organizations/1']} initialIndex={0}>
<_OrganizationNotifications
match={{ path: '/organizations/:id/notifications', url: '/organizations/1/notifications' }}
location={{ search: '', pathname: '/organizations/1/notifications' }}
params={{}}
api={{
getOrganizationNotifications,
getOrganizationNotificationSuccess,
getOrganizationNotificationError,
createOrganizationNotificationSuccess,
createOrganizationNotificationError
}}
handleHttpError={() => {}}
/>
</MemoryRouter>
).find('OrganizationNotifications'); ).find('OrganizationNotifications');
wrapper.instance().readOrgNotifications(1, { foo: 'bar' }); wrapper.instance().readOrgNotifications(1, { foo: 'bar' });
expect(getOrganizationNotifications).toHaveBeenCalledWith(1, { foo: 'bar' }); expect(api.getOrganizationNotifications).toHaveBeenCalledWith(1, { foo: 'bar' });
wrapper.instance().readOrgNotificationSuccess(1, { foo: 'bar' }); wrapper.instance().readOrgNotificationSuccess(1, { foo: 'bar' });
expect(getOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { foo: 'bar' }); expect(api.getOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { foo: 'bar' });
wrapper.instance().readOrgNotificationError(1, { foo: 'bar' }); wrapper.instance().readOrgNotificationError(1, { foo: 'bar' });
expect(getOrganizationNotificationError).toHaveBeenCalledWith(1, { foo: 'bar' }); expect(api.getOrganizationNotificationError).toHaveBeenCalledWith(1, { foo: 'bar' });
wrapper.instance().createOrgNotificationSuccess(1, { id: 2 }); wrapper.instance().createOrgNotificationSuccess(1, { id: 2 });
expect(createOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { id: 2 }); expect(api.createOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { id: 2 });
wrapper.instance().createOrgNotificationError(1, { id: 2 }); wrapper.instance().createOrgNotificationError(1, { id: 2 });
expect(createOrganizationNotificationError).toHaveBeenCalledWith(1, { id: 2 }); expect(api.createOrganizationNotificationError).toHaveBeenCalledWith(1, { id: 2 });
}); });
}); });

View File

@@ -1,12 +1,10 @@
import React from 'react'; import React from 'react';
import { mount, shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { MemoryRouter, Router } from 'react-router-dom';
import { I18nProvider } from '@lingui/react';
import { createMemoryHistory } from 'history'; import { createMemoryHistory } from 'history';
import { mountWithContexts } from '../../../../enzymeHelpers';
import { sleep } from '../../../../testUtils'; import { sleep } from '../../../../testUtils';
import OrganizationTeams, { _OrganizationTeams } from '../../../../../src/pages/Organizations/screens/Organization/OrganizationTeams'; import OrganizationTeams, { _OrganizationTeams } from '../../../../../src/pages/Organizations/screens/Organization/OrganizationTeams';
import OrganizationTeamsList from '../../../../../src/pages/Organizations/components/OrganizationTeamsList'; import OrganizationTeamsList from '../../../../../src/pages/Organizations/components/OrganizationTeamsList';
import { NetworkProvider } from '../../../../../src/contexts/Network';
const listData = { const listData = {
data: { data: {
@@ -38,19 +36,13 @@ describe('<OrganizationTeams />', () => {
test('should load teams on mount', () => { test('should load teams on mount', () => {
const readOrganizationTeamsList = jest.fn(() => Promise.resolve(listData)); const readOrganizationTeamsList = jest.fn(() => Promise.resolve(listData));
mount( mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/organizations/1']} initialIndex={0}>
<NetworkProvider
value={{ api: { readOrganizationTeamsList }, handleHttpError: () => {} }}
>
<OrganizationTeams <OrganizationTeams
id={1} id={1}
searchString="" searchString=""
/> />, { context: {
</NetworkProvider> network: { api: { readOrganizationTeamsList }, handleHttpError: () => {} } }
</MemoryRouter> }
</I18nProvider>
).find('OrganizationTeams'); ).find('OrganizationTeams');
expect(readOrganizationTeamsList).toHaveBeenCalledWith(1, { expect(readOrganizationTeamsList).toHaveBeenCalledWith(1, {
page: 1, page: 1,
@@ -61,19 +53,13 @@ describe('<OrganizationTeams />', () => {
test('should pass fetched teams to list component', async () => { test('should pass fetched teams to list component', async () => {
const readOrganizationTeamsList = jest.fn(() => Promise.resolve(listData)); const readOrganizationTeamsList = jest.fn(() => Promise.resolve(listData));
const wrapper = mount( const wrapper = mountWithContexts(
<I18nProvider>
<MemoryRouter>
<NetworkProvider
value={{ api: { readOrganizationTeamsList }, handleHttpError: () => {} }}
>
<OrganizationTeams <OrganizationTeams
id={1} id={1}
searchString="" searchString=""
/> />, { context: {
</NetworkProvider> network: { api: { readOrganizationTeamsList }, handleHttpError: () => {} } }
</MemoryRouter> }
</I18nProvider>
); );
await sleep(0); await sleep(0);
@@ -105,19 +91,14 @@ describe('<OrganizationTeams />', () => {
const history = createMemoryHistory({ const history = createMemoryHistory({
initialEntries: ['/organizations/1/teams'], initialEntries: ['/organizations/1/teams'],
}); });
const wrapper = mount( const wrapper = mountWithContexts(
<Router history={history}>
<I18nProvider>
<NetworkProvider
value={{ api: { readOrganizationTeamsList }, handleHttpError: () => {} }}
>
<OrganizationTeams <OrganizationTeams
id={1} id={1}
searchString="" searchString=""
/> />, { context: {
</NetworkProvider> network: { api: { readOrganizationTeamsList }, handleHttpError: () => {} },
</I18nProvider> router: { history }
</Router> } }
); );
await sleep(0); await sleep(0);
@@ -132,7 +113,6 @@ describe('<OrganizationTeams />', () => {
readOrganizationTeamsList.mockReturnValueOnce(page2Data); readOrganizationTeamsList.mockReturnValueOnce(page2Data);
history.push('/organizations/1/teams?page=2'); history.push('/organizations/1/teams?page=2');
wrapper.setProps({ history });
await sleep(0); await sleep(0);
wrapper.update(); wrapper.update();

View File

@@ -3,6 +3,7 @@ import React, {
Fragment Fragment
} from 'react'; } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { withRouter } from 'react-router-dom';
import { Title, EmptyState, EmptyStateIcon, EmptyStateBody } from '@patternfly/react-core'; import { Title, EmptyState, EmptyStateIcon, EmptyStateBody } from '@patternfly/react-core';
import { CubesIcon } from '@patternfly/react-icons'; import { CubesIcon } from '@patternfly/react-icons';
import { I18n, i18nMark } from '@lingui/react'; import { I18n, i18nMark } from '@lingui/react';
@@ -344,4 +345,4 @@ Notifications.propTypes = {
}; };
export { Notifications as _Notifications }; export { Notifications as _Notifications };
export default withNetwork(Notifications); export default withRouter(withNetwork(Notifications));

View File

@@ -1,5 +1,5 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Link } from 'react-router-dom'; import { Link, withRouter } from 'react-router-dom';
import { I18n } from '@lingui/react'; import { I18n } from '@lingui/react';
import { Trans, t } from '@lingui/macro'; import { Trans, t } from '@lingui/macro';
@@ -178,4 +178,4 @@ class OrganizationDetail extends Component {
} }
} }
export default withNetwork(OrganizationDetail); export default withRouter(withNetwork(OrganizationDetail));

View File

@@ -41,12 +41,6 @@ class OrganizationNotifications extends Component {
} }
render () { render () {
const {
location,
match,
history
} = this.props;
return ( return (
<NotificationsList <NotificationsList
onReadNotifications={this.readOrgNotifications} onReadNotifications={this.readOrgNotifications}
@@ -54,9 +48,6 @@ class OrganizationNotifications extends Component {
onReadError={this.readOrgNotificationError} onReadError={this.readOrgNotificationError}
onCreateSuccess={this.createOrgNotificationSuccess} onCreateSuccess={this.createOrgNotificationSuccess}
onCreateError={this.createOrgNotificationError} onCreateError={this.createOrgNotificationError}
match={match}
location={location}
history={history}
/> />
); );
} }