mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 03:17:38 -02:30
Merge pull request #11209 from kialam/fix-job-list-refresh
Pass configurable qs to fetchJobsById function.
This commit is contained in:
@@ -98,15 +98,14 @@ function JobList({ defaultParams, showTypeColumn = false }) {
|
|||||||
fetchJobs();
|
fetchJobs();
|
||||||
}, [fetchJobs]);
|
}, [fetchJobs]);
|
||||||
|
|
||||||
// TODO: update QS_CONFIG to be safe for deps array
|
|
||||||
const fetchJobsById = useCallback(
|
const fetchJobsById = useCallback(
|
||||||
async (ids) => {
|
async (ids, qs = {}) => {
|
||||||
const params = parseQueryString(qsConfig, location.search);
|
const params = parseQueryString(qs, location.search);
|
||||||
params.id__in = ids.join(',');
|
params.id__in = ids.join(',');
|
||||||
const { data } = await UnifiedJobsAPI.read(params);
|
const { data } = await UnifiedJobsAPI.read(params);
|
||||||
return data.results;
|
return data.results;
|
||||||
},
|
},
|
||||||
[location.search] // eslint-disable-line react-hooks/exhaustive-deps
|
[location.search]
|
||||||
);
|
);
|
||||||
|
|
||||||
const jobs = useWsJobs(results, fetchJobsById, qsConfig);
|
const jobs = useWsJobs(results, fetchJobsById, qsConfig);
|
||||||
|
|||||||
@@ -265,6 +265,61 @@ describe('<JobList />', () => {
|
|||||||
jest.restoreAllMocks();
|
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(<JobList />);
|
||||||
|
});
|
||||||
|
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 () => {
|
test('should display message about job running status', async () => {
|
||||||
UnifiedJobsAPI.read.mockResolvedValue({
|
UnifiedJobsAPI.read.mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
Reference in New Issue
Block a user