From 4172ec04fcbab052ced553b88a7fd4138205cbcc Mon Sep 17 00:00:00 2001 From: Sneha Date: Wed, 20 Nov 2024 16:09:47 +0530 Subject: [PATCH] CSR-2395 --- src/fmg-components/cart/cart.spec.js | 7 ++----- src/fmg-components/cart/cart.vue | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/fmg-components/cart/cart.spec.js b/src/fmg-components/cart/cart.spec.js index 178dcfdf4..5adff3ab3 100644 --- a/src/fmg-components/cart/cart.spec.js +++ b/src/fmg-components/cart/cart.spec.js @@ -307,7 +307,7 @@ describe("cart.vue", () => { }); // Service package discount Fee Cart Item - test("if there is service package discount fee on the order, a service package discount cart item should be added to the cart", () => { + test("only if there is service package discount fee for the package, a service package discount cart item should be added to the cart", () => { // Arrange const lineItems = { glassParts: [], @@ -336,11 +336,8 @@ describe("cart.vue", () => { availableVaps: availableVaps, }, }); - // Assert - expect(wrapper.vm.servicePackageDiscountCartItem).not.toBeNull(); - expect(wrapper.vm.servicePackageDiscountCartItem.subTotal).toEqual(-70); - expect(wrapper.vm.servicePackageDiscountCartItem.salesTax).toEqual(0); + expect(wrapper.vm.servicePackageDiscountCartItem).toBeNull(); }); // Other Supporting Items Cart Item diff --git a/src/fmg-components/cart/cart.vue b/src/fmg-components/cart/cart.vue index a26821646..52049b0c9 100644 --- a/src/fmg-components/cart/cart.vue +++ b/src/fmg-components/cart/cart.vue @@ -297,8 +297,16 @@ export default { this.lineItems[category] = this.lineItems[category].filter( (lineItemsToKeep) => lineItemsToKeep.cartItemType != cartItemType ); - - await this.dispatchStoreAction(storeActions.SAVE_VAPS, this.lineItems.vaps, false); + if (category == cartItemCategories.VAPS) { + await this.dispatchStoreAction(storeActions.SAVE_VAPS, this.lineItems.vaps, false); + } + if (category == cartItemCategories.SUPPORTING_ITEMS) { + await this.dispatchStoreAction( + storeActions.SAVE_SUPPORTING_ITEMS_SUPPRESSING_STATE_RESETTING, + this.lineItems.supportingItems, + false + ); + } }, async saveVaps(lineItems) { @@ -430,11 +438,15 @@ export default { cartItems.push(this.mobileFeeCartItem); } - if ( - this.servicePackageDiscountCartItem && - this.discountPackageNames == this.packageLevel - ) { - cartItems.push(this.servicePackageDiscountCartItem); + if (this.servicePackageDiscountCartItem) { + if (this.discountPackageNames != this.packageLevel) { + this.removeItem( + this.servicePackageDiscountCartItem.cartItemType, + cartItemCategories.SUPPORTING_ITEMS + ); + } else { + cartItems.push(this.servicePackageDiscountCartItem); + } } if (this.premiumAppointmentDiscountCartItem) {