Skip to content

Commit

Permalink
fix(searchBox): update lifecycle state (#3981)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour authored and Haroenv committed Oct 23, 2019
1 parent 2b08344 commit 0ea4950
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
28 changes: 26 additions & 2 deletions src/connectors/search-box/__tests__/connectSearchBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,33 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/search-box/
const makeWidget = connectSearchBox(renderFn);
const widget = makeWidget();

const nextConfiguration = widget.getConfiguration();
const nextConfiguration = widget.getConfiguration(
new SearchParameters({})
);

expect(nextConfiguration).toEqual(
new SearchParameters({
query: '',
})
);
});

it('takes the default `query` from the `SearchParameters` passed', () => {
const renderFn = () => {};
const makeWidget = connectSearchBox(renderFn);
const widget = makeWidget();

expect(nextConfiguration.query).toBe('');
const nextConfiguration = widget.getConfiguration(
new SearchParameters({
query: 'Previous query',
})
);

expect(nextConfiguration).toEqual(
new SearchParameters({
query: 'Previous query',
})
);
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/connectors/search-box/connectSearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ export default function connectSearchBox(renderFn, unmountFn = noop) {
this._clear();
},

getConfiguration() {
return {
query: '',
};
getConfiguration(state) {
return state.setQueryParameters({
query: state.query || '',
});
},

init({ helper, instantSearchInstance }) {
Expand Down

0 comments on commit 0ea4950

Please sign in to comment.