mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 01:17:35 -02:30
Pass configurable qs to fetchJobsById function.
This commit is contained in:
@@ -100,8 +100,8 @@ function JobList({ defaultParams, showTypeColumn = false }) {
|
|||||||
|
|
||||||
// TODO: update QS_CONFIG to be safe for deps array
|
// 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;
|
||||||
|
|||||||
@@ -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: {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default function useWsJobs(initialJobs, fetchJobsById, qsConfig) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setJobsToFetch([]);
|
setJobsToFetch([]);
|
||||||
const newJobs = await fetchJobsById(throttledJobsToFetch);
|
const newJobs = await fetchJobsById(throttledJobsToFetch, {});
|
||||||
const deduplicated = newJobs.filter(
|
const deduplicated = newJobs.filter(
|
||||||
(job) => !jobs.find((j) => j.id === job.id)
|
(job) => !jobs.find((j) => j.id === job.id)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ describe('useWsJobs hook', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(fetch).toHaveBeenCalledWith([2]);
|
expect(fetch).toHaveBeenCalledWith([2], {});
|
||||||
WS.clean();
|
WS.clean();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user