File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
src/core/components/Paginate
tests/unit/core/components Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -30,11 +30,6 @@ describe('<Paginate />', () => {
3030 . toThrowError ( / c o u n t p r o p e r t y c a n n o t b e u n d e f i n e d / ) ;
3131 } ) ;
3232
33- it ( 'does not allow an undefined currentPage' , ( ) => {
34- expect ( ( ) => renderPaginate ( { currentPage : undefined } ) )
35- . toThrowError ( / c u r r e n t P a g e p r o p e r t y c a n n o t b e u n d e f i n e d / ) ;
36- } ) ;
37-
3833 it ( 'does not allow an undefined pathname' , ( ) => {
3934 expect ( ( ) => renderPaginate ( { pathname : undefined } ) )
4035 . toThrowError ( / p a t h n a m e p r o p e r t y c a n n o t b e u n d e f i n e d / ) ;
@@ -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} ) ;
You can’t perform that action at this time.
0 commit comments