Skip to content

Commit 030d504

Browse files
committed
Fixes #39352 - Job inv page ignores remote_execution_job_invocation_report_template setting
1 parent 1fc6bc6 commit 030d504

2 files changed

Lines changed: 58 additions & 12 deletions

File tree

webpack/JobInvocationDetail/JobInvocationToolbarButtons.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,43 @@ const JobInvocationToolbarButtons = ({ jobId, data }) => {
6262
useEffect(() => {
6363
dispatch(
6464
get({
65-
key: GET_REPORT_TEMPLATES,
66-
url: '/api/report_templates',
67-
handleSuccess: ({ data: { results } }) => {
68-
setReportTemplateJobId(
69-
results.find(result => result.name === 'Job - Invocation Report')
70-
?.id
65+
key: 'GET_REPORT_TEMPLATE_SETTING',
66+
url: '/api/settings/remote_execution_job_invocation_report_template',
67+
handleSuccess: ({ data: { value } }) => {
68+
dispatch(
69+
get({
70+
key: GET_REPORT_TEMPLATES,
71+
url: '/api/report_templates',
72+
params: {
73+
search: `name="${value}"`,
74+
per_page: 1,
75+
},
76+
handleSuccess: ({ data: { results } }) => {
77+
setReportTemplateJobId(results[0]?.id);
78+
},
79+
handleError: () => {
80+
setReportTemplateJobId(undefined);
81+
},
82+
})
7183
);
7284
},
7385
handleError: () => {
74-
setReportTemplateJobId(undefined);
86+
dispatch(
87+
get({
88+
key: GET_REPORT_TEMPLATES,
89+
url: '/api/report_templates',
90+
params: {
91+
search: 'name="Job - Invocation Report"',
92+
per_page: 1,
93+
},
94+
handleSuccess: ({ data: { results } }) => {
95+
setReportTemplateJobId(results[0]?.id);
96+
},
97+
handleError: () => {
98+
setReportTemplateJobId(undefined);
99+
},
100+
})
101+
);
75102
},
76103
})
77104
);

webpack/JobInvocationDetail/__tests__/MainInformation.test.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ jest.spyOn(api, 'get');
3434
// Mock toLocaleString to always use UTC timezone for consistent test results
3535
const originalToLocaleString = Date.prototype.toLocaleString;
3636
beforeAll(() => {
37-
// eslint-disable-next-line no-extend-native
38-
Date.prototype.toLocaleString = function (locale, options) {
39-
return originalToLocaleString.call(this, locale, { ...options, timeZone: 'UTC' });
37+
// eslint-disable-next-line no-extend-native, func-names
38+
Date.prototype.toLocaleString = function(locale, options) {
39+
return originalToLocaleString.call(this, locale, {
40+
...options,
41+
timeZone: 'UTC',
42+
});
4043
};
4144
});
4245
afterAll(() => {
@@ -76,7 +79,12 @@ const initialStateScheduled = {
7679
};
7780

7881
api.get.mockImplementation(({ handleSuccess, ...action }) => {
79-
if (action.key === 'GET_REPORT_TEMPLATES') {
82+
if (action.key === 'GET_REPORT_TEMPLATE_SETTING') {
83+
handleSuccess &&
84+
handleSuccess({
85+
data: { value: 'Job - Invocation Report' },
86+
});
87+
} else if (action.key === 'GET_REPORT_TEMPLATES') {
8088
handleSuccess &&
8189
handleSuccess({
8290
data: mockReportTemplatesResponse,
@@ -229,7 +237,15 @@ describe('JobInvocationDetailPage', () => {
229237
);
230238

231239
const expectedActions = [
232-
{ key: GET_REPORT_TEMPLATES, url: '/api/report_templates' },
240+
{
241+
key: GET_REPORT_TEMPLATES,
242+
url: '/api/report_templates',
243+
params: { search: 'name="Job - Invocation Report"', per_page: 1 },
244+
},
245+
{
246+
key: 'GET_REPORT_TEMPLATE_SETTING',
247+
url: '/api/settings/remote_execution_job_invocation_report_template',
248+
},
233249
{
234250
key: JOB_INVOCATION_KEY,
235251
url: `/api/job_invocations/${jobId}?host_status=true`,
@@ -278,6 +294,9 @@ describe('JobInvocationDetailPage', () => {
278294
if (expectedAction.url) {
279295
expect(actualActions[index].url).toEqual(expectedAction.url);
280296
}
297+
if (expectedAction.params) {
298+
expect(actualActions[index].params).toEqual(expectedAction.params);
299+
}
281300
}
282301
});
283302
});

0 commit comments

Comments
 (0)