From 0f044f6c217f4e0c546534766f754d035aa9c239 Mon Sep 17 00:00:00 2001 From: Kia Lam Date: Tue, 5 Oct 2021 13:04:37 -0700 Subject: [PATCH 1/3] Pass configurable qs to fetchJobsById function. --- awx/ui/src/components/JobList/JobList.js | 4 +- awx/ui/src/components/JobList/JobList.test.js | 55 +++++++++++++++++++ awx/ui/src/components/JobList/useWsJobs.js | 2 +- .../src/components/JobList/useWsJobs.test.js | 2 +- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/awx/ui/src/components/JobList/JobList.js b/awx/ui/src/components/JobList/JobList.js index f86c848cc6..b06437700c 100644 --- a/awx/ui/src/components/JobList/JobList.js +++ b/awx/ui/src/components/JobList/JobList.js @@ -100,8 +100,8 @@ function JobList({ defaultParams, showTypeColumn = false }) { // TODO: update QS_CONFIG to be safe for deps array const fetchJobsById = useCallback( - async (ids) => { - const params = parseQueryString(qsConfig, location.search); + async (ids, qs = {}) => { + const params = parseQueryString(qs, location.search); params.id__in = ids.join(','); const { data } = await UnifiedJobsAPI.read(params); return data.results; diff --git a/awx/ui/src/components/JobList/JobList.test.js b/awx/ui/src/components/JobList/JobList.test.js index 388592d5c3..69a0ba1ed1 100644 --- a/awx/ui/src/components/JobList/JobList.test.js +++ b/awx/ui/src/components/JobList/JobList.test.js @@ -265,6 +265,61 @@ describe('', () => { jest.restoreAllMocks(); }); + test('should query jobs list after delete API requests', async () => { + UnifiedJobsAPI.read.mockResolvedValue({ + data: { + count: 1, + results: [ + { + id: 1, + url: '/api/v2/project_updates/1', + name: 'job 1', + type: 'project_update', + status: 'running', + related: { + cancel: '/api/v2/project_updates/1/cancel', + }, + summary_fields: { + user_capabilities: { + delete: true, + start: true, + }, + }, + }, + ], + }, + }); + const jobListParams = { + order_by: '-finished', + not__launch_type: 'sync', + page: 1, + page_size: 20, + }; + let wrapper; + await act(async () => { + wrapper = mountWithContexts(); + }); + await waitForLoaded(wrapper); + + act(() => { + expect(UnifiedJobsAPI.read).toHaveBeenCalledTimes(1); + wrapper.find('DataListToolbar').invoke('onSelectAll')(true); + }); + wrapper.update(); + wrapper.find('JobListItem'); + expect( + wrapper.find('ToolbarDeleteButton').prop('itemsToDelete') + ).toHaveLength(1); + + await act(async () => { + wrapper.find('ToolbarDeleteButton').invoke('onDelete')(); + expect(UnifiedJobsAPI.read).toHaveBeenCalledTimes(1); + expect(UnifiedJobsAPI.read).toHaveBeenCalledWith(jobListParams); + }); + + jest.restoreAllMocks(); + }); + test('should display message about job running status', async () => { UnifiedJobsAPI.read.mockResolvedValue({ data: { diff --git a/awx/ui/src/components/JobList/useWsJobs.js b/awx/ui/src/components/JobList/useWsJobs.js index b2173950cc..b84868aab6 100644 --- a/awx/ui/src/components/JobList/useWsJobs.js +++ b/awx/ui/src/components/JobList/useWsJobs.js @@ -31,7 +31,7 @@ export default function useWsJobs(initialJobs, fetchJobsById, qsConfig) { return; } setJobsToFetch([]); - const newJobs = await fetchJobsById(throttledJobsToFetch); + const newJobs = await fetchJobsById(throttledJobsToFetch, {}); const deduplicated = newJobs.filter( (job) => !jobs.find((j) => j.id === job.id) ); diff --git a/awx/ui/src/components/JobList/useWsJobs.test.js b/awx/ui/src/components/JobList/useWsJobs.test.js index 1f2775188a..8c9201d8f7 100644 --- a/awx/ui/src/components/JobList/useWsJobs.test.js +++ b/awx/ui/src/components/JobList/useWsJobs.test.js @@ -123,7 +123,7 @@ describe('useWsJobs hook', () => { ); }); - expect(fetch).toHaveBeenCalledWith([2]); + expect(fetch).toHaveBeenCalledWith([2], {}); WS.clean(); }); }); From 4b7faea55265995a0b4765b9d43fa0411f50e599 Mon Sep 17 00:00:00 2001 From: Kia Lam Date: Wed, 6 Oct 2021 13:18:47 -0700 Subject: [PATCH 2/3] Remove comments and linter-disable. --- awx/ui/src/components/JobList/JobList.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/awx/ui/src/components/JobList/JobList.js b/awx/ui/src/components/JobList/JobList.js index b06437700c..9445e58c52 100644 --- a/awx/ui/src/components/JobList/JobList.js +++ b/awx/ui/src/components/JobList/JobList.js @@ -98,7 +98,6 @@ function JobList({ defaultParams, showTypeColumn = false }) { fetchJobs(); }, [fetchJobs]); - // TODO: update QS_CONFIG to be safe for deps array const fetchJobsById = useCallback( async (ids, qs = {}) => { const params = parseQueryString(qs, location.search); @@ -106,7 +105,7 @@ function JobList({ defaultParams, showTypeColumn = false }) { const { data } = await UnifiedJobsAPI.read(params); return data.results; }, - [location.search] // eslint-disable-line react-hooks/exhaustive-deps + [location.search] ); const jobs = useWsJobs(results, fetchJobsById, qsConfig); From 68f44c01ea6b2338e926d5da61f38b47682f4d52 Mon Sep 17 00:00:00 2001 From: Kia Lam Date: Thu, 7 Oct 2021 09:52:33 -0700 Subject: [PATCH 3/3] Rely on default qs value. --- awx/ui/src/components/JobList/useWsJobs.js | 2 +- awx/ui/src/components/JobList/useWsJobs.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/awx/ui/src/components/JobList/useWsJobs.js b/awx/ui/src/components/JobList/useWsJobs.js index b84868aab6..b2173950cc 100644 --- a/awx/ui/src/components/JobList/useWsJobs.js +++ b/awx/ui/src/components/JobList/useWsJobs.js @@ -31,7 +31,7 @@ export default function useWsJobs(initialJobs, fetchJobsById, qsConfig) { return; } setJobsToFetch([]); - const newJobs = await fetchJobsById(throttledJobsToFetch, {}); + const newJobs = await fetchJobsById(throttledJobsToFetch); const deduplicated = newJobs.filter( (job) => !jobs.find((j) => j.id === job.id) ); diff --git a/awx/ui/src/components/JobList/useWsJobs.test.js b/awx/ui/src/components/JobList/useWsJobs.test.js index 8c9201d8f7..1f2775188a 100644 --- a/awx/ui/src/components/JobList/useWsJobs.test.js +++ b/awx/ui/src/components/JobList/useWsJobs.test.js @@ -123,7 +123,7 @@ describe('useWsJobs hook', () => { ); }); - expect(fetch).toHaveBeenCalledWith([2], {}); + expect(fetch).toHaveBeenCalledWith([2]); WS.clean(); }); });