Skip to content

Commit

Permalink
feat(connectHits): implement getWidgetSearchParameters (#4001)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored and Haroenv committed Oct 23, 2019
1 parent 9b81eae commit c77cf66
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/connectors/hits/__tests__/connectHits-test.js
Expand Up @@ -400,6 +400,30 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
expect(results.hits.__escaped).toBe(true);
});

describe('getWidgetSearchParameters', () => {
it('adds the TAG_PLACEHOLDER to the `SearchParameters`', () => {
const render = () => {};
const makeWidget = connectHits(render);
const widget = makeWidget();

const actual = widget.getWidgetSearchParameters(new SearchParameters());

expect(actual).toEqual(new SearchParameters(TAG_PLACEHOLDER));
});

it('does not add the TAG_PLACEHOLDER to the `SearchParameters` with `escapeHTML` disabled', () => {
const render = () => {};
const makeWidget = connectHits(render);
const widget = makeWidget({
escapeHTML: false,
});

const actual = widget.getWidgetSearchParameters(new SearchParameters());

expect(actual).toEqual(new SearchParameters());
});
});

describe('dispose', () => {
it('calls the unmount function', () => {
const helper = algoliasearchHelper({}, '');
Expand Down Expand Up @@ -451,7 +475,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
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({}, '', {
highlightPreTag: '<mark>',
highlightPostTag: '</mark>',
Expand Down
8 changes: 8 additions & 0 deletions src/connectors/hits/connectHits.js
Expand Up @@ -130,6 +130,14 @@ export default function connectHits(renderFn, unmountFn = noop) {
)
);
},

getWidgetSearchParameters(state) {
if (!escapeHTML) {
return state;
}

return state.setQueryParameters(TAG_PLACEHOLDER);
},
};
};
}

0 comments on commit c77cf66

Please sign in to comment.