From 2695f21287ae26e5d3c43479d010f2660b3fa332 Mon Sep 17 00:00:00 2001 From: Brian Gamboc-Javiniar Date: Thu, 10 Jun 2021 14:13:47 -0400 Subject: [PATCH] fix: Saved carts: can't delete description when editing (#12680) closes GH-11807 --- .../saved-cart-form-dialog.component.spec.ts | 15 +++++++++++++++ .../saved-cart-form-dialog.component.ts | 14 +++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/feature-libs/cart/saved-cart/components/saved-cart-form-dialog/saved-cart-form-dialog.component.spec.ts b/feature-libs/cart/saved-cart/components/saved-cart-form-dialog/saved-cart-form-dialog.component.spec.ts index 6bf2c0e1155..2bfc437a512 100644 --- a/feature-libs/cart/saved-cart/components/saved-cart-form-dialog/saved-cart-form-dialog.component.spec.ts +++ b/feature-libs/cart/saved-cart/components/saved-cart-form-dialog/saved-cart-form-dialog.component.spec.ts @@ -211,6 +211,21 @@ describe('SavedCartFormDialogComponent', () => { ); }); + // TODO(#12660): Remove once backend is updated + it('should provide default value to saveCartDescription when empty', () => { + spyOn(savedCartService, 'editSavedCart'); + + mockDialogData$.next({ cart: {}, layoutOption: 'edit' }); + + component.saveOrEditCart(mockCartId); + + expect(savedCartService.editSavedCart).toHaveBeenCalledWith({ + cartId: mockCartId, + saveCartName: '', + saveCartDescription: '-', + }); + }); + describe('should return actual characters left', () => { it('when form control has value', () => { component?.form?.get('description')?.setValue('test'); diff --git a/feature-libs/cart/saved-cart/components/saved-cart-form-dialog/saved-cart-form-dialog.component.ts b/feature-libs/cart/saved-cart/components/saved-cart-form-dialog/saved-cart-form-dialog.component.ts index 452717defef..cb4b99ff00c 100644 --- a/feature-libs/cart/saved-cart/components/saved-cart-form-dialog/saved-cart-form-dialog.component.ts +++ b/feature-libs/cart/saved-cart/components/saved-cart-form-dialog/saved-cart-form-dialog.component.ts @@ -11,8 +11,8 @@ import { DeleteSavedCartEvent, DeleteSavedCartFailEvent, DeleteSavedCartSuccessEvent, - SavedCartFormType, SavedCartFacade, + SavedCartFormType, } from '@spartacus/cart/saved-cart/root'; import { Cart, @@ -122,12 +122,16 @@ export class SavedCartFormDialogComponent implements OnInit, OnDestroy { } saveOrEditCart(cartId: string): void { + const name = this.form.get('name')?.value; + // TODO(#12660): Remove default value once backend is updated + const description = this.form.get('description')?.value || '-'; + switch (this.layoutOption) { case SavedCartFormType.SAVE: { this.savedCartService.saveCart({ cartId, - saveCartName: this.form.get('name')?.value, - saveCartDescription: this.form.get('description')?.value, + saveCartName: name, + saveCartDescription: description, }); break; @@ -136,8 +140,8 @@ export class SavedCartFormDialogComponent implements OnInit, OnDestroy { case SavedCartFormType.EDIT: { this.savedCartService.editSavedCart({ cartId, - saveCartName: this.form.get('name')?.value, - saveCartDescription: this.form.get('description')?.value, + saveCartName: name, + saveCartDescription: description, }); break;