Skip to content

Commit

Permalink
fix(pagination): update lifecycle state (#3979)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour authored and Haroenv committed Oct 23, 2019
1 parent 8f05968 commit 2b08344
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
40 changes: 38 additions & 2 deletions src/connectors/pagination/__tests__/connectPagination-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
);
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/connectors/pagination/connectPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down

0 comments on commit 2b08344

Please sign in to comment.