Skip to content

Commit a9efc4f

Browse files
authored
fix(recommend): omit fallbackParameters from query when not passed as params (#6716)
1 parent a6d4cb5 commit a9efc4f

File tree

6 files changed

+170
-18
lines changed

6 files changed

+170
-18
lines changed

packages/instantsearch.js/src/connectors/looking-similar/__tests__/connectLookingSimilar-test.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ describe('connectLookingSimilar', () => {
118118
maxRecommendations: 10,
119119
threshold: 95,
120120
queryParameters: { userToken: 'token' },
121-
fallbackParameters: {},
122121
})
123122
.addLookingSimilar({
124123
// @ts-expect-error
@@ -127,7 +126,62 @@ describe('connectLookingSimilar', () => {
127126
maxRecommendations: 10,
128127
threshold: 95,
129128
queryParameters: { userToken: 'token' },
130-
fallbackParameters: {},
129+
})
130+
);
131+
});
132+
133+
it('adds escapeHTML tags', () => {
134+
const render = () => {};
135+
const makeWidget = connectLookingSimilar(render);
136+
const widget = makeWidget({
137+
objectIDs: ['1', '2'],
138+
limit: 10,
139+
threshold: 95,
140+
queryParameters: { userToken: 'token' },
141+
fallbackParameters: { query: 'query' },
142+
escapeHTML: true,
143+
});
144+
145+
// @ts-expect-error
146+
const actual = widget.getWidgetParameters(new RecommendParameters(), {
147+
uiState: {},
148+
});
149+
150+
expect(actual).toEqual(
151+
new RecommendParameters()
152+
.addLookingSimilar({
153+
// @ts-expect-error
154+
$$id: widget.$$id,
155+
objectID: '1',
156+
maxRecommendations: 10,
157+
threshold: 95,
158+
queryParameters: {
159+
userToken: 'token',
160+
highlightPostTag: '__/ais-highlight__',
161+
highlightPreTag: '__ais-highlight__',
162+
},
163+
fallbackParameters: {
164+
query: 'query',
165+
highlightPostTag: '__/ais-highlight__',
166+
highlightPreTag: '__ais-highlight__',
167+
},
168+
})
169+
.addLookingSimilar({
170+
// @ts-expect-error
171+
$$id: widget.$$id,
172+
objectID: '2',
173+
maxRecommendations: 10,
174+
threshold: 95,
175+
queryParameters: {
176+
userToken: 'token',
177+
highlightPostTag: '__/ais-highlight__',
178+
highlightPreTag: '__ais-highlight__',
179+
},
180+
fallbackParameters: {
181+
query: 'query',
182+
highlightPostTag: '__/ais-highlight__',
183+
highlightPreTag: '__ais-highlight__',
184+
},
131185
})
132186
);
133187
});

