From 01e46e2abc7899d1bc0465dd6099560071c437b0 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Fri, 7 Apr 2023 10:41:00 -0400 Subject: [PATCH] Fixed unit tests --- .../service-location/service-location.spec.js | 158 ++++++++++++------ .../service-location/service-location.vue | 2 +- 2 files changed, 106 insertions(+), 54 deletions(-) diff --git a/src/layouts/service-location/service-location.spec.js b/src/layouts/service-location/service-location.spec.js index 3589596df..aad61b630 100644 --- a/src/layouts/service-location/service-location.spec.js +++ b/src/layouts/service-location/service-location.spec.js @@ -260,7 +260,11 @@ describe("service-location.vue", () => { const { wrapper } = setupMocks({ mixins: [mockMixin], }); - wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn(); + + const mobileLocationQuestionsComponent = wrapper.findComponent({ + ref: "mobileLocationQuestions", + }); + mobileLocationQuestionsComponent.resetComponent = jest.fn(); const newServiceZipCodeQuestion = { zipCode: "61606", @@ -281,8 +285,16 @@ describe("service-location.vue", () => { test("resets mobile location when service zip code is updated", () => { // Arrange const { wrapper } = setupMocks({}); - wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn(); - wrapper.vm.$refs.serviceZipCodeQuestion.resetMobileFeePart = jest.fn(); + + const mobileLocationQuestionsComponent = wrapper.findComponent({ + ref: "mobileLocationQuestions", + }); + mobileLocationQuestionsComponent.resetComponent = jest.fn(); + + const serviceZipCodeComponent = wrapper.findComponent({ + ref: "serviceZipCodeQuestion", + }); + serviceZipCodeComponent.resetMobileFeePart = jest.fn(); const newServiceZipCodeQuestion = { zipCode: "61606", @@ -312,10 +324,6 @@ describe("service-location.vue", () => { isVehicleProtected: null, }; - const serviceZipCodeComponent = wrapper.findComponent({ - ref: "serviceZipCodeQuestion", - }); - // Act serviceZipCodeComponent.vm.$emit("update:modelValue", newServiceZipCodeQuestion); @@ -326,8 +334,16 @@ describe("service-location.vue", () => { test("resets appointment type selection when service zip code is updated by service zip modal", () => { // Arrange const { wrapper } = setupMocks({}); - wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn(); - wrapper.vm.$refs.serviceZipCodeQuestion.resetMobileFeePart = jest.fn(); + + const mobileLocationQuestionsComponent = wrapper.findComponent({ + ref: "mobileLocationQuestions", + }); + mobileLocationQuestionsComponent.resetComponent = jest.fn(); + + const serviceZipCodeComponent = wrapper.findComponent({ + ref: "serviceZipCodeQuestion", + }); + serviceZipCodeComponent.resetMobileFeePart = jest.fn(); const newServiceZipCodeQuestion = { zipCode: "61606", @@ -336,10 +352,6 @@ describe("service-location.vue", () => { wrapper.vm.selectedAppointmentType = "Inshop"; - const serviceZipCodeComponent = wrapper.findComponent({ - ref: "serviceZipCodeQuestion", - }); - // Act serviceZipCodeComponent.vm.$emit("update:modelValue", newServiceZipCodeQuestion); @@ -350,7 +362,17 @@ describe("service-location.vue", () => { test("displays military zip message when zip is updated", () => { // Arrange const { wrapper } = setupMocks({}); - wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn(); + + const mobileLocationQuestionsComponent = wrapper.findComponent({ + ref: "mobileLocationQuestions", + }); + mobileLocationQuestionsComponent.resetComponent = jest.fn(); + + const serviceZipCodeComponent = wrapper.findComponent({ + ref: "serviceZipCodeQuestion", + }); + serviceZipCodeComponent.resetMobileFeePart = jest.fn(); + expect(wrapper.vm.zipContainsMilitaryBase).toBe(false); const newServiceZipCodeQuestion = { @@ -358,10 +380,6 @@ describe("service-location.vue", () => { state: "OH", }; - const serviceZipCodeComponent = wrapper.findComponent({ - ref: "serviceZipCodeQuestion", - }); - // Act serviceZipCodeComponent.vm.$emit("updated-contains-military-base", true); @@ -371,10 +389,23 @@ describe("service-location.vue", () => { }); describe("updating mobile location", () => { - test("updates the page model after providing the mobile location", () => { + test("updates the page model after providing the mobile location", async () => { // Arrange const { wrapper } = setupMocks({}); - wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn(); + + await wrapper.setData({ + selectedAppointmentType: "Mobile", + }); + + const mobileLocationQuestionsComponent = wrapper.findComponent({ + ref: "mobileLocationQuestions", + }); + mobileLocationQuestionsComponent.resetComponent = jest.fn(); + + const serviceZipCodeComponent = wrapper.findComponent({ + ref: "serviceZipCodeQuestion", + }); + serviceZipCodeComponent.resetMobileFeePart = jest.fn(); const mobileLocationQuestions = { addressQuestions: { @@ -399,12 +430,11 @@ describe("service-location.vue", () => { isVehicleProtected: true, }; - const mobileLocationComponent = wrapper.findComponent({ - ref: "mobileLocationModalQuestions", - }); - // Act - mobileLocationComponent.vm.$emit("update:modelValue", newMobileLocationQuestions); + mobileLocationQuestionsComponent.vm.$emit( + "update:modelValue", + newMobileLocationQuestions + ); // Assert expect(wrapper.vm.mobileLocationQuestions).toStrictEqual(newMobileLocationQuestions); @@ -413,8 +443,20 @@ describe("service-location.vue", () => { test("resets service zip code when mobile location is updated", async () => { // Arrange const { wrapper } = setupMocks({}); - wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn(); - wrapper.vm.$refs.serviceZipCodeQuestion.resetMobileFeePart = jest.fn(); + + await wrapper.setData({ + selectedAppointmentType: "Mobile", + }); + + const mobileLocationQuestionsComponent = wrapper.findComponent({ + ref: "mobileLocationQuestions", + }); + mobileLocationQuestionsComponent.resetComponent = jest.fn(); + + const serviceZipCodeComponent = wrapper.findComponent({ + ref: "serviceZipCodeQuestion", + }); + serviceZipCodeComponent.resetMobileFeePart = jest.fn(); const mobileLocationQuestions = { addressQuestions: { @@ -441,10 +483,6 @@ describe("service-location.vue", () => { mobileFeePart: null, }; - const mobileLocationComponent = wrapper.findComponent({ - ref: "mobileLocationModalQuestions", - }); - wrapper.vm.serviceZipCodeQuestion = { zipCode: "61606", state: "IL", @@ -456,29 +494,38 @@ describe("service-location.vue", () => { }; // Act - mobileLocationComponent.vm.$emit("update:modelValue", newMobileLocationQuestions); + mobileLocationQuestionsComponent.vm.$emit( + "update:modelValue", + newMobileLocationQuestions + ); // Assert expect(wrapper.vm.serviceZipCodeQuestion).toStrictEqual(newServiceZipCodeInfo); }); - test("resets appointment type selection when service zip code is updated by mobile location modal when Mobile is not selected", () => { + test("resets appointment type selection when service zip code is updated by mobile location modal when Mobile is not selected", async () => { // Arrange const { wrapper } = setupMocks({}); - wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn(); - wrapper.vm.$refs.serviceZipCodeQuestion.resetMobileFeePart = jest.fn(); + + await wrapper.setData({ + selectedAppointmentType: "Dropoff", + }); + + const mobileLocationQuestionsComponent = wrapper.findComponent({ + ref: "mobileLocationQuestions", + }); + mobileLocationQuestionsComponent.resetComponent = jest.fn(); + + const serviceZipCodeComponent = wrapper.findComponent({ + ref: "serviceZipCodeQuestion", + }); + serviceZipCodeComponent.resetMobileFeePart = jest.fn(); const newServiceZipCodeQuestion = { zipCode: "61606", state: "IL", }; - wrapper.vm.selectedAppointmentType = "Dropoff"; - - const serviceZipCodeComponent = wrapper.findComponent({ - ref: "serviceZipCodeQuestion", - }); - // Act serviceZipCodeComponent.vm.$emit("update:modelValue", newServiceZipCodeQuestion); @@ -486,12 +533,23 @@ describe("service-location.vue", () => { expect(wrapper.vm.selectedAppointmentType).toStrictEqual(null); }); - test("does not reset appointment type selection when service zip code is updated by mobile location modal when Mobile is selected", () => { + test("does not reset appointment type selection when service zip code is updated by mobile location modal when Mobile is selected", async () => { // Arrange const { wrapper } = setupMocks({}); - const appointmentTypeMobile = "Mobile"; - wrapper.vm.$refs.mobileLocationModalQuestions.resetComponent = jest.fn(); - wrapper.vm.$refs.serviceZipCodeQuestion.resetMobileFeePart = jest.fn(); + + await wrapper.setData({ + selectedAppointmentType: "Mobile", + }); + + const mobileLocationQuestionsComponent = wrapper.findComponent({ + ref: "mobileLocationQuestions", + }); + mobileLocationQuestionsComponent.resetComponent = jest.fn(); + + const serviceZipCodeComponent = wrapper.findComponent({ + ref: "serviceZipCodeQuestion", + }); + serviceZipCodeComponent.resetMobileFeePart = jest.fn(); const mobileLocationQuestions = { addressQuestions: { @@ -504,17 +562,11 @@ describe("service-location.vue", () => { isVehicleProtected: "YesAnswer", }; - wrapper.vm.selectedAppointmentType = "Mobile"; - - const mobileLocationComponent = wrapper.findComponent({ - ref: "mobileLocationModalQuestions", - }); - // Act - mobileLocationComponent.vm.$emit("update:modelValue", mobileLocationQuestions); + mobileLocationQuestionsComponent.vm.$emit("update:modelValue", mobileLocationQuestions); // Assert - expect(wrapper.vm.selectedAppointmentType).toStrictEqual(appointmentTypeMobile); + expect(wrapper.vm.selectedAppointmentType).toStrictEqual("Mobile"); }); }); diff --git a/src/layouts/service-location/service-location.vue b/src/layouts/service-location/service-location.vue index ebb0cf66a..cbdebd397 100644 --- a/src/layouts/service-location/service-location.vue +++ b/src/layouts/service-location/service-location.vue @@ -61,7 +61,7 @@ @updated-serviceability="setServiceabilityDetails" @updated-contains-military-base="setContainsMilitaryBase" validationRules="mobile-location-required" - ref="mobileLocationModalQuestions" + ref="mobileLocationQuestions" linkWidgetName="MobileLocationLinkWidget" modalWidgetName="MobileLocationModalWidget" />