pagination test fixup

This commit is contained in:
Jake McDermott
2019-01-07 07:05:08 -05:00
parent 6a7ba87a02
commit 5bff942110
2 changed files with 17 additions and 16 deletions

View File

@@ -122,7 +122,6 @@ describe('<Pagination />', () => {
test('submit a new page by typing in input works', () => { test('submit a new page by typing in input works', () => {
const textInputSelector = '.pf-l-split__item.pf-m-main .pf-c-form-control'; const textInputSelector = '.pf-l-split__item.pf-m-main .pf-c-form-control';
const submitFormSelector = '.pf-l-split__item.pf-m-main form'; const submitFormSelector = '.pf-l-split__item.pf-m-main form';
const onSetPage = jest.fn(); const onSetPage = jest.fn();
pagination = mount( pagination = mount(
@@ -137,6 +136,7 @@ describe('<Pagination />', () => {
/> />
</I18nProvider> </I18nProvider>
); );
const textInput = pagination.find(textInputSelector); const textInput = pagination.find(textInputSelector);
expect(textInput.length).toBe(1); expect(textInput.length).toBe(1);
textInput.simulate('change'); textInput.simulate('change');
@@ -145,7 +145,7 @@ describe('<Pagination />', () => {
const submitForm = pagination.find(submitFormSelector); const submitForm = pagination.find(submitFormSelector);
expect(submitForm.length).toBe(1); expect(submitForm.length).toBe(1);
submitForm.simulate('submit'); submitForm.simulate('submit');
pagination.setState({ value: 'invalid' }); pagination.find('Pagination').instance().setState({ value: 'invalid' });
submitForm.simulate('submit'); submitForm.simulate('submit');
}); });

View File

@@ -18,8 +18,7 @@ class Pagination extends Component {
constructor (props) { constructor (props) {
super(props); super(props);
const { page } = this.props; const { page } = props;
this.state = { value: page, isOpen: false }; this.state = { value: page, isOpen: false };
this.onPageChange = this.onPageChange.bind(this); this.onPageChange = this.onPageChange.bind(this);
@@ -70,19 +69,15 @@ class Pagination extends Component {
const { onSetPage, page, page_size } = this.props; const { onSetPage, page, page_size } = this.props;
const previousPage = page - 1; const previousPage = page - 1;
if (previousPage >= 1) {
onSetPage(previousPage, page_size); onSetPage(previousPage, page_size);
} }
}
onNext () { onNext () {
const { onSetPage, page, pageCount, page_size } = this.props; const { onSetPage, page, pageCount, page_size } = this.props;
const nextPage = page + 1; const nextPage = page + 1;
if (nextPage <= pageCount) {
onSetPage(nextPage, page_size); onSetPage(nextPage, page_size);
} }
}
onLast () { onLast () {
const { onSetPage, pageCount, page_size } = this.props; const { onSetPage, pageCount, page_size } = this.props;
@@ -143,13 +138,19 @@ class Pagination extends Component {
direction={up} direction={up}
isOpen={isOpen} isOpen={isOpen}
toggle={( toggle={(
<DropdownToggle className="togglePageSize" onToggle={this.onTogglePageSize}> <DropdownToggle
className="togglePageSize"
onToggle={this.onTogglePageSize}
>
{page_size} {page_size}
</DropdownToggle> </DropdownToggle>
)} )}
> >
{opts.map(option => ( {opts.map(option => (
<DropdownItem key={option} component="button"> <DropdownItem
key={option}
component="button"
>
{option} {option}
</DropdownItem> </DropdownItem>
))} ))}