Skip to content

Commit

Permalink
Merge branch 'next' into feat/lifecycle-search-box
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored Jul 31, 2019
2 parents 59e9c27 + 180e80d commit 1004fa8
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
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,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('does not throw without the unmount function', () => {
const rendering = () => {};
Expand Down Expand Up @@ -448,7 +472,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
Original file line number Diff line number Diff line change
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 1004fa8

Please sign in to comment.