mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Synthetics] Improve test duration formatting (#152151)
Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
parent
ee56d954da
commit
f688b37c89
2 changed files with 38 additions and 2 deletions
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { formatTestDuration } from './test_time_formats';
|
||||
|
||||
describe('formatTestDuration', () => {
|
||||
it.each`
|
||||
duration | expected | isMilli
|
||||
${undefined} | ${'0 ms'} | ${undefined}
|
||||
${120_000_000} | ${'2 min'} | ${undefined}
|
||||
${6_200_000} | ${'6.2 s'} | ${false}
|
||||
${500_000} | ${'500 ms'} | ${undefined}
|
||||
${100} | ${'0 ms'} | ${undefined}
|
||||
${undefined} | ${'0 ms'} | ${true}
|
||||
${600_000} | ${'10 min'} | ${true}
|
||||
${6_200} | ${'6.2 s'} | ${true}
|
||||
${500} | ${'500 ms'} | ${true}
|
||||
`(
|
||||
'returns $expected when `duration` is $duration and `isMilli` $isMilli',
|
||||
({
|
||||
duration,
|
||||
expected,
|
||||
isMilli,
|
||||
}: {
|
||||
duration?: number;
|
||||
expected: string;
|
||||
isMilli?: boolean;
|
||||
}) => {
|
||||
expect(formatTestDuration(duration, isMilli)).toBe(expected);
|
||||
}
|
||||
);
|
||||
});
|
|
@ -17,11 +17,11 @@ export const formatTestDuration = (duration = 0, isMilli = false) => {
|
|||
const secs = isMilli ? duration / 1e3 : duration / 1e6;
|
||||
|
||||
if (secs >= 60) {
|
||||
return `${(secs / 60).toFixed(1)} min`;
|
||||
return `${parseFloat((secs / 60).toFixed(1))} min`;
|
||||
}
|
||||
|
||||
if (secs >= 1) {
|
||||
return `${secs.toFixed(1)} s`;
|
||||
return `${parseFloat(secs.toFixed(1))} s`;
|
||||
}
|
||||
|
||||
if (isMilli) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue