Skip to content

Commit

Permalink
fix(hits): update lifecycle state (#3977)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour authored and Haroenv committed Oct 23, 2019
1 parent d21d620 commit 6e55ba6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
25 changes: 16 additions & 9 deletions src/connectors/hits/__tests__/connectHits-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import algoliasearchHelper, { SearchResults } from 'algoliasearch-helper';
import algoliasearchHelper, {
SearchParameters,
SearchResults,
} from 'algoliasearch-helper';
import { TAG_PLACEHOLDER } from '../../../lib/escape-highlight';
import connectHits from '../connectHits';

Expand Down Expand Up @@ -43,10 +46,12 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
const makeWidget = connectHits(renderFn);
const widget = makeWidget({ escapeHTML: true });

expect(widget.getConfiguration()).toEqual({
highlightPreTag: TAG_PLACEHOLDER.highlightPreTag,
highlightPostTag: TAG_PLACEHOLDER.highlightPostTag,
});
expect(widget.getConfiguration(new SearchParameters({}))).toEqual(
new SearchParameters({
highlightPreTag: TAG_PLACEHOLDER.highlightPreTag,
highlightPostTag: TAG_PLACEHOLDER.highlightPostTag,
})
);

// test if widget is not rendered yet at this point
expect(renderFn).toHaveBeenCalledTimes(0);
Expand Down Expand Up @@ -85,10 +90,12 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
const makeWidget = connectHits(renderFn);
const widget = makeWidget();

expect(widget.getConfiguration()).toEqual({
highlightPreTag: TAG_PLACEHOLDER.highlightPreTag,
highlightPostTag: TAG_PLACEHOLDER.highlightPostTag,
});
expect(widget.getConfiguration(new SearchParameters({}))).toEqual(
new SearchParameters({
highlightPreTag: TAG_PLACEHOLDER.highlightPreTag,
highlightPostTag: TAG_PLACEHOLDER.highlightPostTag,
})
);
});

it('Provides the hits and the whole results', () => {
Expand Down
8 changes: 6 additions & 2 deletions src/connectors/hits/connectHits.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ export default function connectHits(renderFn, unmountFn = noop) {
return {
$$type: 'ais.hits',

getConfiguration() {
return escapeHTML ? TAG_PLACEHOLDER : undefined;
getConfiguration(state) {
if (!escapeHTML) {
return state;
}

return state.setQueryParameters(TAG_PLACEHOLDER);
},

init({ instantSearchInstance }) {
Expand Down

0 comments on commit 6e55ba6

Please sign in to comment.