mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
@@ -1,29 +1,38 @@
|
|||||||
import { toFixed, getValueFormat } from './valueFormats';
|
import { toFixed, getValueFormat } from './valueFormats';
|
||||||
|
|
||||||
describe('kbn.toFixed and negative decimals', () => {
|
describe('valueFormats', () => {
|
||||||
it('should treat as zero decimals', () => {
|
describe('toFixed and negative decimals', () => {
|
||||||
const str = toFixed(186.123, -2);
|
it('should treat as zero decimals', () => {
|
||||||
expect(str).toBe('186');
|
const str = toFixed(186.123, -2);
|
||||||
|
expect(str).toBe('186');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('kbn ms format when scaled decimals is null do not use it', () => {
|
describe('ms format when scaled decimals is null do not use it', () => {
|
||||||
it('should use specified decimals', () => {
|
it('should use specified decimals', () => {
|
||||||
const str = getValueFormat('ms')(10000086.123, 1, null);
|
const str = getValueFormat('ms')(10000086.123, 1, null);
|
||||||
expect(str).toBe('2.8 hour');
|
expect(str).toBe('2.8 hour');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('kbn kbytes format when scaled decimals is null do not use it', () => {
|
describe('kbytes format when scaled decimals is null do not use it', () => {
|
||||||
it('should use specified decimals', () => {
|
it('should use specified decimals', () => {
|
||||||
const str = getValueFormat('kbytes')(10000000, 3, null);
|
const str = getValueFormat('kbytes')(10000000, 3, null);
|
||||||
expect(str).toBe('9.537 GiB');
|
expect(str).toBe('9.537 GiB');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('kbn deckbytes format when scaled decimals is null do not use it', () => {
|
describe('deckbytes format when scaled decimals is null do not use it', () => {
|
||||||
it('should use specified decimals', () => {
|
it('should use specified decimals', () => {
|
||||||
const str = getValueFormat('deckbytes')(10000000, 3, null);
|
const str = getValueFormat('deckbytes')(10000000, 3, null);
|
||||||
expect(str).toBe('10.000 GB');
|
expect(str).toBe('10.000 GB');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ms format when scaled decimals is 0', () => {
|
||||||
|
it('should use scaledDecimals and add 3', () => {
|
||||||
|
const str = getValueFormat('ms')(1200, 0, 0);
|
||||||
|
expect(str).toBe('1.200 s');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -56,17 +56,15 @@ export function toFixed(value: number, decimals?: DecimalCount): string {
|
|||||||
|
|
||||||
export function toFixedScaled(
|
export function toFixedScaled(
|
||||||
value: number,
|
value: number,
|
||||||
decimals?: DecimalCount,
|
decimals: DecimalCount,
|
||||||
scaledDecimals?: DecimalCount,
|
scaledDecimals: DecimalCount,
|
||||||
additionalDecimals?: DecimalCount,
|
additionalDecimals: number,
|
||||||
ext?: string
|
ext?: string
|
||||||
) {
|
) {
|
||||||
if (scaledDecimals) {
|
if (scaledDecimals === null || scaledDecimals === undefined) {
|
||||||
if (additionalDecimals) {
|
return toFixed(value, decimals) + ext;
|
||||||
return toFixed(value, scaledDecimals + additionalDecimals) + ext;
|
} else {
|
||||||
} else {
|
return toFixed(value, scaledDecimals + additionalDecimals) + ext;
|
||||||
return toFixed(value, scaledDecimals) + ext;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return toFixed(value, decimals) + ext;
|
return toFixed(value, decimals) + ext;
|
||||||
|
|||||||
Reference in New Issue
Block a user