Skip to content

Commit

Permalink
fix(hitsPerPage): avoid sync default value (#4086)
Browse files Browse the repository at this point in the history
This PR avoid to sync the default value into the `uiState`. This behavior is consistent with the one from `sortBy`. The default value doesn't have to be inside the `uiState` because as the name suggests it's the default one. The option is defined statically, it can't change.
  • Loading branch information
samouss authored and Haroenv committed Oct 23, 2019
1 parent 9f68da5 commit 3f8b958
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/connectors/hits-per-page/__tests__/connectHitsPerPage-test.js
Expand Up @@ -570,6 +570,30 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits-per-pa
expect(actual).toEqual({});
});

test('returns the `uiState` empty with default value selected', () => {
const render = jest.fn();
const makeWidget = connectHitsPerPage(render);
const helper = algoliasearchHelper({}, 'indexName', {
hitsPerPage: 3,
});

const widget = makeWidget({
items: [
{ value: 3, label: '3 items per page', default: true },
{ value: 22, label: '22 items per page' },
],
});

const actual = widget.getWidgetState(
{},
{
searchParameters: helper.state,
}
);

expect(actual).toEqual({});
});

test('returns the `uiState` with a refinement', () => {
const render = jest.fn();
const makeWidget = connectHitsPerPage(render);
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/hits-per-page/connectHitsPerPage.js
Expand Up @@ -217,7 +217,7 @@ You may want to add another entry to the \`items\` option with this value.`
getWidgetState(uiState, { searchParameters }) {
const hitsPerPage = searchParameters.hitsPerPage;

if (hitsPerPage === undefined) {
if (hitsPerPage === undefined || hitsPerPage === defaultItem.value) {
return uiState;
}

Expand Down

0 comments on commit 3f8b958

Please sign in to comment.