Skip to content

Commit 313b80e

Browse files
Fix Paginate so it does not require currentPage (#4509)
1 parent d44e71d commit 313b80e

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/core/components/Paginate/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class PaginateBase extends React.Component {
2020
static propTypes = {
2121
LinkComponent: PropTypes.func,
2222
count: PropTypes.number.isRequired,
23-
currentPage: PropTypes.number.isRequired,
23+
currentPage: PropTypes.number,
2424
i18n: PropTypes.object.isRequired,
2525
pathname: PropTypes.string.isRequired,
2626
perPage: PropTypes.number,
@@ -31,6 +31,7 @@ export class PaginateBase extends React.Component {
3131
static defaultProps = {
3232
perPage: 25, // The default number of results per page returned by the API.
3333
showPages: 0,
34+
currentPage: 1,
3435
}
3536

3637
pageCount() {
@@ -74,9 +75,6 @@ export class PaginateBase extends React.Component {
7475
if (count === undefined) {
7576
throw new Error('The count property cannot be undefined');
7677
}
77-
if (currentPage === undefined) {
78-
throw new Error('The currentPage property cannot be undefined');
79-
}
8078
if (pathname === undefined) {
8179
throw new Error('The pathname property cannot be undefined');
8280
}

tests/unit/core/components/TestPaginate.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ describe('<Paginate />', () => {
3030
.toThrowError(/count property cannot be undefined/);
3131
});
3232

33-
it('does not allow an undefined currentPage', () => {
34-
expect(() => renderPaginate({ currentPage: undefined }))
35-
.toThrowError(/currentPage property cannot be undefined/);
36-
});
37-
3833
it('does not allow an undefined pathname', () => {
3934
expect(() => renderPaginate({ pathname: undefined }))
4035
.toThrowError(/pathname property cannot be undefined/);
@@ -183,4 +178,11 @@ describe('<Paginate />', () => {
183178
expect(firstLink).toHaveProp('pathname', pathname);
184179
expect(firstLink).toHaveProp('pageCount', pageCount);
185180
});
181+
182+
it('defaults currentPage to 1', () => {
183+
const root = renderPaginate({ currentPage: undefined, count: 30 });
184+
185+
const firstLink = root.find(PaginatorLink).first();
186+
expect(firstLink).toHaveProp('currentPage', 1);
187+
});
186188
});

0 commit comments

Comments
 (0)