diff --git a/src/connectors/pagination/__tests__/connectPagination-test.js b/src/connectors/pagination/__tests__/connectPagination-test.js index af55bde870..fe4f93b6e9 100644 --- a/src/connectors/pagination/__tests__/connectPagination-test.js +++ b/src/connectors/pagination/__tests__/connectPagination-test.js @@ -274,9 +274,45 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/pagination/ const makeWidget = connectPagination(renderFn); const widget = makeWidget(); - const nextConfiguation = widget.getConfiguration(); + const nextConfiguation = widget.getConfiguration( + new SearchParameters({}) + ); + + expect(nextConfiguation).toEqual( + new SearchParameters({ + page: 0, + }) + ); + }); - expect(nextConfiguation.page).toBe(0); + it('takes the previous `page` from the `SearchParameters`', () => { + const renderFn = () => {}; + const makeWidget = connectPagination(renderFn); + const widget = makeWidget(); + + const nextConfiguation1 = widget.getConfiguration( + new SearchParameters({ + page: 0, + }) + ); + + expect(nextConfiguation1).toEqual( + new SearchParameters({ + page: 0, + }) + ); + + const nextConfiguation2 = widget.getConfiguration( + new SearchParameters({ + page: 6, + }) + ); + + expect(nextConfiguation2).toEqual( + new SearchParameters({ + page: 6, + }) + ); }); }); diff --git a/src/connectors/pagination/connectPagination.js b/src/connectors/pagination/connectPagination.js index 74371a5e65..f65c481312 100644 --- a/src/connectors/pagination/connectPagination.js +++ b/src/connectors/pagination/connectPagination.js @@ -100,10 +100,10 @@ export default function connectPagination(renderFn, unmountFn = noop) { return { $$type: 'ais.pagination', - getConfiguration() { - return { - page: 0, - }; + getConfiguration(state) { + return state.setQueryParameters({ + page: state.page || 0, + }); }, init({ helper, createURL, instantSearchInstance }) {