From b8e788529f8463509d2a1aec6e984dd5163c765e Mon Sep 17 00:00:00 2001 From: Sneha Date: Tue, 13 Feb 2024 11:16:00 +0530 Subject: [PATCH 1/2] Unit test --- .../menu-modal/menu-modal.spec.js | 67 ++++++- .../funnel-header/menu-modal/menu-modal.vue | 1 + .../promo-modal-question.spec.js | 175 ++++++++++++++++++ .../promo-modal-question.vue | 2 +- .../promo-question/promo-question.spec.js | 0 .../promo-question/promo-question.vue | 0 src/layouts/payment-method/payment-method.vue | 2 +- src/layouts/quote/quote.vue | 2 +- 8 files changed, 245 insertions(+), 4 deletions(-) rename src/{layouts/payment-method => fmg-components}/promo-modal-question/promo-modal-question.spec.js (54%) rename src/{layouts/payment-method => fmg-components}/promo-modal-question/promo-modal-question.vue (99%) rename src/{layouts/payment-method => fmg-components}/promo-modal-question/promo-question/promo-question.spec.js (100%) rename src/{layouts/payment-method => fmg-components}/promo-modal-question/promo-question/promo-question.vue (100%) diff --git a/src/fmg-components/funnel-header/menu-modal/menu-modal.spec.js b/src/fmg-components/funnel-header/menu-modal/menu-modal.spec.js index 3d0843e10..d0c59ba42 100644 --- a/src/fmg-components/funnel-header/menu-modal/menu-modal.spec.js +++ b/src/fmg-components/funnel-header/menu-modal/menu-modal.spec.js @@ -1 +1,66 @@ -test.todo("some test to be written in the future"); +import menuModal from "@/fmg-components/funnel-header/menu-modal/menu-modal.vue"; +import { mount, shallowMount } from "@vue/test-utils"; + +describe("menu-modal.vue", () => { + it("Should return text Footer Navigation", async () => { + // Act + const wrapper = shallowMount(menuModal); + + // Assert + const footerModalLabel = wrapper.find("h5"); + + // Expect + expect(footerModalLabel.text()).toContain("Footer Navigation"); + }); + + it("Should return footer text as Safelite Group", async () => { + // Act + const wrapper = shallowMount(menuModal); + + // Assert + const modalFooter = wrapper.find("div.modal-footer"); + + // Expect + expect(modalFooter.text()).toContain("Safelite Group"); + }); + + it("Should return Terms of use text link text", async () => { + // Act + const wrapper = shallowMount(menuModal); + + // Expect + expect(wrapper.html()).toContain("Terms of use"); + }); + + it('Should return "Your privacy choices" text link text', async () => { + // Act + const wrapper = mount(menuModal); + + // Expect + expect(wrapper.html()).toContain("Your privacy choices"); + }); + + test('Icon for link to "Privacy Policies" page is displayed with the correct alternate text', () => { + // NOTE: We need a way to target a specific component so we can be sure that + // an icon is coming from a specific component. + // That requires an additional prop in the component. Will hold off on adding the prop + // until there is more clarity on how we handle shared components. + // For now the test is below is the best we can do. + + // Arrange + const wrapper = mount(menuModal); + + // Expect + const icon = wrapper.find('[data-id="ccpa-icon"]'); + expect(icon.isVisible()).toBe(true); + expect(icon.attributes("alt")).toBe("Your privacy choices"); + }); + + it("Should return Warranty text link text", async () => { + // Act + const wrapper = shallowMount(menuModal); + + // Expect + expect(wrapper.html()).toContain("Warranty"); + }); +}); diff --git a/src/fmg-components/funnel-header/menu-modal/menu-modal.vue b/src/fmg-components/funnel-header/menu-modal/menu-modal.vue index ef2dfc515..c3e9c5af5 100644 --- a/src/fmg-components/funnel-header/menu-modal/menu-modal.vue +++ b/src/fmg-components/funnel-header/menu-modal/menu-modal.vue @@ -53,6 +53,7 @@ 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 @@