From d769795aa0ca992233f811914ead67c75f3329a1 Mon Sep 17 00:00:00 2001 From: gaoryrt Date: Tue, 29 Dec 2020 12:20:11 +0800 Subject: [PATCH] fix: percent={(3 / 9) * 100} steps={9} shows 2 (#28530) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 fix bug: percent={(3 / 9) * 100} steps={9} shows 2 * ✅ add test for last commit * ✨ update jest snapshot * ✅ add test --- components/progress/Steps.tsx | 2 +- .../progress/__tests__/__snapshots__/demo.test.js.snap | 4 ++-- components/progress/__tests__/index.test.js | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/progress/Steps.tsx b/components/progress/Steps.tsx index 1849ecab3c..f02e66d19a 100644 --- a/components/progress/Steps.tsx +++ b/components/progress/Steps.tsx @@ -20,7 +20,7 @@ const Steps: React.FC = props => { prefixCls, children, } = props; - const current = Math.floor(steps * (percent / 100)); + const current = Math.round(steps * (percent / 100)); const stepWidth = size === 'small' ? 2 : 14; const styledSteps = []; for (let i = 0; i < steps; i += 1) { diff --git a/components/progress/__tests__/__snapshots__/demo.test.js.snap b/components/progress/__tests__/__snapshots__/demo.test.js.snap index f17754825c..5517731d0c 100644 --- a/components/progress/__tests__/__snapshots__/demo.test.js.snap +++ b/components/progress/__tests__/__snapshots__/demo.test.js.snap @@ -1415,7 +1415,7 @@ Array [ style="width:14px;height:8px" />
{ ); }); + it('should display correct step', () => { + const wrapper = mount(); + expect(wrapper.find('.ant-progress-steps-item-active').length).toBe(2); + wrapper.setProps({ percent: 33.33 }); + expect(wrapper.find('.ant-progress-steps-item-active').length).toBe(3); + wrapper.setProps({ percent: 44.44 }); + expect(wrapper.find('.ant-progress-steps-item-active').length).toBe(4); + }); + it('steps should have default percent 0', () => { const wrapper = mount(); expect(wrapper.render()).toMatchSnapshot();