Skip to content

Commit

Permalink
fix: Saved carts: can't delete description when editing (#12680)
Browse files Browse the repository at this point in the history
closes GH-11807
  • Loading branch information
bgambocjaviniar authored Jun 10, 2021
1 parent 1511e89 commit 2695f21
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
DeleteSavedCartEvent,
DeleteSavedCartFailEvent,
DeleteSavedCartSuccessEvent,
SavedCartFormType,
SavedCartFacade,
SavedCartFormType,
} from '@spartacus/cart/saved-cart/root';
import {
Cart,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 2695f21

Please sign in to comment.