Skip to content

Commit

Permalink
feat(recommend): introduce trendingItems widget (#6171)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhayab committed May 21, 2024
1 parent 22ea4a5 commit 186ccbe
Show file tree
Hide file tree
Showing 10 changed files with 837 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
},
{
"path": "./packages/instantsearch.js/dist/instantsearch.production.min.js",
"maxSize": "80 kB"
"maxSize": "80.5 kB"
},
{
"path": "./packages/instantsearch.js/dist/instantsearch.development.js",
"maxSize": "175.25 kB"
"maxSize": "175.75 kB"
},
{
"path": "packages/react-instantsearch-core/dist/umd/ReactInstantSearchCore.min.js",
Expand Down
23 changes: 23 additions & 0 deletions packages/instantsearch.js/src/__tests__/common-widgets.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
numericMenu,
relatedProducts,
frequentlyBoughtTogether,
trendingItems,
} from '../widgets';

import type { TestOptionsMap, TestSetupsMap } from '@instantsearch/tests';
Expand Down Expand Up @@ -513,6 +514,27 @@ const testSetups: TestSetupsMap<TestSuites> = {
})
.start();
},
createTrendingItemsWidgetTests({ instantSearchOptions, widgetParams }) {
const { facetName, facetValue, ...params } = widgetParams;
const facetParams =
facetName && facetValue ? { facetName, facetValue } : {};

instantsearch(instantSearchOptions)
.addWidgets([
trendingItems({
container: document.body.appendChild(document.createElement('div')),
...facetParams,
...params,
}),
])
.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 @@ -540,6 +562,7 @@ const testOptions: TestOptionsMap<TestSuites> = {
createNumericMenuWidgetTests: undefined,
createRelatedProductsWidgetTests: undefined,
createFrequentlyBoughtTogetherTests: undefined,
createTrendingItemsWidgetTests: undefined,
};

describe('Common widget tests (InstantSearch.js)', () => {
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 @@ -47,5 +47,6 @@ export { default as searchBox } from './search-box/search-box';
export { default as sortBy } from './sort-by/sort-by';
export { default as stats } from './stats/stats';
export { default as toggleRefinement } from './toggle-refinement/toggle-refinement';
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';
Loading

0 comments on commit 186ccbe

Please sign in to comment.