Skip to content

Commit

Permalink
feat(recommend): introduce lookingSimilar widget (#6183)
Browse files Browse the repository at this point in the history
* feat(recommend): add lookingSimilar widget

FX-2836

* test(recommend): correct initialisation

* fix: pass fallbackParameters

* test: ensure parameters get forwarded correctly
  • Loading branch information
Haroenv authored and dhayab committed May 21, 2024
1 parent 78a7723 commit 6fae57c
Show file tree
Hide file tree
Showing 13 changed files with 1,153 additions and 10 deletions.
18 changes: 18 additions & 0 deletions packages/instantsearch.js/src/__tests__/common-widgets.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
relatedProducts,
frequentlyBoughtTogether,
trendingItems,
lookingSimilar,
} from '../widgets';

import type { TestOptionsMap, TestSetupsMap } from '@instantsearch/tests';
Expand Down Expand Up @@ -535,6 +536,22 @@ const testSetups: TestSetupsMap<TestSuites> = {
})
.start();
},
createLookingSimilarTests({ instantSearchOptions, widgetParams }) {
instantsearch(instantSearchOptions)
.addWidgets([
lookingSimilar({
container: document.body.appendChild(document.createElement('div')),
...widgetParams,
}),
])
.on('error', () => {
/*
* prevent rethrowing InstantSearch errors, so tests can be asserted.
* IRL this isn't needed, as the error doesn't stop execution.
*/
})
.start();
},
};

const testOptions: TestOptionsMap<TestSuites> = {
Expand Down Expand Up @@ -563,6 +580,7 @@ const testOptions: TestOptionsMap<TestSuites> = {
createRelatedProductsWidgetTests: undefined,
createFrequentlyBoughtTogetherTests: undefined,
createTrendingItemsWidgetTests: undefined,
createLookingSimilarTests: undefined,
};

describe('Common widget tests (InstantSearch.js)', () => {
Expand Down
15 changes: 5 additions & 10 deletions packages/instantsearch.js/src/widgets/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,12 @@ function initiateAllWidgets(): Array<[WidgetNames, Widget | IndexWidget]> {
const EXPERIMENTAL_answers = widget as Widgets['EXPERIMENTAL_answers'];
return EXPERIMENTAL_answers({ container, queryLanguages: ['en'] });
}
case 'frequentlyBoughtTogether': {
const frequentlyBoughtTogether =
case 'frequentlyBoughtTogether':
case 'relatedProducts':
case 'lookingSimilar': {
const recommendWidgetWithObjectIDs =
widget as Widgets['frequentlyBoughtTogether'];
return frequentlyBoughtTogether({
container,
objectIDs: ['objectID'],
});
}
case 'relatedProducts': {
const relatedProducts = widget as Widgets['relatedProducts'];
return relatedProducts({
return recommendWidgetWithObjectIDs({
container,
objectIDs: ['objectID'],
});
Expand Down
1 change: 1 addition & 0 deletions packages/instantsearch.js/src/widgets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ export { default as toggleRefinement } from './toggle-refinement/toggle-refineme
export { default as trendingItems } from './trending-items/trending-items';
export { default as voiceSearch } from './voice-search/voice-search';
export { default as frequentlyBoughtTogether } from './frequently-bought-together/frequently-bought-together';
export { default as lookingSimilar } from './looking-similar/looking-similar';

0 comments on commit 6fae57c

Please sign in to comment.