mirror of https://github.com/buster-so/buster.git
add suffix after percentage
This commit is contained in:
parent
df138531f3
commit
0959403b47
|
@ -358,4 +358,22 @@ describe('formatLabel', () => {
|
|||
).toBe('null');
|
||||
});
|
||||
});
|
||||
|
||||
describe('percent formatter', () => {
|
||||
it('should format percentages', () => {
|
||||
expect(formatLabel(0.1234, { columnType: 'number', style: 'percent' })).toBe('0.12%');
|
||||
});
|
||||
|
||||
it('should format percentages with custom format', () => {
|
||||
expect(
|
||||
formatLabel(0.1234, { columnType: 'number', style: 'percent', dateFormat: 'YYYY-MM-DD' })
|
||||
).toBe('0.12%');
|
||||
});
|
||||
|
||||
it('should put suffix after the percentage', () => {
|
||||
expect(formatLabel(0.1234, { columnType: 'number', style: 'percent', suffix: ' WOW!' })).toBe(
|
||||
'0.12% WOW!'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -157,9 +157,9 @@ const prefixSuffixHandler = (
|
|||
if (replaceMissingDataWith === null && !text) return String(text);
|
||||
|
||||
let result = String(text);
|
||||
if (style === 'percent' && suffix !== '%') result = `${result}%`;
|
||||
if (prefix) result = prefix + result;
|
||||
if (suffix) result = result + suffix;
|
||||
if (style === 'percent' && suffix !== '%') result = `${result}%`;
|
||||
|
||||
return result;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue