diff --git a/__tests__/pages/Organizations/components/OrganizationTeamsList.test.jsx b/__tests__/pages/Organizations/components/OrganizationTeamsList.test.jsx index 563636b9c9..87da53fb38 100644 --- a/__tests__/pages/Organizations/components/OrganizationTeamsList.test.jsx +++ b/__tests__/pages/Organizations/components/OrganizationTeamsList.test.jsx @@ -25,7 +25,7 @@ describe('', () => { {}} + onReadTeamsList={() => {}} removeRole={() => {}} /> @@ -40,7 +40,7 @@ describe('', () => { ({ data: { count: 1, results: mockData } })} + onReadTeamsList={() => ({ data: { count: 1, results: mockData } })} /> @@ -52,52 +52,52 @@ describe('', () => { }); }); - 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( ({ data: { count: 1, results: mockData } })} + onReadTeamsList={() => ({ data: { count: 1, results: mockData } })} /> ).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( ({ data: { count: 1, results: mockData } })} + onReadTeamsList={() => ({ data: { count: 1, results: mockData } })} /> ).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 }); diff --git a/__tests__/pages/Organizations/screens/Organization/OrganizationTeams.test.jsx b/__tests__/pages/Organizations/screens/Organization/OrganizationTeams.test.jsx index 58fe3c2996..d0ef146694 100644 --- a/__tests__/pages/Organizations/screens/Organization/OrganizationTeams.test.jsx +++ b/__tests__/pages/Organizations/screens/Organization/OrganizationTeams.test.jsx @@ -8,7 +8,7 @@ const mockAPITeamsList = { foo: 'bar', }; -const mockGetOrganizationTeamsList = () => Promise.resolve(mockAPITeamsList); +const readOrganizationTeamsList = () => Promise.resolve(mockAPITeamsList); describe('', () => { test('initially renders succesfully', () => { @@ -19,7 +19,7 @@ describe('', () => { location={{ search: '', pathname: '/organizations/1/teams' }} params={{}} api={{ - getOrganizationTeamsList: jest.fn(), + readOrganizationTeamsList: jest.fn(), }} /> @@ -34,12 +34,12 @@ describe('', () => { location={{ search: '', pathname: '/organizations/1/teams' }} params={{}} api={{ - getOrganizationTeamsList: mockGetOrganizationTeamsList + readOrganizationTeamsList }} /> ).find('OrganizationTeams'); - const teamsList = await wrapper.instance().getOrgTeamsList(); + const teamsList = await wrapper.instance().readOrganizationTeamsList(); expect(teamsList).toEqual(mockAPITeamsList); }); }); diff --git a/src/api.js b/src/api.js index b3f594cdd9..ba52325150 100644 --- a/src/api.js +++ b/src/api.js @@ -70,7 +70,7 @@ class APIClient { return this.http.get(endpoint, { params }); } - getOrganizationTeamsList (id, params = {}) { + readOrganizationTeamsList (id, params = {}) { const endpoint = `${API_ORGANIZATIONS}${id}/teams/`; return this.http.get(endpoint, { params }); diff --git a/src/pages/Organizations/components/OrganizationTeamsList.jsx b/src/pages/Organizations/components/OrganizationTeamsList.jsx index 60ab6a94f5..f240a26fe3 100644 --- a/src/pages/Organizations/components/OrganizationTeamsList.jsx +++ b/src/pages/Organizations/components/OrganizationTeamsList.jsx @@ -45,7 +45,7 @@ class OrganizationTeamsList extends React.Component { constructor (props) { super(props); - const { page, page_size } = this.getQueryParams(); + const { page, page_size } = this.readQueryParams(); this.state = { page, @@ -56,22 +56,22 @@ class OrganizationTeamsList extends React.Component { results: [], }; - this.fetchOrgTeamsList = this.fetchOrgTeamsList.bind(this); - this.onSetPage = this.onSetPage.bind(this); - this.onSort = this.onSort.bind(this); - this.getQueryParams = this.getQueryParams.bind(this); + this.readOrganizationTeamsList = this.readOrganizationTeamsList.bind(this); + this.handleSetPage = this.handleSetPage.bind(this); + this.handleSort = this.handleSort.bind(this); + this.reatQueryParams = this.readQueryParams.bind(this); } componentDidMount () { - const queryParams = this.getQueryParams(); + const queryParams = this.readQueryParams(); try { - this.fetchOrgTeamsList(queryParams); + this.readOrganizationTeamsList(queryParams); } catch (error) { this.setState({ error }); } } - onSetPage (pageNumber, pageSize) { + handleSetPage (pageNumber, pageSize) { const { sortOrder, sortedColumnKey } = this.state; const page = parseInt(pageNumber, 10); const page_size = parseInt(pageSize, 10); @@ -82,12 +82,12 @@ class OrganizationTeamsList extends React.Component { order_by = `-${order_by}`; } - const queryParams = this.getQueryParams({ page, page_size, order_by }); + const queryParams = this.readQueryParams({ page, page_size, order_by }); - this.fetchOrgTeamsList(queryParams); + this.readOrganizationTeamsList(queryParams); } - onSort (sortedColumnKey, sortOrder) { + handleSort (sortedColumnKey, sortOrder) { const { page_size } = this.state; let order_by = sortedColumnKey; @@ -96,12 +96,12 @@ class OrganizationTeamsList extends React.Component { order_by = `-${order_by}`; } - const queryParams = this.getQueryParams({ order_by, page_size }); + const queryParams = this.readQueryParams({ order_by, page_size }); - this.fetchOrgTeamsList(queryParams); + this.readOrganizationTeamsList(queryParams); } - getQueryParams (overrides = {}) { + readQueryParams (overrides = {}) { const { location } = this.props; const { search } = location; @@ -110,8 +110,8 @@ class OrganizationTeamsList extends React.Component { return Object.assign({}, this.defaultParams, searchParams, overrides); } - async fetchOrgTeamsList (queryParams) { - const { match, getTeamsList } = this.props; + async readOrganizationTeamsList (queryParams) { + const { match, onReadTeamsList } = this.props; const { page, page_size, order_by } = queryParams; @@ -126,7 +126,7 @@ class OrganizationTeamsList extends React.Component { try { const { data: { count = 0, results = [] } - } = await getTeamsList(match.params.id, queryParams); + } = await onReadTeamsList(match.params.id, queryParams); const pageCount = Math.ceil(count / page_size); const stateToUpdate = { @@ -178,7 +178,7 @@ class OrganizationTeamsList extends React.Component { sortOrder={sortOrder} columns={this.columns} onSearch={() => { }} - onSort={this.onSort} + onSort={this.handleSort} /> {results.map(({ url, id, name }) => ( @@ -198,7 +198,7 @@ class OrganizationTeamsList extends React.Component { page={page} pageCount={pageCount} page_size={page_size} - onSetPage={this.onSetPage} + onSetPage={this.handleSetPage} /> )} @@ -210,7 +210,7 @@ class OrganizationTeamsList extends React.Component { } OrganizationTeamsList.propTypes = { - getTeamsList: PropTypes.func.isRequired, + onReadTeamsList: PropTypes.func.isRequired, }; export default OrganizationTeamsList; diff --git a/src/pages/Organizations/screens/Organization/OrganizationTeams.jsx b/src/pages/Organizations/screens/Organization/OrganizationTeams.jsx index fb0ac01699..0fd6f9e517 100644 --- a/src/pages/Organizations/screens/Organization/OrganizationTeams.jsx +++ b/src/pages/Organizations/screens/Organization/OrganizationTeams.jsx @@ -5,12 +5,12 @@ class OrganizationTeams extends React.Component { constructor (props) { super(props); - this.getOrgTeamsList = this.getOrgTeamsList.bind(this); + this.readOrganizationTeamsList = this.readOrganizationTeamsList.bind(this); } - getOrgTeamsList (id, params) { + readOrganizationTeamsList (id, params) { const { api } = this.props; - return api.getOrganizationTeamsList(id, params); + return api.readOrganizationTeamsList(id, params); } render () { @@ -22,7 +22,7 @@ class OrganizationTeams extends React.Component { return (