@@ -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
8687const 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