Skip to content

Commit

Permalink
fix(clearRefinements): reset page to 0 (#3936)
Browse files Browse the repository at this point in the history
* fix(clearRefinements): reset page to 0

* chore(clearRefinements): clean up

* chore(clearRefinements): remove getter function from the test
  • Loading branch information
Eunjae Lee authored Jul 10, 2019
1 parent fa02bed commit 7378a0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -517,5 +517,26 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin
}
});
});

it('reset the page to 0', () => {
const helper = jsHelper({}, '', {});
helper.search = () => {};
helper.setQuery('not empty');

const rendering = jest.fn();
const makeWidget = connectClearRefinements(rendering);
const widget = makeWidget({});

widget.init({
helper,
state: helper.state,
createURL: () => '#',
});
const clearRefinements = rendering.mock.calls[0][0].refine;

helper.setPage(2);
clearRefinements();
expect(helper.state.page).toBe(0);
});
});
});
2 changes: 1 addition & 1 deletion src/lib/utils/clearRefinements.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @returns {SearchParameters} search parameters with refinements cleared
*/
function clearRefinements({ helper, attributesToClear = [] }) {
let finalState = helper.state;
let finalState = helper.state.setPage(0);

attributesToClear.forEach(attribute => {
if (attribute === '_tags') {
Expand Down

0 comments on commit 7378a0a

Please sign in to comment.