rename org teams functions based on guide

This commit is contained in:
John Mitchell
2019-03-26 17:04:34 -04:00
parent 7e414ace5a
commit 5419434daa
5 changed files with 43 additions and 43 deletions

View File

@@ -25,7 +25,7 @@ describe('<OrganizationTeamsList />', () => {
<OrganizationTeamsList
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '1' } }}
location={{ search: '', pathname: '/organizations/1/teams' }}
getTeamsList={() => {}}
onReadTeamsList={() => {}}
removeRole={() => {}}
/>
</MemoryRouter>
@@ -40,7 +40,7 @@ describe('<OrganizationTeamsList />', () => {
<OrganizationTeamsList
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
location={{ search: '', pathname: '/organizations/1/teams' }}
getTeamsList={() => ({ data: { count: 1, results: mockData } })}
onReadTeamsList={() => ({ data: { count: 1, results: mockData } })}
/>
</MemoryRouter>
</I18nProvider>
@@ -52,52 +52,52 @@ describe('<OrganizationTeamsList />', () => {
});
});
test('onSort being passed properly to DataListToolbar component', async (done) => {
const onSort = jest.spyOn(OrganizationTeamsList.prototype, 'onSort');
test('handleSort being passed properly to DataListToolbar component', async (done) => {
const handleSort = jest.spyOn(OrganizationTeamsList.prototype, 'handleSort');
const wrapper = mount(
<I18nProvider>
<MemoryRouter>
<OrganizationTeamsList
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
location={{ search: '', pathname: '/organizations/1/teams' }}
getTeamsList={() => ({ data: { count: 1, results: mockData } })}
onReadTeamsList={() => ({ data: { count: 1, results: mockData } })}
/>
</MemoryRouter>
</I18nProvider>
).find('OrganizationTeamsList');
expect(onSort).not.toHaveBeenCalled();
expect(handleSort).not.toHaveBeenCalled();
setImmediate(() => {
const rendered = wrapper.update();
rendered.find('button[aria-label="Sort"]').simulate('click');
expect(onSort).toHaveBeenCalled();
expect(handleSort).toHaveBeenCalled();
done();
});
});
test('onSetPage calls getQueryParams fetchOrgTeamsList ', () => {
const spyQueryParams = jest.spyOn(OrganizationTeamsList.prototype, 'getQueryParams');
const spyFetch = jest.spyOn(OrganizationTeamsList.prototype, 'fetchOrgTeamsList');
test('handleSetPage calls readQueryParams and readOrganizationTeamsList ', () => {
const spyQueryParams = jest.spyOn(OrganizationTeamsList.prototype, 'readQueryParams');
const spyFetch = jest.spyOn(OrganizationTeamsList.prototype, 'readOrganizationTeamsList');
const wrapper = mount(
<I18nProvider>
<MemoryRouter>
<OrganizationTeamsList
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
location={{ search: '', pathname: '/organizations/1/teams' }}
getTeamsList={() => ({ data: { count: 1, results: mockData } })}
onReadTeamsList={() => ({ data: { count: 1, results: mockData } })}
/>
</MemoryRouter>
</I18nProvider>
).find('OrganizationTeamsList');
wrapper.instance().onSetPage(2, 10);
wrapper.instance().handleSetPage(2, 10);
expect(spyQueryParams).toHaveBeenCalled();
expect(spyFetch).toHaveBeenCalled();
wrapper.setState({ sortOrder: 'descending' });
wrapper.instance().onSetPage(3, 5);
wrapper.instance().handleSetPage(3, 5);
expect(spyQueryParams).toHaveBeenCalled();
expect(spyFetch).toHaveBeenCalled();
const queryParamCalls = spyQueryParams.mock.calls;
// make sure last two getQueryParams calls
// make sure last two readQueryParams calls
// were called with the correct arguments
expect(queryParamCalls[queryParamCalls.length - 2][0])
.toEqual({ order_by: 'name', page: 2, page_size: 10 });

View File

@@ -8,7 +8,7 @@ const mockAPITeamsList = {
foo: 'bar',
};
const mockGetOrganizationTeamsList = () => Promise.resolve(mockAPITeamsList);
const readOrganizationTeamsList = () => Promise.resolve(mockAPITeamsList);
describe('<OrganizationTeams />', () => {
test('initially renders succesfully', () => {
@@ -19,7 +19,7 @@ describe('<OrganizationTeams />', () => {
location={{ search: '', pathname: '/organizations/1/teams' }}
params={{}}
api={{
getOrganizationTeamsList: jest.fn(),
readOrganizationTeamsList: jest.fn(),
}}
/>
</MemoryRouter>
@@ -34,12 +34,12 @@ describe('<OrganizationTeams />', () => {
location={{ search: '', pathname: '/organizations/1/teams' }}
params={{}}
api={{
getOrganizationTeamsList: mockGetOrganizationTeamsList
readOrganizationTeamsList
}}
/>
</MemoryRouter>
).find('OrganizationTeams');
const teamsList = await wrapper.instance().getOrgTeamsList();
const teamsList = await wrapper.instance().readOrganizationTeamsList();
expect(teamsList).toEqual(mockAPITeamsList);
});
});