Skip to content

Commit

Permalink
fix: load basket information on basket page when personalization stat…
Browse files Browse the repository at this point in the history
…us is determined
  • Loading branch information
Eisie96 committed Mar 1, 2023
1 parent b60e0a1 commit 45f67c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/app/core/store/customer/basket/basket.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CoreStoreModule } from 'ish-core/store/core/core-store.module';
import { loadServerConfigSuccess } from 'ish-core/store/core/server-config';
import { CustomerStoreModule } from 'ish-core/store/customer/customer-store.module';
import { resetOrderErrors } from 'ish-core/store/customer/orders';
import { personalizationStatusDetermined } from 'ish-core/store/customer/user';
import { ApiTokenService } from 'ish-core/utils/api-token/api-token.service';
import { makeHttpError } from 'ish-core/utils/dev/api-service-utils';
import { BasketMockData } from 'ish-core/utils/dev/basket-mock-data';
Expand Down Expand Up @@ -655,8 +656,8 @@ describe('Basket Effects', () => {
actions$ = of(action);

const completion = loadBasket();
actions$ = hot('-a', { a: action });
const expected$ = cold('-c', { c: completion });
actions$ = hot('b-a', { a: action, b: personalizationStatusDetermined() });
const expected$ = cold('--c', { c: completion });

expect(effects.loadBasketOnBasketPage$).toBeObservable(expected$);
});
Expand Down
18 changes: 12 additions & 6 deletions src/app/core/store/customer/basket/basket.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { BasketService } from 'ish-core/services/basket/basket.service';
import { getCurrentCurrency } from 'ish-core/store/core/configuration';
import { mapToRouterState } from 'ish-core/store/core/router';
import { resetOrderErrors } from 'ish-core/store/customer/orders';
import { getLoggedInCustomer, loginUserSuccess } from 'ish-core/store/customer/user';
import { getLoggedInCustomer, loginUserSuccess, personalizationStatusDetermined } from 'ish-core/store/customer/user';
import { ApiTokenService } from 'ish-core/utils/api-token/api-token.service';
import { mapErrorToAction, mapToPayloadProperty, mapToProperty } from 'ish-core/utils/operators';

Expand Down Expand Up @@ -352,14 +352,20 @@ export class BasketEffects {
);

/**
* Trigger LoadBasket action after the user navigated to a basket route
* Reload basket information on basket route to ensure that rendered page is correct.
*/
loadBasketOnBasketPage$ = createEffect(() =>
this.actions$.pipe(
ofType(routerNavigatedAction),
mapToRouterState(),
filter(routerState => /^\/basket/.test(routerState.url)),
map(() => loadBasket())
ofType(personalizationStatusDetermined),
take(1),
switchMap(() =>
this.actions$.pipe(
ofType(routerNavigatedAction),
mapToRouterState(),
filter(routerState => /^\/basket/.test(routerState.url)),
map(() => loadBasket())
)
)
)
);

Expand Down

0 comments on commit 45f67c8

Please sign in to comment.