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

feat(connectAutocomplete): add default value on getConfiguration #3836

Merged
merged 2 commits into from
Jun 3, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions src/connectors/autocomplete/__tests__/connectAutocomplete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -168,6 +157,47 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/autocomplet
expect(rendering.indices[0].hits).toEqual(hits);
});

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);
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');
Expand Down Expand Up @@ -295,7 +325,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: '<mark>',
highlightPostTag: '</mark>',
Expand Down
13 changes: 12 additions & 1 deletion src/connectors/autocomplete/connectAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ export default function connectAutocomplete(renderFn, unmountFn = noop) {

return {
getConfiguration() {
return escapeHTML ? TAG_PLACEHOLDER : undefined;
const parameters = {
query: '',
};

if (!escapeHTML) {
return parameters;
}

return {
...parameters,
...TAG_PLACEHOLDER,
};
},

init({ instantSearchInstance, helper }) {
Expand Down