From 12b468106db68896d93d8562fd03ca0e0919669e Mon Sep 17 00:00:00 2001 From: Vaillant Samuel Date: Tue, 28 May 2019 10:12:54 +0200 Subject: [PATCH 1/2] test(connectAutocomplete): scope getConfiguration into its own describe --- .../__tests__/connectAutocomplete-test.js | 44 ++++++++++++++----- .../autocomplete/connectAutocomplete.js | 2 +- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/connectors/autocomplete/__tests__/connectAutocomplete-test.js b/src/connectors/autocomplete/__tests__/connectAutocomplete-test.js index 4d2a0d19c9..e021fed9f1 100644 --- a/src/connectors/autocomplete/__tests__/connectAutocomplete-test.js +++ b/src/connectors/autocomplete/__tests__/connectAutocomplete-test.js @@ -43,17 +43,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/autocomplet expect(renderFn.mock.calls[1][1]).toBeFalsy(); }); - it('sets the default configuration', () => { - const renderFn = jest.fn(); - const makeWidget = connectAutocomplete(renderFn); - const widget = makeWidget(); - - expect(widget.getConfiguration()).toEqual({ - highlightPreTag: TAG_PLACEHOLDER.highlightPreTag, - highlightPostTag: TAG_PLACEHOLDER.highlightPostTag, - }); - }); - it('creates DerivedHelper', () => { const renderFn = jest.fn(); const makeWidget = connectAutocomplete(renderFn); @@ -168,6 +157,37 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/autocomplet expect(rendering.indices[0].hits).toEqual(hits); }); + describe('getConfiguration', () => { + it('adds the TAG_PLACEHOLDER to the `SearchParameters`', () => { + const renderFn = () => {}; + const makeWidget = connectAutocomplete(renderFn); + const widget = makeWidget(); + + const nextConfiguation = widget.getConfiguration(); + + expect(nextConfiguation.highlightPreTag).toBe( + TAG_PLACEHOLDER.highlightPreTag + ); + + expect(nextConfiguation.highlightPostTag).toBe( + TAG_PLACEHOLDER.highlightPostTag + ); + }); + + it('does not add the TAG_PLACEHOLDER to the `SearchParameters` with `escapeHTML` disabled', () => { + const renderFn = () => {}; + const makeWidget = connectAutocomplete(renderFn); + const widget = makeWidget({ + escapeHTML: false, + }); + + const nextConfiguation = widget.getConfiguration(); + + expect(nextConfiguation.highlightPreTag).toBeUndefined(); + expect(nextConfiguation.highlightPostTag).toBeUndefined(); + }); + }); + describe('dispose', () => { it('calls the unmount function', () => { const helper = algoliasearchHelper(fakeClient, 'firstIndex'); @@ -295,7 +315,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/autocomplet expect(nextState.highlightPostTag).toBeUndefined(); }); - it('does not remove the TAG_PLACEHOLDER from the `SearchParameters` with `escapeHTML`', () => { + it('does not remove the TAG_PLACEHOLDER from the `SearchParameters` with `escapeHTML` disabled', () => { const helper = algoliasearchHelper(fakeClient, 'firstIndex', { highlightPreTag: '', highlightPostTag: '', diff --git a/src/connectors/autocomplete/connectAutocomplete.js b/src/connectors/autocomplete/connectAutocomplete.js index 57839b6faf..6dbf8e63d3 100644 --- a/src/connectors/autocomplete/connectAutocomplete.js +++ b/src/connectors/autocomplete/connectAutocomplete.js @@ -57,7 +57,7 @@ export default function connectAutocomplete(renderFn, unmountFn = noop) { return { getConfiguration() { - return escapeHTML ? TAG_PLACEHOLDER : undefined; + return escapeHTML ? TAG_PLACEHOLDER : {}; }, init({ instantSearchInstance, helper }) { From 407ae102c44dd265a79eb4e10b6ee47182bb979f Mon Sep 17 00:00:00 2001 From: Vaillant Samuel Date: Tue, 28 May 2019 10:14:28 +0200 Subject: [PATCH 2/2] feat(connectAutocomplete): mount a default query --- .../__tests__/connectAutocomplete-test.js | 10 ++++++++++ src/connectors/autocomplete/connectAutocomplete.js | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/connectors/autocomplete/__tests__/connectAutocomplete-test.js b/src/connectors/autocomplete/__tests__/connectAutocomplete-test.js index e021fed9f1..8a5740a3e8 100644 --- a/src/connectors/autocomplete/__tests__/connectAutocomplete-test.js +++ b/src/connectors/autocomplete/__tests__/connectAutocomplete-test.js @@ -158,6 +158,16 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/autocomplet }); describe('getConfiguration', () => { + it('adds a `query` to the `SearchParameters`', () => { + const renderFn = () => {}; + const makeWidget = connectAutocomplete(renderFn); + const widget = makeWidget(); + + const nextConfiguation = widget.getConfiguration(); + + expect(nextConfiguation.query).toBe(''); + }); + it('adds the TAG_PLACEHOLDER to the `SearchParameters`', () => { const renderFn = () => {}; const makeWidget = connectAutocomplete(renderFn); diff --git a/src/connectors/autocomplete/connectAutocomplete.js b/src/connectors/autocomplete/connectAutocomplete.js index 6dbf8e63d3..d7030e20a3 100644 --- a/src/connectors/autocomplete/connectAutocomplete.js +++ b/src/connectors/autocomplete/connectAutocomplete.js @@ -57,7 +57,18 @@ export default function connectAutocomplete(renderFn, unmountFn = noop) { return { getConfiguration() { - return escapeHTML ? TAG_PLACEHOLDER : {}; + const parameters = { + query: '', + }; + + if (!escapeHTML) { + return parameters; + } + + return { + ...parameters, + ...TAG_PLACEHOLDER, + }; }, init({ instantSearchInstance, helper }) {