diff --git a/src/layouts/payment-method/promo-modal-question/promo-modal-question.spec.js b/src/fmg-components/promo-modal-question/promo-modal-question.spec.js similarity index 54% rename from src/layouts/payment-method/promo-modal-question/promo-modal-question.spec.js rename to src/fmg-components/promo-modal-question/promo-modal-question.spec.js index 1dcc2ac70..435a53277 100644 --- a/src/layouts/payment-method/promo-modal-question/promo-modal-question.spec.js +++ b/src/fmg-components/promo-modal-question/promo-modal-question.spec.js @@ -2,6 +2,12 @@ import { mount, shallowMount } from "@vue/test-utils"; import promoModalQuestion from "./promo-modal-question"; import { storeActions } from "@/constants/store-actions"; import baseMixin from "@/mixins/base-mixin.js"; +import { + promoErrorCodes, + getPromoCodesFromPromoObjectsWithoutDuplicates, + getPromoCodeWithoutBundleIdentifier, +} from "@/helpers/promotions-helper"; +import { cartItemCategories } from "@/constants/cart-item-categories"; let mockReturnsForStoreActions = {}; @@ -222,4 +228,173 @@ describe("promo-modal-question.vue", () => { expect(taxedLineItems).toEqual(taxedlineItems); }); + test("Get promoCode list will return the applied promos", async () => { + // Arrange + const promos = [ + { promoCode: "duplicatePromo" }, + { promoCode: "duplicatePromo" }, + { promoCode: "bundlePromo/400" }, + { promoCode: "bundlePromo/401" }, + ]; + const appliedPromos = ["duplicatePromo", "bundlePromo"]; + const lineItems = { + glassParts: [], + supportingItems: [], + vaps: [], + promos: [], + }; + + const wrapper = mount(promoModalQuestion, { + mixins: [mockMixin], + props: { + modelValue: lineItems, + modalWidgetName: modalWidgetName, + }, + attachTo: document.body, + }); + + // Act + wrapper.vm.getPromoCodeList(); + const promoCodeToDisplay = getPromoCodesFromPromoObjectsWithoutDuplicates(promos); + + // Assert + expect(promoCodeToDisplay).toEqual(appliedPromos); + }); + test("On clicking remove the promo gets removed from the lineItems", async () => { + //Arrange + const lineItems = { + glassParts: [], + supportingItems: [], + vaps: [], + promos: [{ promoCode: "duplicatePromo" }, { promoCode: "duplicatePromo" }], + }; + + const wrapper = mount(promoModalQuestion, { + mixins: [mockMixin], + props: { + modelValue: lineItems, + modalWidgetName: modalWidgetName, + }, + attachTo: document.body, + }); + const promo = ["bundlePromo"]; + //Act + wrapper.vm.removeItem(promo); + const existingPromo = (lineItems[cartItemCategories.PROMOS] = lineItems[ + cartItemCategories.PROMOS + ].filter( + (lineItemsToKeep) => + getPromoCodeWithoutBundleIdentifier(lineItemsToKeep.promoCode) != promo + )); + + //Assert + expect(existingPromo).toEqual(lineItems.promos); + }); + test("Getting stacking alert on stack promo error code", async () => { + // Arrange + const lineItems = { + glassParts: [], + supportingItems: [], + vaps: [], + promos: [], + }; + + const wrapper = mount(promoModalQuestion, { + mixins: [mockMixin], + props: { + modelValue: lineItems, + modalWidgetName: modalWidgetName, + }, + attachTo: document.body, + }); + const additionalInfo = ["testAdditionalInfo"]; + + const stackingErrorCode = promoErrorCodes.PROMO_STACKING_NOT_ALLOWED; + + // Act + wrapper.vm.getErrorMessage(stackingErrorCode, additionalInfo); + + // Assert + expect(wrapper.vm.displayStackingPromoAlert).toBe(true); + }); + test("Getting invalid promo alert on invalid promoCode", async () => { + // Arrange + const lineItems = { + glassParts: [], + supportingItems: [], + vaps: [], + promos: [], + }; + + const wrapper = mount(promoModalQuestion, { + mixins: [mockMixin], + props: { + modelValue: lineItems, + modalWidgetName: modalWidgetName, + }, + attachTo: document.body, + }); + const additionalInfo = ["testAdditionalInfo"]; + + const invalidErrorCode = promoErrorCodes.INVALID_PROMO_ON_ORDER; + + // Act + wrapper.vm.getErrorMessage(invalidErrorCode, additionalInfo); + + // Assert + expect(wrapper.vm.displayInvalidPromoAlert).toBe(true); + }); + test("Getting invalid promo alert on invalid promoCode", async () => { + // Arrange + const lineItems = { + glassParts: [], + supportingItems: [], + vaps: [], + promos: [], + }; + + const wrapper = mount(promoModalQuestion, { + mixins: [mockMixin], + props: { + modelValue: lineItems, + modalWidgetName: modalWidgetName, + }, + attachTo: document.body, + }); + const additionalInfo = ["APPOINTMENT_TYPE"]; + + const invalidErrorCode = promoErrorCodes.INVALID_PROMO_ON_ORDER; + + // Act + wrapper.vm.getErrorMessage(invalidErrorCode, additionalInfo); + + // Assert + expect(wrapper.vm.displayInShopPromoAlert).toBe(true); + }); + test("Get conflicting promoCodes on applying more than one promo", async () => { + // Arrange + const lineItems = { + glassParts: [], + supportingItems: [], + vaps: [], + promos: [], + }; + + const wrapper = mount(promoModalQuestion, { + mixins: [mockMixin], + props: { + modelValue: lineItems, + modalWidgetName: modalWidgetName, + }, + attachTo: document.body, + }); + const additionalInfo = ["1wiper0", "Glass30"]; + const conflictingCodes = ["1wiper0", "Glass30"]; + + //Act + wrapper.vm.getConflictingPromoCode(additionalInfo); + + //Assert + expect(conflictingCodes).toEqual(additionalInfo); + }); }); diff --git a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue b/src/fmg-components/promo-modal-question/promo-modal-question.vue similarity index 99% rename from src/layouts/payment-method/promo-modal-question/promo-modal-question.vue rename to src/fmg-components/promo-modal-question/promo-modal-question.vue index da8d344e9..aed1bba21 100644 --- a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue +++ b/src/fmg-components/promo-modal-question/promo-modal-question.vue @@ -64,7 +64,7 @@