Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: show mini cart animation after add quote to cart (#1041, #1287)
  • Loading branch information
SGrueber committed Oct 7, 2022
1 parent a2c2d3b commit a1cf6c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/app/core/services/basket/basket.service.ts
Expand Up @@ -571,7 +571,7 @@ export class BasketService {
* @param quoteId The id of the quote that should be added to the basket.
* @returns The info message if present.
*/
addQuoteToBasket(quoteId: string): Observable<string> {
addQuoteToBasket(quoteId: string): Observable<BasketInfo[]> {
if (!quoteId) {
return throwError(() => new Error('addQuoteToBasket() called without quoteId'));
}
Expand All @@ -584,7 +584,7 @@ export class BasketService {
headers: this.basketHeaders,
}
)
.pipe(map(({ infos }) => infos?.[0]?.message));
.pipe(map(BasketInfoMapper.fromInfo));
}

/**
Expand Down
23 changes: 17 additions & 6 deletions src/app/extensions/quoting/store/quoting/quoting.effects.spec.ts
Expand Up @@ -180,21 +180,32 @@ describe('Quoting Effects', () => {

describe('addQuoteToBasket$', () => {
beforeEach(() => {
when(basketService.addQuoteToBasket(anything())).thenReturn(of(''));
when(basketService.addQuoteToBasket(anything())).thenReturn(of(undefined));
});

describe('with basket', () => {
beforeEach(() => {
store$.overrideSelector(getCurrentBasketId, 'basketID');
});

it('should directly add quote to basket via quoting service', done => {
it('should directly add quote to basket via basket service', done => {
actions$ = of(addQuoteToBasket({ id: 'quoteID' }));

effects.addQuoteToBasket$.subscribe(() => {
verify(basketService.addQuoteToBasket('quoteID')).once();
verify(basketService.createBasket()).never();
done();
effects.addQuoteToBasket$.pipe(toArray()).subscribe({
next: actions => {
verify(basketService.addQuoteToBasket('quoteID')).once();
verify(basketService.createBasket()).never();
expect(actions).toMatchInlineSnapshot(`
[Basket API] Add Items To Basket Success:
lineItems: []
info: undefined
[Basket Internal] Load Basket
[Quoting API] Add Quote To Basket Success:
id: "quoteID"
`);
},
error: fail,
complete: done,
});
});
});
Expand Down
8 changes: 6 additions & 2 deletions src/app/extensions/quoting/store/quoting/quoting.effects.ts
Expand Up @@ -9,7 +9,7 @@ import { BasketService } from 'ish-core/services/basket/basket.service';
import { displaySuccessMessage } from 'ish-core/store/core/messages';
import { selectRouteParam, selectUrl } from 'ish-core/store/core/router';
import { setBreadcrumbData } from 'ish-core/store/core/viewconf';
import { getCurrentBasketId, loadBasket } from 'ish-core/store/customer/basket';
import { addItemsToBasketSuccess, getCurrentBasketId, loadBasket } from 'ish-core/store/customer/basket';
import {
mapErrorToAction,
mapToPayload,
Expand Down Expand Up @@ -149,7 +149,11 @@ export class QuotingEffects {
!basketId ? this.basketService.createBasket().pipe(map(basket => basket.id)) : of(basketId)
),
concatMap(() => this.basketService.addQuoteToBasket(quoteId)),
mergeMap(() => [loadBasket(), addQuoteToBasketSuccess({ id: quoteId })]),
mergeMap(info => [
addItemsToBasketSuccess({ lineItems: [], info }), // update lastTimeProductAdded in the basket state
loadBasket(),
addQuoteToBasketSuccess({ id: quoteId }),
]),
mapErrorToAction(loadQuotingFail)
)
)
Expand Down

0 comments on commit a1cf6c8

Please sign in to comment.