Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions webpack/JobInvocationDetail/JobInvocationToolbarButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
enableRecurringLogic,
} from './JobInvocationActions';
import {
STATUS,
GET_REPORT_TEMPLATES,
GET_REPORT_TEMPLATE_INPUTS,
} from './JobInvocationConstants';
Expand All @@ -43,6 +42,11 @@ const JobInvocationToolbarButtons = ({ jobId, data }) => {
const [isActionOpen, setIsActionOpen] = useState(false);
const [reportTemplateJobId, setReportTemplateJobId] = useState(undefined);
const [templateInputId, setTemplateInputId] = useState(undefined);
const isCreateReportDisabled =
!useHasPermission('generate_report_templates') ||
task?.state === 'running' ||
reportTemplateJobId === undefined ||
templateInputId === undefined;
const queryParams = new URLSearchParams({
[`report_template_report[input_values][${templateInputId}][value]`]: jobId,
});
Expand Down Expand Up @@ -210,11 +214,7 @@ const JobInvocationToolbarButtons = ({ jobId, data }) => {
`/templates/report_templates/${reportTemplateJobId}/generate?${queryParams.toString()}`
)}
variant="secondary"
isDisabled={
!useHasPermission('generate_report_templates') ||
task?.state === STATUS.PENDING ||
templateInputId === undefined
}
isDisabled={isCreateReportDisabled}
>
{__(`Create report`)}
</Button>
Expand Down
35 changes: 35 additions & 0 deletions webpack/JobInvocationDetail/__tests__/MainInformation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,41 @@ describe('JobInvocationDetailPage', () => {
).toEqual(`/legacy/job_invocations/${jobId}`);
});

it('disables Create report when the job task state is running', async () => {
const jobId = jobInvocationData.id;
const store = mockStore({
...initialState,
JOB_INVOCATION_KEY: {
response: {
...jobInvocationData,
task: { ...jobInvocationData.task, state: 'running' },
},
},
CURRENT_PERMISSIONS: {
response: {
results: [{ name: 'generate_report_templates' }],
},
status: 'RESOLVED',
},
});

render(
<Provider store={store}>
<JobInvocationDetailPage
match={{ params: { id: `${jobId}` } }}
{...props}
/>
</Provider>
);

const createReportButton = screen.getByRole('link', {
name: 'Create report',
});

expect(createReportButton).toHaveAttribute('aria-disabled', 'true');
expect(createReportButton).toHaveClass('pf-m-disabled');
});

it('shows scheduled date', async () => {
const store = mockStore(initialStateScheduled);
render(
Expand Down
Loading