From debd7f349634a4ae3651732a44ad2e9e091b695d Mon Sep 17 00:00:00 2001 From: ty888 <1506125048@qq.com> Date: Fri, 13 May 2022 00:47:20 +0800 Subject: [PATCH 1/3] fix(statistic): ignore the decimal part when the precision is negative (#35520) --- components/statistic/Number.tsx | 2 +- components/statistic/__tests__/index.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/components/statistic/Number.tsx b/components/statistic/Number.tsx index 6d6e0bd062..0e9fc2222f 100644 --- a/components/statistic/Number.tsx +++ b/components/statistic/Number.tsx @@ -30,7 +30,7 @@ const StatisticNumber: React.FC = 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) { diff --git a/components/statistic/__tests__/index.test.js b/components/statistic/__tests__/index.test.js index 109df17ab2..abd47d69d8 100644 --- a/components/statistic/__tests__/index.test.js +++ b/components/statistic/__tests__/index.test.js @@ -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(); + 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(); From e8d9c4256562d04bf027b7be79bd4ad8ade7d3c3 Mon Sep 17 00:00:00 2001 From: zombiej Date: Fri, 13 May 2022 10:14:09 +0800 Subject: [PATCH 2/3] test: Update snapshot --- .../cascader/__tests__/__snapshots__/demo-extend.test.ts.snap | 2 +- components/cascader/__tests__/__snapshots__/demo.test.js.snap | 2 +- components/select/demo/responsive.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/cascader/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/cascader/__tests__/__snapshots__/demo-extend.test.ts.snap index 9cfbb0f639..22faababa6 100644 --- a/components/cascader/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/cascader/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -1534,7 +1534,7 @@ exports[`renders ./components/cascader/demo/multiple.md extend context correctly >