updating PR

This commit is contained in:
Alex Corey
2019-04-30 09:48:42 -04:00
parent 1bae944b85
commit f4da620c4d

View File

@@ -67,21 +67,20 @@ describe('<_OrganizationsList />', () => {
); );
}); });
test('Puts 1 selected Org in state when onSelect is called.', async () => { test('Puts 1 selected Org in state when onSelect is called.', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<OrganizationsList /> <OrganizationsList />
).find('OrganizationsList'); ).find('OrganizationsList');
await setImmediate(async () => {
wrapper.setState({ wrapper.setState({
results: mockAPIOrgsList.data.results results: mockAPIOrgsList.data.results
});
wrapper.update();
}); });
wrapper.update();
wrapper.instance().onSelect(mockAPIOrgsList.data.results.slice(0, 1)); wrapper.instance().onSelect(mockAPIOrgsList.data.results.slice(0, 1));
expect(wrapper.state('selected').length).toBe(1); expect(wrapper.state('selected').length).toBe(1);
}); });
test('Puts all Orgs in state when onSelectAll is called.', async () => { test('Puts all Orgs in state when onSelectAll is called.', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<OrganizationsList /> <OrganizationsList />
).find('OrganizationsList'); ).find('OrganizationsList');
@@ -93,7 +92,7 @@ describe('<_OrganizationsList />', () => {
expect(wrapper.find('OrganizationsList').state().selected.length).toEqual(wrapper.state().results.length); expect(wrapper.find('OrganizationsList').state().selected.length).toEqual(wrapper.state().results.length);
}); });
test('orgsToDelete is 0 when close modal button is clicked.', async () => { test('orgsToDelete is 0 when close modal button is clicked.', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<OrganizationsList /> <OrganizationsList />
); );
@@ -113,7 +112,7 @@ describe('<_OrganizationsList />', () => {
wrapper.unmount(); wrapper.unmount();
}); });
test('orgsToDelete is 0 when cancel modal button is clicked.', async () => { test('orgsToDelete is 0 when cancel modal button is clicked.', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<OrganizationsList /> <OrganizationsList />
); );
@@ -133,7 +132,7 @@ describe('<_OrganizationsList />', () => {
wrapper.unmount(); wrapper.unmount();
}); });
test('api is called to delete Orgs for each org in orgsToDelete.', async () => { test('api is called to delete Orgs for each org in orgsToDelete.', () => {
const fetchOrganizations = jest.fn(() => wrapper.find('OrganizationsList').setState({ const fetchOrganizations = jest.fn(() => wrapper.find('OrganizationsList').setState({
results: [] results: []
})); }));
@@ -158,7 +157,7 @@ describe('<_OrganizationsList />', () => {
expect(api.destroyOrganization).toHaveBeenCalledTimes(component.state('results').length); expect(api.destroyOrganization).toHaveBeenCalledTimes(component.state('results').length);
}); });
test('call fetchOrganizations after org(s) have been deleted', async () => { test('call fetchOrganizations after org(s) have been deleted', () => {
const fetchOrgs = jest.spyOn(_OrganizationsList.prototype, 'fetchOrganizations'); const fetchOrgs = jest.spyOn(_OrganizationsList.prototype, 'fetchOrganizations');
const event = { preventDefault: () => { } }; const event = { preventDefault: () => { } };
wrapper = mountWithContexts( wrapper = mountWithContexts(
@@ -171,11 +170,11 @@ describe('<_OrganizationsList />', () => {
selected: mockAPIOrgsList.data.results.slice(0, 1) selected: mockAPIOrgsList.data.results.slice(0, 1)
}); });
const component = wrapper.find('OrganizationsList'); const component = wrapper.find('OrganizationsList');
await component.instance().handleOrgDelete(event); component.instance().handleOrgDelete(event);
expect(fetchOrgs).toBeCalled(); expect(fetchOrgs).toBeCalled();
}); });
test('url updates properly', async () => { test('url updates properly', () => {
const history = createMemoryHistory({ const history = createMemoryHistory({
initialEntries: ['organizations?order_by=name&page=1&page_size=5'], initialEntries: ['organizations?order_by=name&page=1&page_size=5'],
}); });
@@ -193,7 +192,7 @@ describe('<_OrganizationsList />', () => {
expect(history.location.search).toBe('?order_by=modified&page=1&page_size=5'); expect(history.location.search).toBe('?order_by=modified&page=1&page_size=5');
}); });
test('onSort sends the correct information to fetchOrganizations', async () => { test('onSort sends the correct information to fetchOrganizations', () => {
const history = createMemoryHistory({ const history = createMemoryHistory({
initialEntries: ['organizations?order_by=name&page=1&page_size=5'], initialEntries: ['organizations?order_by=name&page=1&page_size=5'],
}); });
@@ -226,15 +225,16 @@ describe('<_OrganizationsList />', () => {
} }
} }
); );
await setImmediate(async () => { await wrapper.setState({
wrapper.setState({ results: mockAPIOrgsList.data.results,
results: mockAPIOrgsList.data.results, selected: [...mockAPIOrgsList.data.results].push({
selected: [...mockAPIOrgsList.data.results].push({ id: 'a' }) name: 'Organization 6',
}); id: 'a',
wrapper.update(); })
}); });
wrapper.update();
const component = wrapper.find('OrganizationsList'); const component = wrapper.find('OrganizationsList');
component.instance().handleOrgDelete(); component.instance().handleOrgDelete();
expect(handleError).toBeCalled(); expect(handleError).toHaveBeenCalled();
}); });
}); });