Skip to content

Commit

Permalink
fix(queryPreviewList): repeated query loading issue (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegopf authored Jul 18, 2024
1 parent b1d2459 commit 60aa0c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ describe('testing QueryPreviewList', () => {
expect(queryPreviews.wrappers).toHaveLength(1);
expect(queryPreviews.at(0).text()).toEqual('shoes - Crazy shoes');
});

it('load next batch when it contains duplicates', async () => {
const { getQueryPreviewItemWrappers, reRender, wrapper } = renderQueryPreviewList({
queriesPreviewInfo: [{ query: 'shirt' }, { query: 'jeans' }],
results: {
shirt: [createResultStub('Cool shirt')],
jeans: [createResultStub('Sick jeans')],
dress: [createResultStub('cool dress ')]
}
});
await reRender();
let queryPreviews = getQueryPreviewItemWrappers();
expect(queryPreviews.wrappers).toHaveLength(2);
wrapper.setProps({
queriesPreviewInfo: [{ query: 'shirt' }, { query: 'jeans' }, { query: 'dress' }]
});
await reRender();
queryPreviews = getQueryPreviewItemWrappers();
expect(queryPreviews.wrappers).toHaveLength(3);
});
});

interface RenderQueryPreviewListOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@
queries,
(newQueries: string[], oldQueries: string[] | undefined) => {
if (newQueries.toString() !== oldQueries?.toString()) {
queriesStatus.value = {};
for (const key of Object.keys(queriesStatus.value)) {
if (!newQueries.includes(key)) {
delete queriesStatus.value[key];
}
}
loadNext();
}
},
Expand Down

0 comments on commit 60aa0c0

Please sign in to comment.