mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 18:09:57 -03:30
Pass configurable qs to fetchJobsById function.
This commit is contained in:
parent
87105a654c
commit
0f044f6c21
@ -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;
|
||||
|
||||
@ -265,6 +265,61 @@ describe('<JobList />', () => {
|
||||
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 () => {
|
||||
UnifiedJobsAPI.read.mockResolvedValue({
|
||||
data: {
|
||||
|
||||
@ -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)
|
||||
);
|
||||
|
||||
@ -123,7 +123,7 @@ describe('useWsJobs hook', () => {
|
||||
);
|
||||
});
|
||||
|
||||
expect(fetch).toHaveBeenCalledWith([2]);
|
||||
expect(fetch).toHaveBeenCalledWith([2], {});
|
||||
WS.clean();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user