Commit c855daec authored by Scott Hampton's avatar Scott Hampton

Add a utils spec

Added a utils spec file to test the formattedTime
util function.
parent dce6ba76
import { TestStatus } from '~/pipelines/constants';
import { secondsToMilliseconds } from '~/lib/utils/datetime_utility';
import { __, sprintf } from '../../../locale';
export function iconForTestStatus(status) {
......@@ -15,7 +14,7 @@ export function iconForTestStatus(status) {
export const formattedTime = (seconds = 0) => {
if (seconds < 1) {
const milliseconds = secondsToMilliseconds(seconds);
const milliseconds = seconds * 1000;
return sprintf(__('%{milliseconds}ms'), { milliseconds: milliseconds.toFixed(2) });
}
return sprintf(__('%{seconds}s'), { seconds: seconds.toFixed(2) });
......
import { formattedTime } from '~/pipelines/stores/test_reports/utils';
describe('Test reports utils', () => {
describe('formattedTime', () => {
describe('when time is smaller than a second', () => {
it('should return time in milliseconds fixed to 2 decimals', () => {
const result = formattedTime(0.4815162342);
expect(result).toBe('481.52ms');
});
});
describe('when time is equal to a second', () => {
it('should return time in seconds fixed to 2 decimals', () => {
const result = formattedTime(1);
expect(result).toBe('1.00s');
});
});
describe('when time is greater than a second', () => {
it('should return time in seconds fixed to 2 decimals', () => {
const result = formattedTime(4.815162342);
expect(result).toBe('4.82s');
});
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment