From 0f044f6c217f4e0c546534766f754d035aa9c239 Mon Sep 17 00:00:00 2001 From: Kia Lam Date: Tue, 5 Oct 2021 13:04:37 -0700 Subject: [PATCH] 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(); }); });