Skip to content

Commit

Permalink
fix: suppress the wrong display of Search-No-Results page after a sea…
Browse files Browse the repository at this point in the history
…rch (#1679)

* this happened if a query parameter like a filter has been set before
  • Loading branch information
SGrueber authored Jun 24, 2024
1 parent d2e6c82 commit 3a92e22
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('Product Listing Effects', () => {
it('should fire all necessary actions for search page', fakeAsync(() => {
store$.dispatch(loadMoreProducts({ id: { type: 'search', value: 'term' } }));

tick(0);
tick(5);

expect(store$.actionsArray()).toMatchInlineSnapshot(`
[Product Listing] Load More Products:
Expand All @@ -92,7 +92,7 @@ describe('Product Listing Effects', () => {
it('should fire all necessary actions for family page', fakeAsync(() => {
store$.dispatch(loadMoreProducts({ id: { type: 'category', value: 'cat' } }));

tick(0);
tick(5);

expect(store$.actionsArray()).toMatchInlineSnapshot(`
[Product Listing] Load More Products:
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('Product Listing Effects', () => {
it('should fire all necessary actions for search page', fakeAsync(() => {
store$.dispatch(loadMoreProducts({ id: { type: 'search', value: 'term' } }));

tick(0);
tick(5);

expect(store$.actionsArray()).toMatchInlineSnapshot(`
[Product Listing] Load More Products:
Expand All @@ -147,7 +147,7 @@ describe('Product Listing Effects', () => {
it('should fire all necessary actions for family page', fakeAsync(() => {
store$.dispatch(loadMoreProducts({ id: { type: 'category', value: 'cat' } }));

tick(0);
tick(5);

expect(store$.actionsArray()).toMatchInlineSnapshot(`
[Product Listing] Load More Products:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Inject, Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Store, select } from '@ngrx/store';
import { isEqual } from 'lodash-es';
import { distinctUntilChanged, filter, map, switchMap, take, withLatestFrom } from 'rxjs/operators';
import { debounceTime, distinctUntilChanged, filter, map, switchMap, take, withLatestFrom } from 'rxjs/operators';

import {
DEFAULT_PRODUCT_LISTING_VIEW_TYPE,
Expand Down Expand Up @@ -125,6 +125,8 @@ export class ProductListingEffects {
);
}),
distinctUntilChanged(isEqual),
// prevent an unnecessary loadMoreProductsForParamsAction in case a new search is triggered and a query parameter like a filter had been previously been set
debounceTime(1),
map(({ id, filters, sorting, page }) => loadMoreProductsForParams({ id, filters, sorting, page }))
)
);
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/store/shopping/search/search.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ describe('Search Effects', () => {
verify(productsServiceMock.searchProducts(searchTerm, 12, anything(), 0)).once();

store$.dispatch(loadMoreProducts({ id: { type: 'search', value: searchTerm }, page: 2 }));
tick(5);
verify(productsServiceMock.searchProducts(searchTerm, 12, anything(), 12)).once();

store$.dispatch(loadMoreProducts({ id: { type: 'search', value: searchTerm }, page: 3 }));
tick(5);
verify(productsServiceMock.searchProducts(searchTerm, 12, anything(), 24)).once();
}));
});
Expand Down
20 changes: 10 additions & 10 deletions src/app/core/store/shopping/shopping-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ describe('Shopping Store', () => {
expect(store.actionsArray()).toMatchInlineSnapshot(`
@ngrx/router-store/request: /category/A.123.456
@ngrx/router-store/navigation: /category/A.123.456
[Product Listing] Load More Products:
id: {"type":"category","value":"A.123.456"}
[Viewconf Internal] Set Breadcrumb Data:
breadcrumbData: [{"text":"nA","link":"/na-ctgA"},{"text":"nA123","link":"/na...
@ngrx/router-store/navigated: /category/A.123.456
[Product Listing] Load More Products:
id: {"type":"category","value":"A.123.456"}
[Viewconf Internal] Set Breadcrumb Data:
Expand All @@ -594,11 +599,6 @@ describe('Shopping Store', () => {
sortableAttributes: []
[Filter API] Load Filter Success:
filterNavigation: {}
@ngrx/router-store/navigated: /category/A.123.456
[Product Listing] Load More Products:
id: {"type":"category","value":"A.123.456"}
[Viewconf Internal] Set Breadcrumb Data:
breadcrumbData: [{"text":"nA","link":"/na-ctgA"},{"text":"nA123","link":"/na...
`);
}));
});
Expand Down Expand Up @@ -693,6 +693,11 @@ describe('Shopping Store', () => {
expect(store.actionsArray()).toMatchInlineSnapshot(`
@ngrx/router-store/request: /category/A.123.456
@ngrx/router-store/navigation: /category/A.123.456
[Product Listing] Load More Products:
id: {"type":"category","value":"A.123.456"}
[Viewconf Internal] Set Breadcrumb Data:
breadcrumbData: [{"text":"nA","link":"/na-ctgA"},{"text":"nA123","link":"/na...
@ngrx/router-store/navigated: /category/A.123.456
[Product Listing] Load More Products:
id: {"type":"category","value":"A.123.456"}
[Viewconf Internal] Set Breadcrumb Data:
Expand All @@ -719,11 +724,6 @@ describe('Shopping Store', () => {
sortableAttributes: []
[Filter API] Load Filter Success:
filterNavigation: {}
@ngrx/router-store/navigated: /category/A.123.456
[Product Listing] Load More Products:
id: {"type":"category","value":"A.123.456"}
[Viewconf Internal] Set Breadcrumb Data:
breadcrumbData: [{"text":"nA","link":"/na-ctgA"},{"text":"nA123","link":"/na...
`);
}));
});
Expand Down

0 comments on commit 3a92e22

Please sign in to comment.