Skip to content

Commit 8c65249

Browse files
samoussHaroenv
authored andcommitted
feat(connectInfiniteHits): add default value on getConfiguration (#3837)
* test(connectInfiniteHits): scope getConfiguration in its own describe * test(connectInfiniteHits): mount a default page
1 parent 724b83f commit 8c65249

File tree

3 files changed

+54
-26
lines changed

3 files changed

+54
-26
lines changed

src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.ts

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
5353
escapeHTML: true,
5454
});
5555

56-
expect(widget.getConfiguration!()).toEqual({
57-
highlightPreTag: TAG_PLACEHOLDER.highlightPreTag,
58-
highlightPostTag: TAG_PLACEHOLDER.highlightPostTag,
59-
});
60-
6156
expect(renderFn).toHaveBeenCalledTimes(0);
6257

6358
const helper = algoliasearchHelper({} as Client, '', {});
@@ -121,17 +116,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
121116
);
122117
});
123118

124-
it('sets the default configuration', () => {
125-
const renderFn = (): void => {};
126-
const makeWidget = connectInfiniteHits(renderFn);
127-
const widget = makeWidget({});
128-
129-
expect(widget.getConfiguration!()).toEqual({
130-
highlightPreTag: TAG_PLACEHOLDER.highlightPreTag,
131-
highlightPostTag: TAG_PLACEHOLDER.highlightPostTag,
132-
});
133-
});
134-
135119
it('Provides the hits and accumulates results on next page', () => {
136120
const renderFn = jest.fn();
137121
const makeWidget = connectInfiniteHits(renderFn);
@@ -624,6 +608,47 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
624608
expect((results.hits as any).__escaped).toBe(true);
625609
});
626610

611+
describe('getConfiguration', () => {
612+
it('adds a `page` to the `SearchParameters`', () => {
613+
const renderFn = (): void => {};
614+
const makeWidget = connectInfiniteHits(renderFn);
615+
const widget = makeWidget({});
616+
617+
const nextConfiguration = widget.getConfiguration!();
618+
619+
expect(nextConfiguration.page).toBe(0);
620+
});
621+
622+
it('adds the TAG_PLACEHOLDER to the `SearchParameters`', () => {
623+
const renderFn = (): void => {};
624+
const makeWidget = connectInfiniteHits(renderFn);
625+
const widget = makeWidget({});
626+
627+
const nextConfiguration = widget.getConfiguration!();
628+
629+
expect(nextConfiguration.highlightPreTag).toBe(
630+
TAG_PLACEHOLDER.highlightPreTag
631+
);
632+
633+
expect(nextConfiguration.highlightPostTag).toBe(
634+
TAG_PLACEHOLDER.highlightPostTag
635+
);
636+
});
637+
638+
it('does not add the TAG_PLACEHOLDER to the `SearchParameters` with `escapeHTML` disabled', () => {
639+
const renderFn = (): void => {};
640+
const makeWidget = connectInfiniteHits(renderFn);
641+
const widget = makeWidget({
642+
escapeHTML: false,
643+
});
644+
645+
const nextConfiguration = widget.getConfiguration!();
646+
647+
expect(nextConfiguration.highlightPreTag).toBeUndefined();
648+
expect(nextConfiguration.highlightPostTag).toBeUndefined();
649+
});
650+
});
651+
627652
describe('dispose', () => {
628653
it('calls the unmount function', () => {
629654
const helper = algoliasearchHelper({} as Client, '', {});
@@ -678,7 +703,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
678703
expect(nextState.highlightPostTag).toBeUndefined();
679704
});
680705

681-
it('does not remove the TAG_PLACEHOLDER from the `SearchParameters` with `escapeHTML`', () => {
706+
it('does not remove the TAG_PLACEHOLDER from the `SearchParameters` with `escapeHTML` disabled', () => {
682707
const helper = algoliasearchHelper({} as Client, '', {
683708
highlightPreTag: '<mark>',
684709
highlightPostTag: '</mark>',

src/connectors/infinite-hits/connectInfiniteHits.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,18 @@ const connectInfiniteHits: InfiniteHitsConnector = (
8585

8686
return {
8787
getConfiguration() {
88-
return escapeHTML ? TAG_PLACEHOLDER : {};
88+
const parameters = {
89+
page: 0,
90+
};
91+
92+
if (!escapeHTML) {
93+
return parameters;
94+
}
95+
96+
return {
97+
...parameters,
98+
...TAG_PLACEHOLDER,
99+
};
89100
},
90101

91102
init({ instantSearchInstance, helper }) {

src/widgets/infinite-hits/__tests__/infinite-hits-test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { render } from 'preact-compat';
22
import algoliasearchHelper from 'algoliasearch-helper';
3-
import { TAG_PLACEHOLDER } from '../../../lib/escape-highlight';
43
import infiniteHits from '../infinite-hits';
54
import { Client } from '../../../types';
65

@@ -53,13 +52,6 @@ describe('infiniteHits()', () => {
5352
};
5453
});
5554

56-
it('It does have a specific configuration', () => {
57-
expect(widget.getConfiguration()).toEqual({
58-
highlightPreTag: TAG_PLACEHOLDER.highlightPreTag,
59-
highlightPostTag: TAG_PLACEHOLDER.highlightPostTag,
60-
});
61-
});
62-
6355
it('calls twice render(<Hits props />, container)', () => {
6456
const state = { page: 0 };
6557
widget.render({ results, state });

0 commit comments

Comments
 (0)