Skip to content

Commit 724b83f

Browse files
samoussHaroenv
authored andcommitted
feat(connectAutocomplete): add default value on getConfiguration (#3836)
* test(connectAutocomplete): scope getConfiguration into its own describe * feat(connectAutocomplete): mount a default query
1 parent 705b3e6 commit 724b83f

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

src/connectors/autocomplete/__tests__/connectAutocomplete-test.js

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/autocomplet
4343
expect(renderFn.mock.calls[1][1]).toBeFalsy();
4444
});
4545

46-
it('sets the default configuration', () => {
47-
const renderFn = jest.fn();
48-
const makeWidget = connectAutocomplete(renderFn);
49-
const widget = makeWidget();
50-
51-
expect(widget.getConfiguration()).toEqual({
52-
highlightPreTag: TAG_PLACEHOLDER.highlightPreTag,
53-
highlightPostTag: TAG_PLACEHOLDER.highlightPostTag,
54-
});
55-
});
56-
5746
it('creates DerivedHelper', () => {
5847
const renderFn = jest.fn();
5948
const makeWidget = connectAutocomplete(renderFn);
@@ -164,6 +153,47 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/autocomplet
164153
expect(rendering.indices[0].hits).toEqual(hits);
165154
});
166155

156+
describe('getConfiguration', () => {
157+
it('adds a `query` to the `SearchParameters`', () => {
158+
const renderFn = () => {};
159+
const makeWidget = connectAutocomplete(renderFn);
160+
const widget = makeWidget();
161+
162+
const nextConfiguation = widget.getConfiguration();
163+
164+
expect(nextConfiguation.query).toBe('');
165+
});
166+
167+
it('adds the TAG_PLACEHOLDER to the `SearchParameters`', () => {
168+
const renderFn = () => {};
169+
const makeWidget = connectAutocomplete(renderFn);
170+
const widget = makeWidget();
171+
172+
const nextConfiguation = widget.getConfiguration();
173+
174+
expect(nextConfiguation.highlightPreTag).toBe(
175+
TAG_PLACEHOLDER.highlightPreTag
176+
);
177+
178+
expect(nextConfiguation.highlightPostTag).toBe(
179+
TAG_PLACEHOLDER.highlightPostTag
180+
);
181+
});
182+
183+
it('does not add the TAG_PLACEHOLDER to the `SearchParameters` with `escapeHTML` disabled', () => {
184+
const renderFn = () => {};
185+
const makeWidget = connectAutocomplete(renderFn);
186+
const widget = makeWidget({
187+
escapeHTML: false,
188+
});
189+
190+
const nextConfiguation = widget.getConfiguration();
191+
192+
expect(nextConfiguation.highlightPreTag).toBeUndefined();
193+
expect(nextConfiguation.highlightPostTag).toBeUndefined();
194+
});
195+
});
196+
167197
describe('dispose', () => {
168198
it('calls the unmount function', () => {
169199
const helper = algoliasearchHelper(fakeClient, 'firstIndex');
@@ -291,7 +321,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/autocomplet
291321
expect(nextState.highlightPostTag).toBeUndefined();
292322
});
293323

294-
it('does not remove the TAG_PLACEHOLDER from the `SearchParameters` with `escapeHTML`', () => {
324+
it('does not remove the TAG_PLACEHOLDER from the `SearchParameters` with `escapeHTML` disabled', () => {
295325
const helper = algoliasearchHelper(fakeClient, 'firstIndex', {
296326
highlightPreTag: '<mark>',
297327
highlightPostTag: '</mark>',

src/connectors/autocomplete/connectAutocomplete.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@ export default function connectAutocomplete(renderFn, unmountFn = noop) {
5757

5858
return {
5959
getConfiguration() {
60-
return escapeHTML ? TAG_PLACEHOLDER : undefined;
60+
const parameters = {
61+
query: '',
62+
};
63+
64+
if (!escapeHTML) {
65+
return parameters;
66+
}
67+
68+
return {
69+
...parameters,
70+
...TAG_PLACEHOLDER,
71+
};
6172
},
6273

6374
init({ instantSearchInstance, helper }) {

0 commit comments

Comments
 (0)