adding test

This commit is contained in:
Peter Holmberg
2019-03-21 14:05:45 +01:00
parent 528f085c96
commit 6e05b9f41c

View File

@@ -1,4 +1,10 @@
import { getDisplayProcessor, getColorFromThreshold, DisplayProcessor, DisplayValue } from './displayValue';
import {
getDisplayProcessor,
getColorFromThreshold,
DisplayProcessor,
DisplayValue,
getDecimalsForValue,
} from './displayValue';
import { MappingType, ValueMapping } from '../types';
function assertSame(input: any, processors: DisplayProcessor[], match: DisplayValue) {
@@ -155,3 +161,18 @@ describe('Format value', () => {
expect(instance(value).text).toEqual('1-20');
});
});
describe('getDecimalsForValue()', () => {
it('should calculate reasonable decimals precision for given value', () => {
expect(getDecimalsForValue(1.01)).toEqual({ decimals: 1, scaledDecimals: 4 });
expect(getDecimalsForValue(9.01)).toEqual({ decimals: 0, scaledDecimals: 2 });
expect(getDecimalsForValue(1.1)).toEqual({ decimals: 1, scaledDecimals: 4 });
expect(getDecimalsForValue(2)).toEqual({ decimals: 0, scaledDecimals: 2 });
expect(getDecimalsForValue(20)).toEqual({ decimals: 0, scaledDecimals: 1 });
expect(getDecimalsForValue(200)).toEqual({ decimals: 0, scaledDecimals: 0 });
expect(getDecimalsForValue(2000)).toEqual({ decimals: 0, scaledDecimals: 0 });
expect(getDecimalsForValue(20000)).toEqual({ decimals: 0, scaledDecimals: -2 });
expect(getDecimalsForValue(200000)).toEqual({ decimals: 0, scaledDecimals: -3 });
expect(getDecimalsForValue(200000000)).toEqual({ decimals: 0, scaledDecimals: -6 });
});
});