Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(searchBox): update lifecycle state #3981

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/connectors/search-box/__tests__/connectSearchBox-test.js
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
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