From 686130d8a5a82465b797bdfdeafa02bfe8978b14 Mon Sep 17 00:00:00 2001 From: maxiao Date: Wed, 3 Nov 2021 19:08:19 +0800 Subject: [PATCH 1/4] feat: simple Pagination cant emit onChange when change page --- src/Pagination.jsx | 13 ++++++++++++- tests/jumper.test.js | 14 +++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Pagination.jsx b/src/Pagination.jsx index ff3f18c2..870c695b 100644 --- a/src/Pagination.jsx +++ b/src/Pagination.jsx @@ -172,7 +172,12 @@ class Pagination extends React.Component { isValid = (page) => { const { total } = this.props; - return isInteger(page) && page !== this.state.current && isInteger(total) && total > 0; + return ( + isInteger(page) && + page !== this.state.current && + isInteger(total) && + total > 0 + ); }; shouldDisplayQuickJumper = () => { @@ -206,6 +211,11 @@ class Pagination extends React.Component { } }; + handleBlur = (e) => { + const value = this.getValidValue(e); + this.handleChange(value); + }; + changePageSize = (size) => { let { current } = this.state; const newCurrent = calculatePage(size, this.state, this.props); @@ -476,6 +486,7 @@ class Pagination extends React.Component { onKeyDown={this.handleKeyDown} onKeyUp={this.handleKeyUp} onChange={this.handleKeyUp} + onBlur={this.handleBlur} size="3" /> / diff --git a/tests/jumper.test.js b/tests/jumper.test.js index d5c905a1..a833e1c1 100644 --- a/tests/jumper.test.js +++ b/tests/jumper.test.js @@ -31,13 +31,13 @@ describe('Pagination with jumper', () => { expect(onChange).toHaveBeenLastCalledWith(1, 10); }); - it('should not call onChange when blur input', () => { - const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper'); - const input = quickJumper.find('input'); - input.simulate('blur'); - expect(wrapper.state().current).toBe(10); - expect(onChange).not.toBeCalled(); - }); + // it('should not call onChange when blur input', () => { + // const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper'); + // const input = quickJumper.find('input'); + // input.simulate('blur'); + // expect(wrapper.state().current).toBe(10); + // expect(onChange).not.toBeCalled(); + // }); it('should not jumper when click pre/next button', () => { const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper'); From 9147b3c1e11f3166699b7208ff1bfcd7f0c735fc Mon Sep 17 00:00:00 2001 From: maxiao Date: Thu, 4 Nov 2021 10:55:38 +0800 Subject: [PATCH 2/4] feat:revise pagination jumper.test when input blur --- tests/jumper.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/jumper.test.js b/tests/jumper.test.js index a833e1c1..cc11b0a5 100644 --- a/tests/jumper.test.js +++ b/tests/jumper.test.js @@ -31,13 +31,13 @@ describe('Pagination with jumper', () => { expect(onChange).toHaveBeenLastCalledWith(1, 10); }); - // it('should not call onChange when blur input', () => { - // const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper'); - // const input = quickJumper.find('input'); - // input.simulate('blur'); - // expect(wrapper.state().current).toBe(10); - // expect(onChange).not.toBeCalled(); - // }); + it('should call onChange when blur input', () => { + const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper'); + const input = quickJumper.find('input'); + input.simulate('blur'); + expect(wrapper.state().current).toBe(10); + expect(onChange).toBeCalled(); + }); it('should not jumper when click pre/next button', () => { const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper'); From 47062a8aa883f63e21f12865320cc0522c92b652 Mon Sep 17 00:00:00 2001 From: maxiao Date: Thu, 4 Nov 2021 14:17:45 +0800 Subject: [PATCH 3/4] test:Pagination add call onChange when value changed and input blur --- tests/jumper.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/jumper.test.js b/tests/jumper.test.js index cc11b0a5..f877bb00 100644 --- a/tests/jumper.test.js +++ b/tests/jumper.test.js @@ -31,11 +31,11 @@ describe('Pagination with jumper', () => { expect(onChange).toHaveBeenLastCalledWith(1, 10); }); - it('should call onChange when blur input', () => { + it('should call onChange when value changed and input blur', () => { const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper'); const input = quickJumper.find('input'); + input.simulate('change', { target: { value: '2' } }); input.simulate('blur'); - expect(wrapper.state().current).toBe(10); expect(onChange).toBeCalled(); }); From 14e2f2f7aaaf896329685a1b9824b71b246c7c0b Mon Sep 17 00:00:00 2001 From: maxiao Date: Fri, 5 Nov 2021 00:45:39 +0800 Subject: [PATCH 4/4] feat: simple Pagination test --- tests/jumper.test.js | 6 +++--- tests/simple.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/jumper.test.js b/tests/jumper.test.js index f877bb00..d5c905a1 100644 --- a/tests/jumper.test.js +++ b/tests/jumper.test.js @@ -31,12 +31,12 @@ describe('Pagination with jumper', () => { expect(onChange).toHaveBeenLastCalledWith(1, 10); }); - it('should call onChange when value changed and input blur', () => { + it('should not call onChange when blur input', () => { const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper'); const input = quickJumper.find('input'); - input.simulate('change', { target: { value: '2' } }); input.simulate('blur'); - expect(onChange).toBeCalled(); + expect(wrapper.state().current).toBe(10); + expect(onChange).not.toBeCalled(); }); it('should not jumper when click pre/next button', () => { diff --git a/tests/simple.test.js b/tests/simple.test.js index db2fb34b..ca90c3a1 100644 --- a/tests/simple.test.js +++ b/tests/simple.test.js @@ -22,6 +22,18 @@ describe('simple Pagination', () => { wrapper.unmount(); }); + it('input change value will emit onChange when input blur', () => { + const onChange = jest.fn(); + const component = mount( + , + ); + const greaterCurrent = component.find('.rc-pagination-simple'); + const input = greaterCurrent.find('input'); + input.simulate('change', { target: { value: '2' } }); + input.simulate('blur'); + expect(onChange).toBeCalled(); + }); + it('default current page is 1', () => { expect(wrapper.state().current).toBe(1); });