Skip to content

Commit

Permalink
chore: fix pr comments and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lauramargar committed Sep 20, 2023
1 parent f068128 commit bf9e743
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Filter[]>);
return {
query: this.queryPreviewInfo.query,
rows: this.config.maxItemsToRequest,
extraParams: { ...this.params, ...this.queryPreviewInfo.extraParams },
filters: filtersApply,
filters: filters,
...(origin && { origin })
};
}
Expand Down

0 comments on commit bf9e743

Please sign in to comment.