Skip to content

Commit

Permalink
fix: display filter navigation after page refresh with logged in user (
Browse files Browse the repository at this point in the history
…#1232, #1286)

closes: #1232
  • Loading branch information
SGrueber authored and shauke committed Oct 7, 2022
1 parent a1cf6c8 commit c6bbe51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/app/core/store/shopping/filter/filter.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { anything, deepEqual, instance, mock, verify, when } from 'ts-mockito';

import { FilterNavigation } from 'ish-core/models/filter-navigation/filter-navigation.model';
import { FilterService } from 'ish-core/services/filter/filter.service';
import { personalizationStatusDetermined } from 'ish-core/store/customer/user';
import { setProductListingPageSize } from 'ish-core/store/shopping/product-listing';
import { makeHttpError } from 'ish-core/utils/dev/api-service-utils';

Expand Down Expand Up @@ -80,7 +81,8 @@ describe('Filter Effects', () => {
describe('loadAvailableFilters$', () => {
it('should call the filterService for LoadFilterForCategories action', done => {
const action = loadFilterForCategory({ uniqueId: 'c' });
actions$ = of(action);

actions$ = of(personalizationStatusDetermined, action);

effects.loadAvailableFilters$.subscribe(() => {
verify(filterServiceMock.getFilterForCategory(anything())).once();
Expand All @@ -90,7 +92,7 @@ describe('Filter Effects', () => {

it('should call the filterService for loadFilterForSearch action', done => {
const action = loadFilterForSearch({ searchTerm: 'c' });
actions$ = of(action);
actions$ = of(personalizationStatusDetermined, action);

effects.loadAvailableFilters$.subscribe(() => {
verify(filterServiceMock.getFilterForSearch(anything())).once();
Expand All @@ -100,7 +102,7 @@ describe('Filter Effects', () => {

it('should call the filterService for loadFilterForMaster action', done => {
const action = loadFilterForMaster({ masterSKU: 'c' });
actions$ = of(action);
actions$ = of(personalizationStatusDetermined, action);

effects.loadAvailableFilters$.subscribe(() => {
verify(filterServiceMock.getFilterForMaster(anything())).once();
Expand All @@ -111,17 +113,17 @@ describe('Filter Effects', () => {
it('should map to action of type LoadFilterSuccess', () => {
const action = loadFilterForCategory({ uniqueId: 'c' });
const completion = loadFilterSuccess({ filterNavigation: filterNav });
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
actions$ = hot('b-a-a-a', { a: action, b: personalizationStatusDetermined });
const expected$ = cold('--c-c-c', { c: completion });

expect(effects.loadAvailableFilters$).toBeObservable(expected$);
});

it('should map invalid request to action of type LoadFilterFail', () => {
const action = loadFilterForCategory({ uniqueId: 'invalid' });
const completion = loadFilterFail({ error: makeHttpError({ message: 'invalid' }) });
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
actions$ = hot('b-a-a-a', { a: action, b: personalizationStatusDetermined });
const expected$ = cold('--c-c-c', { c: completion });

expect(effects.loadAvailableFilters$).toBeObservable(expected$);
});
Expand All @@ -137,11 +139,11 @@ describe('Filter Effects', () => {

actions$ = merge(
// go to master 1
of(loadFilterForMaster({ masterSKU: 'master1' })),
of(personalizationStatusDetermined, loadFilterForMaster({ masterSKU: 'master1' })),
// go to category
of(loadFilterForCategory({ uniqueId: 'category' })).pipe(delay(300)),
of(personalizationStatusDetermined, loadFilterForCategory({ uniqueId: 'category' })).pipe(delay(300)),
// go to master 2 before category filters are loaded
of(loadFilterForMaster({ masterSKU: 'master2' })).pipe(delay(500))
of(personalizationStatusDetermined, loadFilterForMaster({ masterSKU: 'master2' })).pipe(delay(500))
);

let lastAction;
Expand Down
4 changes: 3 additions & 1 deletion src/app/core/store/shopping/filter/filter.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Actions, createEffect, ofType } from '@ngrx/effects';
import { map, mergeMap, switchMap } from 'rxjs/operators';

import { FilterService } from 'ish-core/services/filter/filter.service';
import { mapErrorToAction, mapToPayload } from 'ish-core/utils/operators';
import { personalizationStatusDetermined } from 'ish-core/store/customer/user';
import { delayUntil, mapErrorToAction, mapToPayload } from 'ish-core/utils/operators';

import {
applyFilter,
Expand All @@ -23,6 +24,7 @@ export class FilterEffects {
loadAvailableFilters$ = createEffect(() =>
this.actions$.pipe(
ofType(loadFilterForCategory, loadFilterForSearch, loadFilterForMaster),
delayUntil(this.actions$.pipe(ofType(personalizationStatusDetermined))),
map(action => {
switch (action.type) {
case loadFilterForCategory.type:
Expand Down

0 comments on commit c6bbe51

Please sign in to comment.