diff --git a/webpack/components/AnsibleHostDetail/components/JobsTab/JobsTabHelper.js b/webpack/components/AnsibleHostDetail/components/JobsTab/JobsTabHelper.js
index dfac587fd..2fab9cea8 100644
--- a/webpack/components/AnsibleHostDetail/components/JobsTab/JobsTabHelper.js
+++ b/webpack/components/AnsibleHostDetail/components/JobsTab/JobsTabHelper.js
@@ -77,3 +77,23 @@ export const useCancelMutation = (resourceName, resourceId) =>
},
],
});
+
+export const readableCron = (cron = '') => {
+ if (cron.match(/(\d+ \* \* \* \*)/)) {
+ return 'hourly';
+ }
+
+ if (cron.match(/(\d+ \d+ \* \* \*)/)) {
+ return 'daily';
+ }
+
+ if (cron.match(/(\d+ \d+ \* \* \d+)/)) {
+ return 'weekly';
+ }
+
+ if (cron.match(/(\d+ \d+ \d+ \* \*)/)) {
+ return 'monthly';
+ }
+
+ return 'custom';
+};
diff --git a/webpack/components/AnsibleHostDetail/components/JobsTab/PreviousJobsTable.js b/webpack/components/AnsibleHostDetail/components/JobsTab/PreviousJobsTable.js
index ed553752e..a2ccc15a6 100644
--- a/webpack/components/AnsibleHostDetail/components/JobsTab/PreviousJobsTable.js
+++ b/webpack/components/AnsibleHostDetail/components/JobsTab/PreviousJobsTable.js
@@ -16,6 +16,7 @@ import Pagination from 'foremanReact/components/Pagination';
import { decodeId } from '../../../../globalIdHelper';
import withLoading from '../../../withLoading';
+import { readableCron } from './JobsTabHelper';
const PreviousJobsTable = ({ history, totalCount, jobs, pagination }) => {
const columns = [
@@ -61,7 +62,7 @@ const PreviousJobsTable = ({ history, totalCount, jobs, pagination }) => {
|
- {job.recurringLogic.cronLine} |
+ {readableCron(job.recurringLogic.cronLine)} |
))}
diff --git a/webpack/components/AnsibleHostDetail/components/JobsTab/RecurringJobsTable.js b/webpack/components/AnsibleHostDetail/components/JobsTab/RecurringJobsTable.js
index 4ee4c39fe..a7dcba458 100644
--- a/webpack/components/AnsibleHostDetail/components/JobsTab/RecurringJobsTable.js
+++ b/webpack/components/AnsibleHostDetail/components/JobsTab/RecurringJobsTable.js
@@ -14,7 +14,7 @@ import {
Td,
} from '@patternfly/react-table';
-import { useCancelMutation } from './JobsTabHelper';
+import { useCancelMutation, readableCron } from './JobsTabHelper';
import withLoading from '../../../withLoading';
import { decodeId } from '../../../../globalIdHelper';
@@ -74,7 +74,7 @@ const RecurringJobsTable = ({ jobs, resourceName, resourceId }) => {
{job.description}
- {job.recurringLogic.cronLine} |
+ {readableCron(job.recurringLogic.cronLine)} |
|
diff --git a/webpack/components/AnsibleHostDetail/components/JobsTab/__test__/JobsTab.test.js b/webpack/components/AnsibleHostDetail/components/JobsTab/__test__/JobsTab.test.js
index 420deafd5..ca1e41047 100644
--- a/webpack/components/AnsibleHostDetail/components/JobsTab/__test__/JobsTab.test.js
+++ b/webpack/components/AnsibleHostDetail/components/JobsTab/__test__/JobsTab.test.js
@@ -18,6 +18,7 @@ import {
import * as toasts from '../../../../../toastHelper';
import { toCron } from '../NewRecurringJobHelper';
+import { readableCron } from '../JobsTabHelper';
import {
tick,
@@ -49,8 +50,10 @@ describe('JobsTab', () => {
.map(element => expect(element).toBeInTheDocument());
expect(screen.getByText('Scheduled recurring jobs')).toBeInTheDocument();
expect(screen.getByText('Previously executed jobs')).toBeInTheDocument();
- expect(screen.getByText(toCron(futureDate, 'weekly'))).toBeInTheDocument();
- expect(screen.getByText('54 10 15 * *')).toBeInTheDocument();
+ expect(
+ screen.getByText(readableCron(toCron(futureDate, 'weekly')))
+ ).toBeInTheDocument();
+ expect(screen.getByText('monthly')).toBeInTheDocument();
});
it('should show empty state', async () => {
render(
@@ -129,7 +132,9 @@ describe('JobsTab', () => {
message: 'Ansible job was successfully created.',
});
await waitFor(tick);
- expect(screen.getByText(toCron(futureDate, 'weekly'))).toBeInTheDocument();
+ expect(
+ screen.getByText(readableCron(toCron(futureDate, 'weekly')))
+ ).toBeInTheDocument();
expect(screen.getByText('in 3 days')).toBeInTheDocument();
expect(
screen.queryByText('No config job for Ansible roles scheduled')
diff --git a/webpack/components/AnsibleHostDetail/components/JobsTab/__test__/JobsTabHelper.test.js b/webpack/components/AnsibleHostDetail/components/JobsTab/__test__/JobsTabHelper.test.js
new file mode 100644
index 000000000..5de819f67
--- /dev/null
+++ b/webpack/components/AnsibleHostDetail/components/JobsTab/__test__/JobsTabHelper.test.js
@@ -0,0 +1,11 @@
+import { readableCron } from '../JobsTabHelper';
+
+describe('JobTabsHelper', () => {
+ it('readableCron', () => {
+ expect(readableCron('01 * * * *')).toBe('hourly');
+ expect(readableCron('01 01 * * *')).toBe('daily');
+ expect(readableCron('01 01 * * 01')).toBe('weekly');
+ expect(readableCron('01 01 01 * *')).toBe('monthly');
+ expect(readableCron()).toBe('custom');
+ });
+});
diff --git a/webpack/routes/HostgroupJobs/__test__/HostgroupJobs.test.js b/webpack/routes/HostgroupJobs/__test__/HostgroupJobs.test.js
index aa3390214..ffd09f7fe 100644
--- a/webpack/routes/HostgroupJobs/__test__/HostgroupJobs.test.js
+++ b/webpack/routes/HostgroupJobs/__test__/HostgroupJobs.test.js
@@ -24,6 +24,7 @@ import {
} from '../../../testHelper';
import { toCron } from '../../../components/AnsibleHostDetail/components/JobsTab/NewRecurringJobHelper';
+import { readableCron } from '../../../components/AnsibleHostDetail/components/JobsTab/JobsTabHelper';
const TestComponent = withRedux(withRouter(withMockedProvider(HostgroupJobs)));
@@ -46,7 +47,7 @@ describe('HostgroupJobs', () => {
.map(element => expect(element).toBeInTheDocument());
expect(screen.getByText('Scheduled recurring jobs')).toBeInTheDocument();
expect(screen.getByText('Previously executed jobs')).toBeInTheDocument();
- expect(screen.getByText('54 10 15 * *')).toBeInTheDocument();
+ expect(screen.getByText(readableCron('54 10 15 * *'))).toBeInTheDocument();
});
it('should show empty state', async () => {
render(
@@ -103,7 +104,9 @@ describe('HostgroupJobs', () => {
type: 'success',
message: 'Ansible job was successfully created.',
});
- expect(screen.getByText(toCron(futureDate, 'weekly'))).toBeInTheDocument();
+ expect(
+ screen.getByText(readableCron(toCron(futureDate, 'weekly')))
+ ).toBeInTheDocument();
expect(screen.getByText('in 3 days')).toBeInTheDocument();
expect(
screen.queryByText('No config job for Ansible roles scheduled')