Skip to content

Commit

Permalink
fix(connectNumericRefinementList): reset page on refine
Browse files Browse the repository at this point in the history
* test(connectNumericRefinementList): failing test for page reset
* fix(connectNumericRefinementList): reset page on refine
  • Loading branch information
Maxime Janton authored and bobylito committed Jun 19, 2017
1 parent c36f7c5 commit 22ec08d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,40 @@ describe('connectNumericRefinementList', () => {
const secondRenderingOptions = rendering.mock.calls[1][0];
expect(secondRenderingOptions.items[0].isRefined).toBe(true);
});

it('should reset page on refine()', () => {
const rendering = jest.fn();
const makeWidget = connectNumericRefinementList(rendering);

const widget = makeWidget({
attributeName: 'numerics',
options: [
{name: 'below 10', end: 10},
{name: '10 - 20', start: 10, end: 20},
{name: 'more than 20', start: 20},
{name: '42', start: 42, end: 42},
{name: 'void'},
],
});

const helper = jsHelper(fakeClient);
helper.search = sinon.stub();
helper.setPage(2);

widget.init({
helper,
state: helper.state,
createURL: () => '#',
onHistoryChange: () => {},
});

expect(helper.state.page).toBe(2);

const firstRenderingOptions = rendering.mock.calls[0][0];
const {refine, items} = firstRenderingOptions;

refine(items[0].value);

expect(helper.state.page).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ function refine(state, attributeName, options, facetValue) {
}
}

resolvedState.page = 0;

return resolvedState;
}

Expand Down

0 comments on commit 22ec08d

Please sign in to comment.