Commit b4bca473 by Francisco Guimarães

Adding tests

parent 3db5d142
......@@ -399,6 +399,77 @@ describe('duration', () => {
});
});
describe('clock', () => {
it('null', () => {
const str = kbn.toClock(null, 0);
expect(str).toBe('');
});
it('size less than 1 second', () => {
const str = kbn.toClock(999, 0);
expect(str).toBe('999ms');
});
describe('size less than 1 minute', () => {
it('default', () => {
const str = kbn.toClock(59999);
expect(str).toBe('59s:999ms');
});
it('decimals equals 0', () => {
const str = kbn.toClock(59999, 0);
expect(str).toBe('59s');
});
});
describe('size less than 1 hour', () => {
it('default', () => {
const str = kbn.toClock(3599999);
expect(str).toBe('59m:59s:999ms');
});
it('decimals equals 0', () => {
const str = kbn.toClock(3599999, 0);
expect(str).toBe('59m');
});
it('decimals equals 1', () => {
const str = kbn.toClock(3599999, 1);
expect(str).toBe('59m:59s');
});
});
describe('size greater than or equal 1 hour', () => {
it('default', () => {
const str = kbn.toClock(7199999);
expect(str).toBe('01h:59m:59s:999ms');
});
it('decimals equals 0', () => {
const str = kbn.toClock(7199999, 0);
expect(str).toBe('01h');
});
it('decimals equals 1', () => {
const str = kbn.toClock(7199999, 1);
expect(str).toBe('01h:59m');
});
it('decimals equals 2', () => {
const str = kbn.toClock(7199999, 2);
expect(str).toBe('01h:59m:59s');
});
});
describe('size greater than or equal 1 day', () => {
it('default', () => {
const str = kbn.toClock(89999999);
expect(str).toBe('24h:59m:59s:999ms');
});
it('decimals equals 0', () => {
const str = kbn.toClock(89999999, 0);
expect(str).toBe('24h');
});
it('decimals equals 1', () => {
const str = kbn.toClock(89999999, 1);
expect(str).toBe('24h:59m');
});
it('decimals equals 2', () => {
const str = kbn.toClock(89999999, 2);
expect(str).toBe('24h:59m:59s');
});
});
});
describe('volume', () => {
it('1000m3', () => {
const str = kbn.valueFormats['m3'](1000, 1, null);
......
......@@ -809,7 +809,9 @@ kbn.toDuration = (size, decimals, timeScale) => {
};
kbn.toClock = (size, decimals) => {
console.log(`size ${JSON.stringify(size, null, 2)}`);
if (size === null) {
return '';
}
// < 1 second
if (size < 1000) {
......@@ -838,7 +840,7 @@ kbn.toClock = (size, decimals) => {
let format = 'mm\\m:ss\\s:SSS\\m\\s';
const hours = ('0' + Math.floor(moment.duration(size, 'milliseconds').asHours())).slice(-2);
const hours = `${('0' + Math.floor(moment.duration(size, 'milliseconds').asHours())).slice(-2)}h`;
if (decimals === 0) {
format = '';
......
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