diff --git a/src/helpers/service-location-helper.spec.js b/src/helpers/service-location-helper.spec.js index 9b1920fba..ac3eace06 100644 --- a/src/helpers/service-location-helper.spec.js +++ b/src/helpers/service-location-helper.spec.js @@ -2,7 +2,8 @@ import { getPricedMobileFeePart } from "./service-location-helper"; import { storeActions } from "@/constants/store-actions"; const mockStoreActionGetMobileFeePart = storeActions.GET_MOBILE_FEE_PART; -const mockStoreActionPriceOrderItemsAndSaveServerData = storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA; +const mockStoreActionPriceOrderItemsAndSaveServerData = + storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA; jest.mock("@/mixins/base-mixin.js", () => ({ methods: { @@ -40,12 +41,11 @@ jest.mock("@/mixins/base-mixin.js", () => ({ ]); } }), - }, })); describe("service-location-helper.js", () => { - it("Should return the null if no service zip code is passed in", async() => { + it("Should return the null if no service zip code is passed in", async () => { // Arrange / Act const serviceZipCode = null; const expected = null; @@ -54,9 +54,9 @@ describe("service-location-helper.js", () => { // Assert expect(result).toEqual(expected); - }); + }); - it("Should return the priced mobile fee part", async() => { + it("Should return the priced mobile fee part", async () => { // Arrange / Act const serviceZipCode = "43235"; const expected = { @@ -66,13 +66,13 @@ describe("service-location-helper.js", () => { laborAmount: 49.99, sellingPrice: 0, kitPrice: 0, - } + }; const result = await getPricedMobileFeePart(serviceZipCode); // Assert expect(result).toEqual(expected); }); -}) +}); //test.todo("some test to be written in the future"); diff --git a/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.spec.js b/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.spec.js index 7e5aaff8c..f7a2238c8 100644 --- a/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.spec.js +++ b/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.spec.js @@ -2,6 +2,7 @@ import mobileLocationModalQuestions from "./mobile-location-modal-questions"; import { mount, shallowMount } from "@vue/test-utils"; import { storeActions } from "@/constants/store-actions"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; +import modal from "@/digital-components/modal/modal"; import crypto from "crypto"; @@ -42,7 +43,7 @@ const mockMixin = { }), getZipCodeData: jest.fn((zip) => { - if (zip === "43235") { + if (zip === "43235" || zip === "55555") { return Promise.resolve({ containsMilitaryBase: false, isServiceable: true, @@ -128,6 +129,213 @@ describe("mobile-location-modal-questions.vue", () => { expect(wrapper.vm.internalModel.isVehicleProtected).toEqual(true); expect(wrapper.vm.internalModel.serviceZipCode).toEqual("55555"); }); + + it("Should open the modal when the 'Enter your service address' link is clicked", async () => { + // Arrange + const mobileLocationQuestions = { + addressQuestions: { + streetAddress: "555 Some St", + apartmentNumberOrBusinessName: "Apt 1", + city: "Funkytown", + state: "OH", + zipCode: "55555", + }, + isVehicleProtected: true, + serviceZipCode: "55555", + }; + + const { wrapper } = setupMocks({ + mixins: [mockMixin], + props: { + modelValue: mobileLocationQuestions, + }, + mountOptions: { + attachTo: document.body, + }, + }); + + wrapper.vm.$refs.MobileLocationModalWidget.openModal = jest.fn(); + const mobileLocationLink = wrapper.findComponent({ ref: "mobileLocationLink" }); + + // // Act + await mobileLocationLink.trigger("click-event"); + + // // Assert + expect(wrapper.vm.$refs.MobileLocationModalWidget.openModal).toHaveBeenCalled(); + }); + + it("Should emit update:modelValue on setMobileLocation for a valid address and vehicle protection answer", async () => { + // Arrange + const mobileLocationQuestions = { + addressQuestions: { + streetAddress: "", + apartmentNumberOrBusinessName: "", + city: "", + state: "", + zipCode: "", + }, + isVehicleProtected: true, + serviceZipCode: "", + }; + + const newMobileLocationQuestions = { + addressQuestions: { + streetAddress: "555 Some St", + apartmentNumberOrBusinessName: "Apt 1", + city: "Funkytown", + state: "OH", + zipCode: "55555", + }, + isVehicleProtected: true, + serviceZipCode: "55555", + }; + + const wrapper = shallowMount(mobileLocationModalQuestions, { + mixins: [mockMixin], + props: { + modelValue: mobileLocationQuestions, + linkWidgetName: linkWidgetName, + modalWidgetName: modalWidgetName, + }, + attachTo: document.body, + }); + wrapper.vm.$refs.MobileLocationModalWidget.closeModal = jest.fn(); + + // Act + wrapper.vm.internalModel = newMobileLocationQuestions; + await wrapper.vm.setMobileLocation(); + + let expectedEmit = [[newMobileLocationQuestions]]; + + // Assert + expect(wrapper.emitted("update:modelValue")).toEqual(expectedEmit); + }); + + it("Should not emit update:modelValue on setMobileLocation for an invalid address zip code", async () => { + // Arrange + const mobileLocationQuestions = { + addressQuestions: { + streetAddress: "", + apartmentNumberOrBusinessName: "", + city: "", + state: "", + zipCode: "", + }, + isVehicleProtected: true, + serviceZipCode: "", + }; + + const newMobileLocationQuestions = { + addressQuestions: { + streetAddress: "555 Some St", + apartmentNumberOrBusinessName: "Apt 1", + city: "Funkytown", + state: "OH", + zipCode: "61000", + }, + isVehicleProtected: true, + serviceZipCode: "61000", + }; + + const wrapper = shallowMount(mobileLocationModalQuestions, { + mixins: [mockMixin], + props: { + modelValue: mobileLocationQuestions, + linkWidgetName: linkWidgetName, + modalWidgetName: modalWidgetName, + }, + attachTo: document.body, + }); + wrapper.vm.$refs.MobileLocationModalWidget.closeModal = jest.fn(); + + // Act + wrapper.vm.internalModel = newMobileLocationQuestions; + await wrapper.vm.setMobileLocation(); + + // Assert + expect(wrapper.emitted("update:modelValue")).not.toBeTruthy(); + }); + + it("Should display invalid zip alert for invalid address zip inputs", async () => { + // Arrange + const mobileLocationQuestions = { + addressQuestions: { + streetAddress: "", + apartmentNumberOrBusinessName: "", + city: "", + state: "", + zipCode: "", + }, + isVehicleProtected: true, + serviceZipCode: "", + }; + + const newMobileLocationQuestions = { + addressQuestions: { + streetAddress: "555 Some St", + apartmentNumberOrBusinessName: "Apt 1", + city: "Funkytown", + state: "OH", + zipCode: "11111", + }, + isVehicleProtected: true, + serviceZipCode: "11111", + }; + + const wrapper = shallowMount(mobileLocationModalQuestions, { + mixins: [mockMixin], + props: { + modelValue: mobileLocationQuestions, + linkWidgetName: linkWidgetName, + modalWidgetName: modalWidgetName, + }, + attachTo: document.body, + }); + + wrapper.vm.internalModel = newMobileLocationQuestions; + + // Act + await wrapper.vm.setMobileLocation(); + + // Assert + expect(wrapper.vm.displayInvalidZipAlert).toBe(true); + }); + + it("Should clear the internal model when resetModel is called", async () => { + // Arrange + const mobileLocationQuestions = { + addressQuestions: { + streetAddress: "555 Some St", + apartmentNumberOrBusinessName: "Apt 1", + city: "Funkytown", + state: "OH", + zipCode: "55555", + }, + isVehicleProtected: true, + serviceZipCode: "55555", + }; + + const { wrapper } = setupMocks({ + mixins: [mockMixin], + props: { + modelValue: mobileLocationQuestions, + }, + mountOptions: { + attachTo: document.body, + }, + }); + + // Act + wrapper.vm.resetModel(); + + // Assert + expect(wrapper.vm.internalModel.addressQuestions.streetAddress).toEqual(""); + expect(wrapper.vm.internalModel.addressQuestions.apartmentNumberOrBusinessName).toEqual(""); + expect(wrapper.vm.internalModel.addressQuestions.city).toEqual(""); + expect(wrapper.vm.internalModel.addressQuestions.state).toEqual(""); + expect(wrapper.vm.internalModel.addressQuestions.zipCode).toEqual(""); + expect(wrapper.vm.internalModel.isVehicleProtected).toEqual(null); + }); }); function setupMocks({ mountOptions, mixins, props, isShallowMount = true }) { diff --git a/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.vue b/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.vue index ba7cc2fab..644a875d3 100644 --- a/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.vue +++ b/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.vue @@ -7,6 +7,7 @@ v-html="mobileLocationLinkPromptText">