Skip to content

Commit

Permalink
Closes #395 Fix indexed passed when replacing a break (for only one p…
Browse files Browse the repository at this point in the history
…age) with the actual page
  • Loading branch information
MonsieurV committed Nov 24, 2021
1 parent 049841c commit 91ad937
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

- Removed support for depecrated `extraAriaContext` (please use `ariaLabelBuilder` instead)

## >= 8.0.1

- Fix the indexed passed when replacing a break (containing only one page) with the actual page (see: https://github.com/AdeleD/react-paginate/pull/395)

## >= 8.0.0

- Remove button role for links with an href (see: https://github.com/AdeleD/react-paginate/pull/390)
Expand Down
51 changes: 51 additions & 0 deletions __tests__/PaginationBoxView-test.js
Expand Up @@ -2127,4 +2127,55 @@ describe('Test custom props', () => {
).toBe('break');
});
});

describe('Prevent breaks for one page', () => {
it('test clicks on previous and next buttons', () => {
const pagination = ReactTestUtils.renderIntoDocument(
<PaginationBoxView
pageRangeDisplayed={5}
pageCount={12}
renderOnZeroPageCount={null}
marginPagesDisplayed={1}
/>
);

const elmts = ReactTestUtils.scryRenderedDOMComponentsWithTag(
pagination,
'a'
);
const previous = elmts[0];
const next = elmts[elmts.length - 1];

ReactTestUtils.Simulate.click(next);
expect(
ReactDOM.findDOMNode(pagination).querySelectorAll('.selected a').length
).toBe(1);
expect(
ReactDOM.findDOMNode(pagination).querySelector('.selected a').textContent
).toBe('2');

// Click to go to page 8.
for (let i = 1; i < 7; i++) {
ReactTestUtils.Simulate.click(next);
expect(
ReactDOM.findDOMNode(pagination).querySelectorAll('.selected a').length
).toBe(1);
expect(
ReactDOM.findDOMNode(pagination).querySelector('.selected a').textContent
).toBe(`${2+i}`);
}
expect(
ReactDOM.findDOMNode(pagination).querySelector('.selected a').textContent
).toBe('8');

ReactTestUtils.Simulate.click(previous);

expect(
ReactDOM.findDOMNode(pagination).querySelectorAll('.selected a').length
).toBe(1);
expect(
ReactDOM.findDOMNode(pagination).querySelector('.selected a').textContent
).toBe('7');
});
});
});
2 changes: 1 addition & 1 deletion dist/react-paginate.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-paginate.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-paginate",
"version": "8.0.0",
"version": "8.0.1",
"description": "A ReactJS component that creates a pagination.",
"main": "./dist/react-paginate.js",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions react_components/PaginationBoxView.js
Expand Up @@ -445,8 +445,8 @@ export default class PaginationBoxView extends Component {
) {
actualPageElement = {
type: 'page',
index: i,
display: createPageView(i),
index: pageElement.index,
display: createPageView(pageElement.index),
};
}
// We add the displayed elements in the same pass, to avoid another iteration.
Expand Down

0 comments on commit 91ad937

Please sign in to comment.