packages/instantsearch.js/src/connectors/looking-similar/connectLookingSimilar.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,12 @@ export default (function connectLookingSimilar<
215215
objectID,
216216
maxRecommendations: limit,
217217
threshold,
218-
fallbackParameters: {
219-
...fallbackParameters,
220-
...(escapeHTML ? TAG_PLACEHOLDER : {}),
221-
},
218+
fallbackParameters: fallbackParameters
219+
? {
220+
...fallbackParameters,
221+
...(escapeHTML ? TAG_PLACEHOLDER : {}),
222+
}
223+
: undefined,
222224
queryParameters: {
223225
...queryParameters,
224226
...(escapeHTML ? TAG_PLACEHOLDER : {}),

packages/instantsearch.js/src/connectors/related-products/__tests__/connectRelatedProducts-test.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ describe('connectRelatedProducts', () => {
118118
maxRecommendations: 10,
119119
threshold: 95,
120120
queryParameters: { userToken: 'token' },
121-
fallbackParameters: {},
122121
})
123122
.addRelatedProducts({
124123
// @ts-expect-error
@@ -127,7 +126,62 @@ describe('connectRelatedProducts', () => {
127126
maxRecommendations: 10,
128127
threshold: 95,
129128
queryParameters: { userToken: 'token' },
130-
fallbackParameters: {},
129+
})
130+
);
131+
});
132+
133+
it('adds escapeHTML tags', () => {
134+
const render = () => {};
135+
const makeWidget = connectRelatedProducts(render);
136+
const widget = makeWidget({
137+
objectIDs: ['1', '2'],
138+
limit: 10,
139+
threshold: 95,
140+
queryParameters: { userToken: 'token' },
141+
fallbackParameters: { query: 'query' },
142+
escapeHTML: true,
143+
});
144+
145+
// @ts-expect-error
146+
const actual = widget.getWidgetParameters(new RecommendParameters(), {
147+
uiState: {},
148+
});
149+
150+
expect(actual).toEqual(
151+
new RecommendParameters()
152+
.addRelatedProducts({
153+
// @ts-expect-error
154+
$$id: widget.$$id,
155+
objectID: '1',
156+
maxRecommendations: 10,
157+
threshold: 95,
158+
queryParameters: {
159+
userToken: 'token',
160+
highlightPostTag: '__/ais-highlight__',
161+
highlightPreTag: '__ais-highlight__',
162+
},
163+
fallbackParameters: {
164+
highlightPostTag: '__/ais-highlight__',
165+
highlightPreTag: '__ais-highlight__',
166+
query: 'query',
167+
},
168+
})
169+
.addRelatedProducts({
170+
// @ts-expect-error
171+
$$id: widget.$$id,
172+
objectID: '2',
173+
maxRecommendations: 10,
174+
threshold: 95,
175+
queryParameters: {
176+
userToken: 'token',
177+
highlightPostTag: '__/ais-highlight__',
178+
highlightPreTag: '__ais-highlight__',
179+
},
180+
fallbackParameters: {
181+
highlightPostTag: '__/ais-highlight__',
182+
highlightPreTag: '__ais-highlight__',
183+
query: 'query',
184+
},
131185
})
132186
);
133187
});

packages/instantsearch.js/src/connectors/related-products/connectRelatedProducts.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,12 @@ export default (function connectRelatedProducts<
216216
objectID,
217217
maxRecommendations: limit,
218218
threshold,
219-
fallbackParameters: {
220-
...fallbackParameters,
221-
...(escapeHTML ? TAG_PLACEHOLDER : {}),
222-
},
219+
fallbackParameters: fallbackParameters
220+
? {
221+
...fallbackParameters,
222+
...(escapeHTML ? TAG_PLACEHOLDER : {}),
223+
}
224+
: undefined,
223225
queryParameters: {
224226
...queryParameters,
225227
...(escapeHTML ? TAG_PLACEHOLDER : {}),

packages/instantsearch.js/src/connectors/trending-items/__tests__/connectTrendingItems-test.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ describe('connectTrendingItems', () => {
134134
maxRecommendations: 10,
135135
threshold: 95,
136136
queryParameters: { userToken: 'token' },
137-
fallbackParameters: {},
138137
})
139138
);
140139
});
@@ -165,7 +164,46 @@ describe('connectTrendingItems', () => {
165164
maxRecommendations: 10,
166165
threshold: 95,
167166
queryParameters: { userToken: 'token' },
168-
fallbackParameters: {},
167+
})
168+
);
169+
});
170+
171+
it('adds escapeHTML tags', () => {
172+
const render = () => {};
173+
const makeWidget = connectTrendingItems(render);
174+
const widget = makeWidget({
175+
facetName: 'key',
176+
facetValue: 'value',
177+
limit: 10,
178+
threshold: 95,
179+
queryParameters: { userToken: 'token' },
180+
escapeHTML: true,
181+
fallbackParameters: { query: 'query' },
182+
});
183+
184+
// @ts-expect-error
185+
const actual = widget.getWidgetParameters(new RecommendParameters(), {
186+
uiState: {},
187+
});
188+
189+
expect(actual).toEqual(
190+
new RecommendParameters().addTrendingItems({
191+
// @ts-expect-error
192+
$$id: widget.$$id,
193+
facetName: 'key',
194+
facetValue: 'value',
195+
maxRecommendations: 10,
196+
threshold: 95,
197+
queryParameters: {
198+
userToken: 'token',
199+
highlightPostTag: '__/ais-highlight__',
200+
highlightPreTag: '__ais-highlight__',
201+
},
202+
fallbackParameters: {
203+
highlightPostTag: '__/ais-highlight__',
204+
highlightPreTag: '__ais-highlight__',
205+
query: 'query',
206+
},
169207
})
170208
);
171209
});

packages/instantsearch.js/src/connectors/trending-items/connectTrendingItems.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,12 @@ export default (function connectTrendingItems<
235235
facetValue: facetValue as string,
236236
maxRecommendations: limit,
237237
threshold,
238-
fallbackParameters: {
239-
...fallbackParameters,
240-
...(escapeHTML ? TAG_PLACEHOLDER : {}),
241-
},
238+
fallbackParameters: fallbackParameters
239+
? {
240+
...fallbackParameters,
241+
...(escapeHTML ? TAG_PLACEHOLDER : {}),
242+
}
243+
: undefined,
242244
queryParameters: {
243245
...queryParameters,
244246
...(escapeHTML ? TAG_PLACEHOLDER : {}),

0 commit comments

Comments
 (0)