1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-30 22:21:13 +03:00

Convert elapsed days into hours and add unit test

This commit is contained in:
Marliana Lara 2020-02-10 16:55:33 -05:00
parent debbac5c78
commit 69049a4427
No known key found for this signature in database
GPG Key ID: 38C73B40DFA809EE
2 changed files with 25 additions and 10 deletions

View File

@ -41,17 +41,16 @@ const Wrapper = styled.div`
`;
const toHHMMSS = elapsed => {
const pad = n => {
return `00${n}`.slice(-2);
};
const sec_num = parseInt(elapsed, 10);
const hours = Math.floor(sec_num / 3600);
const minutes = Math.floor(sec_num / 60) % 60;
const seconds = sec_num % 60;
const date = new Date();
date.setTime(elapsed * 1000);
const hrs = date.getUTCHours();
const mins = date.getUTCMinutes();
const secs = date.getUTCSeconds();
const stampHours = hours < 10 ? `0${hours}` : hours;
const stampMinutes = minutes < 10 ? `0${minutes}` : minutes;
const stampSeconds = seconds < 10 ? `0${seconds}` : seconds;
return `${pad(hrs)}:${pad(mins)}:${pad(secs)}`;
return `${stampHours}:${stampMinutes}:${stampSeconds}`;
};
const OUTPUT_NO_COUNT_JOB_TYPES = [
@ -67,7 +66,7 @@ const OutputToolbar = ({ i18n, job, onDelete }) => {
const taskCount = job?.playbook_counts?.task_count;
const darkCount = job?.host_status_counts?.dark;
const failureCount = job?.host_status_counts?.failures;
const totalHostCount = Object.keys(job?.host_status_counts).reduce(
const totalHostCount = Object.keys(job?.host_status_counts || {}).reduce(
(sum, key) => sum + job?.host_status_counts[key],
0
);

View File

@ -67,6 +67,22 @@ describe('<OutputToolbar />', () => {
expect(wrapper.find('div[aria-label="Failed Host Count"]').length).toBe(0);
});
test('should display elapsed time as HH:MM:SS', () => {
wrapper = mountWithContexts(
<OutputToolbar
job={{
...mockJobData,
elapsed: 274265,
}}
onDelete={() => {}}
/>
);
expect(wrapper.find('div[aria-label="Elapsed Time"] Badge').text()).toBe(
'76:11:05'
);
});
test('should hide relaunch button based on user capabilities', () => {
expect(wrapper.find('LaunchButton').length).toBe(1);
wrapper = mountWithContexts(