mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Units: adds scale symbol for currencies with suffixed symbol (#24678)
This commit is contained in:
parent
cfac591234
commit
51509bb2ff
@ -0,0 +1,55 @@
|
||||
import { currency } from './symbolFormatters';
|
||||
|
||||
describe('currency', () => {
|
||||
const symbol = '@';
|
||||
|
||||
describe('when called without asSuffix', () => {
|
||||
const fmtFunc = currency(symbol);
|
||||
|
||||
it.each`
|
||||
value | expectedSuffix | expectedText
|
||||
${999} | ${''} | ${'999'}
|
||||
${1000} | ${'K'} | ${'1'}
|
||||
${1000000} | ${'M'} | ${'1'}
|
||||
${1000000000} | ${'B'} | ${'1'}
|
||||
${1000000000000} | ${'T'} | ${'1'}
|
||||
${1000000000000000} | ${undefined} | ${'NA'}
|
||||
${-1000000000000} | ${'T'} | ${'-1'}
|
||||
${-1000000000} | ${'B'} | ${'-1'}
|
||||
${-1000000} | ${'M'} | ${'-1'}
|
||||
${-1000} | ${'K'} | ${'-1'}
|
||||
${-999} | ${''} | ${'-999'}
|
||||
`('when called with value:{$value}', ({ value, expectedSuffix, expectedText }) => {
|
||||
const { prefix, suffix, text } = fmtFunc(value);
|
||||
|
||||
expect(prefix).toEqual(symbol);
|
||||
expect(suffix).toEqual(expectedSuffix);
|
||||
expect(text).toEqual(expectedText);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when called with asSuffix', () => {
|
||||
const fmtFunc = currency(symbol, true);
|
||||
|
||||
it.each`
|
||||
value | expectedSuffix | expectedText
|
||||
${999} | ${'@'} | ${'999'}
|
||||
${1000} | ${'K@'} | ${'1'}
|
||||
${1000000} | ${'M@'} | ${'1'}
|
||||
${1000000000} | ${'B@'} | ${'1'}
|
||||
${1000000000000} | ${'T@'} | ${'1'}
|
||||
${1000000000000000} | ${undefined} | ${'NA'}
|
||||
${-1000000000000} | ${'T@'} | ${'-1'}
|
||||
${-1000000000} | ${'B@'} | ${'-1'}
|
||||
${-1000000} | ${'M@'} | ${'-1'}
|
||||
${-1000} | ${'K@'} | ${'-1'}
|
||||
${-999} | ${'@'} | ${'-999'}
|
||||
`('when called with value:{$value}', ({ value, expectedSuffix, expectedText }) => {
|
||||
const { prefix, suffix, text } = fmtFunc(value);
|
||||
|
||||
expect(prefix).toEqual(undefined);
|
||||
expect(suffix).toEqual(expectedSuffix);
|
||||
expect(text).toEqual(expectedText);
|
||||
});
|
||||
});
|
||||
});
|
@ -10,7 +10,7 @@ export function currency(symbol: string, asSuffix?: boolean): ValueFormatter {
|
||||
}
|
||||
const scaled = scaler(size, decimals, scaledDecimals);
|
||||
if (asSuffix) {
|
||||
scaled.suffix = symbol;
|
||||
scaled.suffix = scaled.suffix !== undefined ? `${scaled.suffix}${symbol}` : undefined;
|
||||
} else {
|
||||
scaled.prefix = symbol;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user