Test time conductor history 4287 (#4321)

Added some extra test for the new implementation of Time Conductor History on PR 4287
* Refractor on testing and Time Conductor
* Update duration.js
Refractor on getPreciseDuration()
This commit is contained in:
Jon Ander Oribe 2021-10-22 21:21:28 +02:00 committed by GitHub
parent 0249ab4df5
commit 5eaf222f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 16 deletions

View File

@ -21,6 +21,7 @@
*****************************************************************************/
import {createMouseEvent, createOpenMct, resetApplicationState} from "utils/testing";
import {millisecondsToDHMS, getPreciseDuration} from "../../utils/duration";
import ConductorPlugin from "./plugin";
import Vue from 'vue';
@ -126,3 +127,19 @@ describe('time conductor', () => {
});
});
describe('duration functions', () => {
it('should transform milliseconds to DHMS', () => {
const functionResults = [millisecondsToDHMS(0), millisecondsToDHMS(86400000),
millisecondsToDHMS(129600000), millisecondsToDHMS(661824000)];
const validResults = [' ', '+ 1d', '+ 1d 12h', '+ 7d 15h 50m 24s'];
expect(validResults).toEqual(functionResults);
});
it('should get precise duration', () => {
const functionResults = [getPreciseDuration(0), getPreciseDuration(643680000),
getPreciseDuration(1605312000)];
const validResults = ['00:00:00:00', '07:10:48:00', '18:13:55:12'];
expect(validResults).toEqual(functionResults);
});
});

View File

@ -33,11 +33,7 @@ function normalizeAge(num) {
}
function toDoubleDigits(num) {
if (num >= 10) {
return num;
} else {
return `0${num}`;
}
return num >= 10 ? num : `0${num}`;
}
function addTimeSuffix(value, suffix) {
@ -56,17 +52,14 @@ export function millisecondsToDHMS(numericDuration) {
return `${ dhms ? '+' : ''} ${dhms}`;
}
export function getPreciseDuration(numericDuration) {
let result;
export function getPreciseDuration(value) {
const ms = value || 0;
const days = toDoubleDigits(Math.floor((numericDuration) / (24 * 60 * 60 * 1000)));
let remaining = (numericDuration) % (24 * 60 * 60 * 1000);
const hours = toDoubleDigits(Math.floor((remaining) / (60 * 60 * 1000)));
remaining = (remaining) % (60 * 60 * 1000);
const minutes = toDoubleDigits(Math.floor((remaining) / (60 * 1000)));
remaining = (remaining) % (60 * 1000);
const seconds = toDoubleDigits(Math.floor((remaining) / (1000)));
result = `${days}:${hours}:${minutes}:${seconds}`;
return [
toDoubleDigits(Math.floor(normalizeAge(ms / ONE_DAY))),
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_DAY) / ONE_HOUR))),
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_HOUR) / ONE_MINUTE))),
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_MINUTE) / ONE_SECOND)))
].join(":");
return result;
}