diff --git a/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts b/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts index 8fabdef16b..18fadcb0e4 100644 --- a/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts +++ b/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts @@ -103,7 +103,11 @@ describe('query preview', () => { it('sends the `QueryPreviewRequestUpdated` event', async () => { const { queryPreviewRequestUpdatedSpy, wrapper, updateExtraParams } = renderQueryPreview({ - queryPreviewInfo: { query: 'shoes', extraParams: { directory: 'Magrathea' } } + queryPreviewInfo: { + query: 'shoes', + extraParams: { directory: 'Magrathea' }, + filters: ['fit:regular'] + } }); jest.advanceTimersByTime(0); // Wait for first emission. @@ -112,6 +116,15 @@ describe('query preview', () => { extraParams: { directory: 'Magrathea' }, + filters: { + fit: [ + { + id: 'fit:regular', + modelName: 'RawFilter', + selected: true + } + ] + }, origin: undefined, query: 'shoes', rows: 24 @@ -126,6 +139,15 @@ describe('query preview', () => { extraParams: { directory: 'Magrathea' }, + filters: { + fit: [ + { + id: 'fit:regular', + modelName: 'RawFilter', + selected: true + } + ] + }, origin: 'popular_search:none', query: 'shoes', rows: 24 @@ -139,6 +161,15 @@ describe('query preview', () => { directory: 'Magrathea', store: 'Uganda' }, + filters: { + fit: [ + { + id: 'fit:regular', + modelName: 'RawFilter', + selected: true + } + ] + }, origin: 'popular_search:none', query: 'shoes', rows: 24 diff --git a/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue b/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue index 186668b617..10d7f7dc43 100644 --- a/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue +++ b/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue @@ -162,19 +162,21 @@ feature: this.queryFeature, location: this.location }); - const filtersApply = this.queryPreviewInfo.filters?.reduce((filtersList, filterId) => { + const filters = this.queryPreviewInfo.filters?.reduce((filtersList, filterId) => { const facetId = filterId.split(':')[0]; const rawFilter = createRawFilter(filterId); filtersList[facetId] = filtersList[facetId] ? filtersList[facetId].concat(rawFilter) : [rawFilter]; + return filtersList; }, {} as Record); + return { query: this.queryPreviewInfo.query, rows: this.config.maxItemsToRequest, extraParams: { ...this.params, ...this.queryPreviewInfo.extraParams }, - filters: filtersApply, + filters: filters, ...(origin && { origin }) }; }