mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
pagination test fixup
This commit is contained in:
@@ -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');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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,18 +69,14 @@ 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 () {
|
||||||
@@ -143,14 +138,20 @@ class Pagination extends Component {
|
|||||||
direction={up}
|
direction={up}
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
toggle={(
|
toggle={(
|
||||||
<DropdownToggle className="togglePageSize" onToggle={this.onTogglePageSize}>
|
<DropdownToggle
|
||||||
{ page_size }
|
className="togglePageSize"
|
||||||
|
onToggle={this.onTogglePageSize}
|
||||||
|
>
|
||||||
|
{page_size}
|
||||||
</DropdownToggle>
|
</DropdownToggle>
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{opts.map(option => (
|
{opts.map(option => (
|
||||||
<DropdownItem key={option} component="button">
|
<DropdownItem
|
||||||
{ option }
|
key={option}
|
||||||
|
component="button"
|
||||||
|
>
|
||||||
|
{option}
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
))}
|
))}
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
@@ -159,7 +160,7 @@ class Pagination extends Component {
|
|||||||
<LevelItem>
|
<LevelItem>
|
||||||
<Split gutter="md" className="pf-u-display-flex pf-u-align-items-center">
|
<Split gutter="md" className="pf-u-display-flex pf-u-align-items-center">
|
||||||
<SplitItem>
|
<SplitItem>
|
||||||
<Trans>{ itemMin } - { itemMax } of { count }</Trans>
|
<Trans>{itemMin} - {itemMax} of {count}</Trans>
|
||||||
</SplitItem>
|
</SplitItem>
|
||||||
<SplitItem>
|
<SplitItem>
|
||||||
<div className="pf-c-input-group">
|
<div className="pf-c-input-group">
|
||||||
@@ -200,7 +201,7 @@ class Pagination extends Component {
|
|||||||
value={value}
|
value={value}
|
||||||
type="text"
|
type="text"
|
||||||
onChange={this.onPageChange}
|
onChange={this.onPageChange}
|
||||||
/> of { pageCount }
|
/> of {pageCount}
|
||||||
</Trans>
|
</Trans>
|
||||||
</form>
|
</form>
|
||||||
</SplitItem>
|
</SplitItem>
|
||||||
|
|||||||
Reference in New Issue
Block a user