Skip to content

Commit

Permalink
feat(connectSearchBox): mount with a default query (#3840)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored and Haroenv committed Oct 23, 2019
1 parent fb70363 commit c3a7d69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/connectors/search-box/__tests__/connectSearchBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/search-box/
foo: 'bar',
});

expect(widget.getConfiguration).toBe(undefined);

const helper = algoliasearchHelper({});
helper.search = () => {};

Expand Down Expand Up @@ -276,6 +274,18 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/search-box/
expect(helper.search).toHaveBeenCalledTimes(1);
});

describe('getConfiguration', () => {
it('adds a `query` to the `SearchParameters`', () => {
const renderFn = () => {};
const makeWidget = connectSearchBox(renderFn);
const widget = makeWidget();

const nextConfiguration = widget.getConfiguration();

expect(nextConfiguration.query).toBe('');
});
});

describe('dispose', () => {
it('calls the unmount function', () => {
const helper = algoliasearchHelper({}, '');
Expand Down
6 changes: 6 additions & 0 deletions src/connectors/search-box/connectSearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export default function connectSearchBox(renderFn, unmountFn = noop) {
this._clear();
},

getConfiguration() {
return {
query: '',
};
},

init({ helper, instantSearchInstance }) {
this._cachedClear = this._cachedClear.bind(this);
this._clear = clear(helper);
Expand Down

0 comments on commit c3a7d69

Please sign in to comment.