Skip to content

Commit

Permalink
Merge pull request #140 from AdamZarger/size_limit
Browse files Browse the repository at this point in the history
Calculate correct pagination with new size limit
  • Loading branch information
AdamZarger authored Jan 25, 2019
2 parents b847282 + 188c46f commit 97c9ea3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Pagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class Pagination extends React.Component {

_calculatePages( props ) {
const from = props.from || 0;
const size = props.size || 1;
var size = props.size || 1;
if ( size > 100 ) {
size = 100;
}
const total = props.total || 0;
const c = Math.ceil( from / size ) + 1;

Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/Pagination.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ it('records text input from the user', () => {
expect(target.state('inputValue')).toEqual(49)
})

it('corrects large size to size limit', () => {
const target = shallow(<Pagination from="175" size="500" total="1000" />)

// Expect 1000 / 100
expect(target.state('total')).toEqual(10)
})

describe('disabled buttons', () => {
it('disables the previous button when on the first page', () => {
const target = shallow(<Pagination from="0" size="10" total="100" />)
Expand Down

0 comments on commit 97c9ea3

Please sign in to comment.