Skip to content

Commit

Permalink
fix: prevent outdated basket information on /basket route (#1342)
Browse files Browse the repository at this point in the history
* load basket on a successful /basket route navigation to prevent outdated basket information
  • Loading branch information
Eisie96 authored Dec 14, 2022
1 parent 88b4206 commit 1a730f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/app/core/store/customer/basket/basket.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,34 @@ describe('Basket Effects', () => {
});
});

describe('loadBasketOnBasketPage$', () => {
it('should fire LoadBasket when route basket is navigated', () => {
router.navigateByUrl('/basket');

const action = routerTestNavigatedAction({
routerState: { url: '/basket' },
});
actions$ = of(action);

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

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

it('should not fire LoadBasket when route /something is navigated', () => {
router.navigateByUrl('/something');

actions$ = of(
routerTestNavigatedAction({
routerState: { url: '/something' },
})
);
expect(effects.loadBasketOnBasketPage$).toBeObservable(cold('|'));
});
});

describe('createRequisition$', () => {
beforeEach(() => {
store.dispatch(loadBasketSuccess({ basket: { id: 'BID' } as Basket }));
Expand Down
12 changes: 12 additions & 0 deletions src/app/core/store/customer/basket/basket.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ export class BasketEffects {
)
);

/**
* Trigger LoadBasket action after the user navigated to a basket route
*/
loadBasketOnBasketPage$ = createEffect(() =>
this.actions$.pipe(
ofType(routerNavigatedAction),
mapToRouterState(),
filter(routerState => /^\/basket/.test(routerState.url)),
map(() => loadBasket())
)
);

/**
* Creates a requisition based on the given basket, if approval is required
*/
Expand Down

0 comments on commit 1a730f8

Please sign in to comment.