Skip to content

Commit 77e71ac

Browse files
committed
Fixes #39352 - Job inv page ignores remote_execution_job_invocation_report_template setting
1 parent 709bb12 commit 77e71ac

3 files changed

Lines changed: 96 additions & 13 deletions

File tree

webpack/JobInvocationDetail/JobInvocationConstants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const GET_TEMPLATE_INVOCATIONS = 'GET_TEMPLATE_INVOCATIONS';
1313
export const CHANGE_ENABLED_RECURRING_LOGIC = 'CHANGE_ENABLED_RECURRING_LOGIC';
1414
export const CANCEL_RECURRING_LOGIC = 'CANCEL_RECURRING_LOGIC';
1515
export const GET_REPORT_TEMPLATES = 'GET_REPORT_TEMPLATES';
16+
export const GET_REPORT_TEMPLATE_SETTING = 'GET_REPORT_TEMPLATE_SETTING';
1617
export const GET_REPORT_TEMPLATE_INPUTS = 'GET_REPORT_TEMPLATE_INPUTS';
1718
export const JOB_INVOCATION_HOSTS = 'JOB_INVOCATION_HOSTS';
1819
export const GET_TEMPLATE_INVOCATION = 'GET_TEMPLATE_INVOCATION';

webpack/JobInvocationDetail/JobInvocationToolbarButtons.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import {
2424
STATUS,
2525
GET_REPORT_TEMPLATES,
26+
GET_REPORT_TEMPLATE_SETTING,
2627
GET_REPORT_TEMPLATE_INPUTS,
2728
} from './JobInvocationConstants';
2829
import { selectTaskCancelable } from './JobInvocationSelectors';
@@ -80,22 +81,37 @@ const JobInvocationToolbarButtons = ({ jobId, data }) => {
8081

8182
useEffect(() => {
8283
let isMounted = true;
84+
const fetchReportTemplate = templateName => {
85+
dispatch(
86+
get({
87+
key: GET_REPORT_TEMPLATES,
88+
url: '/api/report_templates',
89+
params: {
90+
search: `name="${templateName}"`,
91+
per_page: 1,
92+
},
93+
handleSuccess: ({ data: { results } }) => {
94+
if (isMounted) {
95+
setReportTemplateJobId(results[0]?.id);
96+
}
97+
},
98+
handleError: () => {
99+
if (isMounted) {
100+
setReportTemplateJobId(undefined);
101+
}
102+
},
103+
})
104+
);
105+
};
83106
dispatch(
84107
get({
85-
key: GET_REPORT_TEMPLATES,
86-
url: '/api/report_templates',
87-
handleSuccess: ({ data: { results } }) => {
88-
if (isMounted) {
89-
setReportTemplateJobId(
90-
results.find(result => result.name === 'Job - Invocation Report')
91-
?.id
92-
);
93-
}
108+
key: GET_REPORT_TEMPLATE_SETTING,
109+
url: '/api/settings/remote_execution_job_invocation_report_template',
110+
handleSuccess: ({ data: { value } }) => {
111+
fetchReportTemplate(value);
94112
},
95113
handleError: () => {
96-
if (isMounted) {
97-
setReportTemplateJobId(undefined);
98-
}
114+
fetchReportTemplate('Job - Invocation Report');
99115
},
100116
})
101117
);

webpack/JobInvocationDetail/__tests__/MainInformation.test.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
CANCEL_RECURRING_LOGIC,
3030
CHANGE_ENABLED_RECURRING_LOGIC,
3131
GET_REPORT_TEMPLATES,
32+
GET_REPORT_TEMPLATE_SETTING,
3233
GET_REPORT_TEMPLATE_INPUTS,
3334
GET_TASK,
3435
JOB_INVOCATION_KEY,
@@ -85,7 +86,13 @@ jest.mock('foremanReact/routes/common/PageLayout/PageLayout', () =>
8586

8687
const setupApiMocks = () => {
8788
api.get.mockImplementation(({ handleSuccess, key, ...action }) => {
88-
if (key === GET_REPORT_TEMPLATES) {
89+
if (key === GET_REPORT_TEMPLATE_SETTING) {
90+
if (handleSuccess) {
91+
handleSuccess({
92+
data: { value: 'Job - Invocation Report' },
93+
});
94+
}
95+
} else if (key === GET_REPORT_TEMPLATES) {
8996
if (handleSuccess) {
9097
handleSuccess({
9198
data: mockReportTemplatesResponse,
@@ -323,6 +330,59 @@ describe('JobInvocationDetailPage', () => {
323330
expect(createReportButton).toHaveClass('pf-m-disabled');
324331
});
325332

333+
it('falls back to default template name when settings API fails', async () => {
334+
api.get.mockImplementation(
335+
({ handleSuccess, handleError, key, ...action }) => {
336+
if (key === GET_REPORT_TEMPLATE_SETTING) {
337+
if (handleError) {
338+
handleError({ message: 'Not found' });
339+
}
340+
} else if (key === GET_REPORT_TEMPLATES) {
341+
if (handleSuccess) {
342+
handleSuccess({
343+
data: mockReportTemplatesResponse,
344+
});
345+
}
346+
} else if (key === GET_REPORT_TEMPLATE_INPUTS) {
347+
if (handleSuccess) {
348+
handleSuccess({
349+
data: mockReportTemplateInputsResponse,
350+
});
351+
}
352+
}
353+
354+
return { type: 'get', key, ...action };
355+
}
356+
);
357+
358+
const jobId = jobInvocationData.id;
359+
360+
renderJobInvocationDetailPage(createJobInvocationDetailState(), {
361+
jobId,
362+
});
363+
364+
expect(api.get).toHaveBeenCalledWith(
365+
expect.objectContaining({
366+
key: GET_REPORT_TEMPLATE_SETTING,
367+
url: '/api/settings/remote_execution_job_invocation_report_template',
368+
})
369+
);
370+
expect(api.get).toHaveBeenCalledWith(
371+
expect.objectContaining({
372+
key: GET_REPORT_TEMPLATES,
373+
url: '/api/report_templates',
374+
params: expect.objectContaining({
375+
search: 'name="Job - Invocation Report"',
376+
}),
377+
})
378+
);
379+
expect(screen.getByText('Create report').getAttribute('href')).toEqual(
380+
foremanUrl(
381+
`/templates/report_templates/${mockReportTemplatesResponse.results[0].id}/generate?report_template_report%5Binput_values%5D%5B${mockReportTemplateInputsResponse.results[0].id}%5D%5Bvalue%5D=${jobId}`
382+
)
383+
);
384+
});
385+
326386
it('should dispatch global actions', async () => {
327387
const actualActions = jest.requireActual('../JobInvocationActions');
328388
const { getTask } = jest.requireMock('../JobInvocationActions');
@@ -342,6 +402,12 @@ describe('JobInvocationDetailPage', () => {
342402
{ jobId }
343403
);
344404

405+
expect(api.get).toHaveBeenCalledWith(
406+
expect.objectContaining({
407+
key: GET_REPORT_TEMPLATE_SETTING,
408+
url: '/api/settings/remote_execution_job_invocation_report_template',
409+
})
410+
);
345411
expect(api.get).toHaveBeenCalledWith(
346412
expect.objectContaining({
347413
key: GET_REPORT_TEMPLATES,

0 commit comments

Comments
 (0)