-
-
Save epixa/aed0d611e41ac366073d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import expect from 'expect.js'; | |
import ngMock from 'ngMock'; | |
import RegistryFieldFormatsProvider from 'ui/registry/field_formats'; | |
describe('Duration Format', function () { | |
var fieldFormats; | |
var DurationFormat; | |
beforeEach(ngMock.module('kibana')); | |
beforeEach(ngMock.inject(function (Private) { | |
fieldFormats = Private(RegistryFieldFormatsProvider); | |
DurationFormat = fieldFormats.getType('duration'); | |
})); | |
function test(inputFormat, outputFormat, outputPrecision) { | |
return function doTest(input, output) { | |
it(`should format "${input} [${inputFormat}]" input as duration [${outputFormat}:${outputPrecision}]`, () => { | |
const duration = new DurationFormat({ inputFormat, outputFormat, outputPrecision }); | |
expect(duration.convert(input)).to.eql(output); | |
}); | |
return doTest; | |
}; | |
} | |
test({ inputFormat: 'seconds', outputFormat: 'humanize' }) | |
(-60, 'minus a minute') | |
(60, 'a minute') | |
(125, '2 minutes'); | |
test({ inputFormat: 'seconds', outputFormat: 'asSeconds', outputPrecision: 0 }) | |
(-60, '-60') | |
(60, '60') | |
(125, '125'); | |
test({ inputFormat: 'seconds', outputFormat: 'asSeconds', outputPrecision: 2 }) | |
(-60, '-60.00') | |
(60, '60.00') | |
(125, '125.00'); | |
test({ inputFormat: 'minutes', outputFormat: 'humanize' }) | |
(-60, 'minus an hour') | |
(60, 'an hour') | |
(125, '2 hours'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment