fix(statistic): ignore the decimal part when the precision is negative (#35520)

pull/35529/head
ty888 3 years ago committed by GitHub
parent be2b0d8a6e
commit debd7f3496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,7 +30,7 @@ const StatisticNumber: React.FC<NumberProps> = props => {
int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
if (typeof precision === 'number') {
decimal = padEnd(decimal, precision, '0').slice(0, precision);
decimal = padEnd(decimal, precision, '0').slice(0, precision > 0 ? precision : 0);
}
if (decimal) {

@ -51,6 +51,20 @@ describe('Statistic', () => {
expect(wrapper.render()).toMatchSnapshot();
});
it('allow negetive precision', () => {
[
[-1, -1112893.1212, '-1,112,893'],
[-2, -1112893.1212, '-1,112,893'],
[-3, -1112893.1212, '-1,112,893'],
[-1, -1112893, '-1,112,893'],
[-1, 1112893, '1,112,893'],
].forEach(([precision, value, expectValue]) => {
const wrapper = mount(<Statistic precision={precision} value={value} />);
expect(wrapper.find('.ant-statistic-content-value-int').text()).toEqual(expectValue);
expect(wrapper.find('.ant-statistic-content-value-decimal').length).toBe(0);
})
});
it('loading with skeleton', async () => {
let loading = false;
const wrapper = mount(<Statistic title="Active Users" value={112112} loading={loading} />);

Loading…
Cancel
Save