Add namespacing for query params (#205)

* use qs utils to namespace query params

* refactor Lookup and SelectResource Steps to use PaginatedDataList

* preserve query params when adding new ones

* require namespace for QS Configs
This commit is contained in:
Keith Grant
2019-05-15 10:06:14 -04:00
committed by GitHub
parent d59975c1ad
commit 4407aeac20
19 changed files with 2656 additions and 2648 deletions

View File

@@ -1,7 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import { mountWithContexts } from '../../../../enzymeHelpers';
import { sleep } from '../../../../testUtils';
import OrganizationTeams, { _OrganizationTeams } from '../../../../../src/pages/Organizations/screens/Organization/OrganizationTeams';
@@ -68,65 +66,14 @@ describe('<OrganizationTeams />', () => {
const list = wrapper.find('PaginatedDataList');
expect(list.prop('items')).toEqual(listData.data.results);
expect(list.prop('itemCount')).toEqual(listData.data.count);
expect(list.prop('queryParams')).toEqual({
page: 1,
page_size: 5,
order_by: 'name',
});
});
test('should pass queryParams to PaginatedDataList', async () => {
const page1Data = listData;
const page2Data = {
data: {
count: 7,
results: [
{ id: 6, name: 'six', url: '/org/team/6' },
{ id: 7, name: 'seven', url: '/org/team/7' },
]
}
};
const readOrganizationTeamsList = jest.fn();
readOrganizationTeamsList.mockReturnValueOnce(page1Data);
const history = createMemoryHistory({
initialEntries: ['/organizations/1/teams'],
});
const wrapper = mountWithContexts(
<Router history={history}>
<OrganizationTeams
id={1}
searchString=""
/>
</Router>,
{ context: {
network: {
api: { readOrganizationTeamsList },
handleHttpError: () => {}
},
router: false,
} }
);
await sleep(0);
wrapper.update();
const list = wrapper.find('PaginatedDataList');
expect(list.prop('queryParams')).toEqual({
page: 1,
page_size: 5,
order_by: 'name',
});
readOrganizationTeamsList.mockReturnValueOnce(page2Data);
history.push('/organizations/1/teams?page=2');
await sleep(0);
wrapper.update();
const list2 = wrapper.find('PaginatedDataList');
expect(list2.prop('queryParams')).toEqual({
page: 2,
page_size: 5,
order_by: 'name',
expect(list.prop('qsConfig')).toEqual({
namespace: 'team',
defaultParams: {
page: 1,
page_size: 5,
order_by: 'name',
},
integerFields: ['page', 'page_size'],
});
});
});

View File

@@ -146,24 +146,6 @@ describe('<OrganizationsList />', () => {
expect(fetchOrgs).toBeCalled();
});
test('url updates properly', () => {
const history = createMemoryHistory({
initialEntries: ['organizations?order_by=name&page=1&page_size=5'],
});
wrapper = mountWithContexts(
<OrganizationsList />, {
context: { router: { history } }
}
);
const component = wrapper.find('OrganizationsList');
component.instance().updateUrl({
page: 1,
page_size: 5,
order_by: 'modified'
});
expect(history.location.search).toBe('?order_by=modified&page=1&page_size=5');
});
test('error is thrown when org not successfully deleted from api', async () => {
const history = createMemoryHistory({
initialEntries: ['organizations?order_by=name&page=1&page_size=5'],