mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +00:00
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:
@ -21,6 +21,7 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
import {createMouseEvent, createOpenMct, resetApplicationState} from "utils/testing";
|
import {createMouseEvent, createOpenMct, resetApplicationState} from "utils/testing";
|
||||||
|
import {millisecondsToDHMS, getPreciseDuration} from "../../utils/duration";
|
||||||
import ConductorPlugin from "./plugin";
|
import ConductorPlugin from "./plugin";
|
||||||
import Vue from 'vue';
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -33,11 +33,7 @@ function normalizeAge(num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toDoubleDigits(num) {
|
function toDoubleDigits(num) {
|
||||||
if (num >= 10) {
|
return num >= 10 ? num : `0${num}`;
|
||||||
return num;
|
|
||||||
} else {
|
|
||||||
return `0${num}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTimeSuffix(value, suffix) {
|
function addTimeSuffix(value, suffix) {
|
||||||
@ -56,17 +52,14 @@ export function millisecondsToDHMS(numericDuration) {
|
|||||||
return `${ dhms ? '+' : ''} ${dhms}`;
|
return `${ dhms ? '+' : ''} ${dhms}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPreciseDuration(numericDuration) {
|
export function getPreciseDuration(value) {
|
||||||
let result;
|
const ms = value || 0;
|
||||||
|
|
||||||
const days = toDoubleDigits(Math.floor((numericDuration) / (24 * 60 * 60 * 1000)));
|
return [
|
||||||
let remaining = (numericDuration) % (24 * 60 * 60 * 1000);
|
toDoubleDigits(Math.floor(normalizeAge(ms / ONE_DAY))),
|
||||||
const hours = toDoubleDigits(Math.floor((remaining) / (60 * 60 * 1000)));
|
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_DAY) / ONE_HOUR))),
|
||||||
remaining = (remaining) % (60 * 60 * 1000);
|
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_HOUR) / ONE_MINUTE))),
|
||||||
const minutes = toDoubleDigits(Math.floor((remaining) / (60 * 1000)));
|
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_MINUTE) / ONE_SECOND)))
|
||||||
remaining = (remaining) % (60 * 1000);
|
].join(":");
|
||||||
const seconds = toDoubleDigits(Math.floor((remaining) / (1000)));
|
|
||||||
result = `${days}:${hours}:${minutes}:${seconds}`;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user