From 5bff9421109a710be217829cea145e782be04839 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Mon, 7 Jan 2019 07:05:08 -0500 Subject: [PATCH] pagination test fixup --- __tests__/components/Pagination.test.jsx | 4 ++-- src/components/Pagination/Pagination.jsx | 29 ++++++++++++------------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/__tests__/components/Pagination.test.jsx b/__tests__/components/Pagination.test.jsx index 6360098c7a..05413a49ad 100644 --- a/__tests__/components/Pagination.test.jsx +++ b/__tests__/components/Pagination.test.jsx @@ -122,7 +122,6 @@ describe('', () => { test('submit a new page by typing in input works', () => { const textInputSelector = '.pf-l-split__item.pf-m-main .pf-c-form-control'; const submitFormSelector = '.pf-l-split__item.pf-m-main form'; - const onSetPage = jest.fn(); pagination = mount( @@ -137,6 +136,7 @@ describe('', () => { /> ); + const textInput = pagination.find(textInputSelector); expect(textInput.length).toBe(1); textInput.simulate('change'); @@ -145,7 +145,7 @@ describe('', () => { const submitForm = pagination.find(submitFormSelector); expect(submitForm.length).toBe(1); submitForm.simulate('submit'); - pagination.setState({ value: 'invalid' }); + pagination.find('Pagination').instance().setState({ value: 'invalid' }); submitForm.simulate('submit'); }); diff --git a/src/components/Pagination/Pagination.jsx b/src/components/Pagination/Pagination.jsx index 98998b4140..f7a6e4d461 100644 --- a/src/components/Pagination/Pagination.jsx +++ b/src/components/Pagination/Pagination.jsx @@ -18,8 +18,7 @@ class Pagination extends Component { constructor (props) { super(props); - const { page } = this.props; - + const { page } = props; this.state = { value: page, isOpen: false }; this.onPageChange = this.onPageChange.bind(this); @@ -70,18 +69,14 @@ class Pagination extends Component { const { onSetPage, page, page_size } = this.props; const previousPage = page - 1; - if (previousPage >= 1) { - onSetPage(previousPage, page_size); - } + onSetPage(previousPage, page_size); } onNext () { const { onSetPage, page, pageCount, page_size } = this.props; const nextPage = page + 1; - if (nextPage <= pageCount) { - onSetPage(nextPage, page_size); - } + onSetPage(nextPage, page_size); } onLast () { @@ -143,14 +138,20 @@ class Pagination extends Component { direction={up} isOpen={isOpen} toggle={( - - { page_size } + + {page_size} )} > {opts.map(option => ( - - { option } + + {option} ))} @@ -159,7 +160,7 @@ class Pagination extends Component { - { itemMin } - { itemMax } of { count } + {itemMin} - {itemMax} of {count}
@@ -200,7 +201,7 @@ class Pagination extends Component { value={value} type="text" onChange={this.onPageChange} - /> of { pageCount } + /> of {pageCount}