Skip to content

Commit

Permalink
fix: unwanted snapshot update
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisie96 authored and shauke committed Sep 6, 2022
1 parent 8979484 commit 090ff73
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { provideMockStore } from '@ngrx/store/testing';

import {
DEFAULT_PRODUCT_LISTING_VIEW_TYPE,
DEFAULT_PRODUCT_LISTING_VIEW_TYPE_MOBILE,
PRODUCT_LISTING_ITEMS_PER_PAGE,
} from 'ish-core/configurations/injection-keys';
import { getDeviceType } from 'ish-core/store/core/configuration';
import { CoreStoreModule } from 'ish-core/store/core/core-store.module';
import { ShoppingStoreModule } from 'ish-core/store/shopping/shopping-store.module';
import { StoreWithSnapshots, provideStoreSnapshots } from 'ish-core/utils/dev/ngrx-testing';
Expand All @@ -24,17 +22,14 @@ describe('Product Listing Effects', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
CoreStoreModule.forTesting(['router'], [ProductListingEffects]),
CoreStoreModule.forTesting(['router', 'configuration'], [ProductListingEffects]),
RouterTestingModule.withRoutes([{ path: 'some', children: [] }]),
ShoppingStoreModule.forTesting('productListing'),
],
providers: [
{ provide: DEFAULT_PRODUCT_LISTING_VIEW_TYPE_MOBILE, useValue: 'list' },
{ provide: DEFAULT_PRODUCT_LISTING_VIEW_TYPE, useValue: 'list' },
{ provide: PRODUCT_LISTING_ITEMS_PER_PAGE, useValue: 7 },
provideMockStore({
selectors: [{ selector: getDeviceType, value: 'desktop' }],
}),
provideStoreSnapshots(),
],
});
Expand Down Expand Up @@ -79,15 +74,43 @@ describe('Product Listing Effects', () => {

tick(0);

expect(store$.actionsArray()).toMatchInlineSnapshot(`Array []`);
expect(store$.actionsArray()).toMatchInlineSnapshot(`
[Product Listing] Load More Products:
id: {"type":"search","value":"term"}
[Product Listing Internal] Load More Products For Params:
id: {"type":"search","value":"term"}
filters: undefined
sorting: "name-asc"
page: undefined
[Search Internal] Search Products:
searchTerm: "term"
page: undefined
sorting: "name-asc"
[Filter Internal] Load Filter for Search:
searchTerm: "term"
`);
}));

it('should fire all necessary actions for family page', fakeAsync(() => {
store$.dispatch(loadMoreProducts({ id: { type: 'category', value: 'cat' } }));

tick(0);

expect(store$.actionsArray()).toMatchInlineSnapshot(`Array []`);
expect(store$.actionsArray()).toMatchInlineSnapshot(`
[Product Listing] Load More Products:
id: {"type":"category","value":"cat"}
[Product Listing Internal] Load More Products For Params:
id: {"type":"category","value":"cat"}
filters: undefined
sorting: "name-asc"
page: undefined
[Products Internal] Load Products for Category:
categoryId: "cat"
page: undefined
sorting: "name-asc"
[Filter Internal] Load Filter For Category:
uniqueId: "cat"
`);
}));
});

Expand All @@ -103,7 +126,22 @@ describe('Product Listing Effects', () => {

tick(0);

expect(store$.actionsArray()).toMatchInlineSnapshot(`Array []`);
expect(store$.actionsArray()).toMatchInlineSnapshot(`
[Product Listing] Load More Products:
id: {"type":"search","value":"term"}
[Product Listing Internal] Load More Products For Params:
id: {"type":"search","value":"term","filters":{"param":[1],"sear...
filters: {"param":[1],"searchTerm":[1]}
sorting: undefined
page: undefined
[Filter Internal] Load Products For Filter:
id: {"type":"search","value":"term","filters":{"param":[1],"sear...
searchParameter: {"param":[1],"searchTerm":[1]}
page: undefined
sorting: undefined
[Filter] Apply Filter:
searchParameter: {"param":[1],"searchTerm":[1]}
`);
expect(store$.actionsArray()[1]).toHaveProperty('payload.filters.param', ['foobar']);
expect(store$.actionsArray()[1]).toHaveProperty('payload.filters.searchTerm', ['term']);
}));
Expand All @@ -113,7 +151,22 @@ describe('Product Listing Effects', () => {

tick(0);

expect(store$.actionsArray()).toMatchInlineSnapshot(`Array []`);
expect(store$.actionsArray()).toMatchInlineSnapshot(`
[Product Listing] Load More Products:
id: {"type":"category","value":"cat"}
[Product Listing Internal] Load More Products For Params:
id: {"type":"category","value":"cat","filters":{"param":[1]}}
filters: {"param":[1]}
sorting: undefined
page: undefined
[Filter Internal] Load Products For Filter:
id: {"type":"category","value":"cat","filters":{"param":[1]}}
searchParameter: {"param":[1]}
page: undefined
sorting: undefined
[Filter] Apply Filter:
searchParameter: {"param":[1]}
`);
}));
});
});
2 changes: 1 addition & 1 deletion src/app/core/store/shopping/search/search.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Search Effects', () => {

TestBed.configureTestingModule({
imports: [
CoreStoreModule.forTesting(['router'], [SearchEffects, ProductListingEffects]),
CoreStoreModule.forTesting(['router', 'configuration'], [SearchEffects, ProductListingEffects]),
RouterTestingModule.withRoutes([
{ path: 'error', children: [] },
{ path: 'search/:searchTerm', children: [] },
Expand Down

0 comments on commit 090ff73

Please sign in to comment.