From de0add665cdc509ba86f1b259b0b23427a8ae5ca Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Mon, 16 Jan 2023 15:09:38 -0500 Subject: [PATCH 1/3] updates --- src/helpers/unit-test-helper.js | 2 + .../address-lookup/address-lookup.spec.js | 105 +++++++++--------- .../address-questions.spec.js | 92 +-------------- .../customer-questions.spec.js | 2 - src/mixins/vin-pages-mixin.js | 4 +- src/mixins/vin-pages-mixin.spec.js | 8 -- 6 files changed, 57 insertions(+), 156 deletions(-) diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index 4cee713a..42b5db66 100644 --- a/src/helpers/unit-test-helper.js +++ b/src/helpers/unit-test-helper.js @@ -48,6 +48,8 @@ export function getMountOptions(mockData) { mocks.queryStrings = queryStrings; mocks.$router = mockData?.router; mocks.$route = mockData?.route; + mocks.$loadScript = mockData?.loadScript; + mocks.prependActionToMethod = jest.fn(); const global = { mocks: mocks, diff --git a/src/layouts/address-lookup/address-lookup.spec.js b/src/layouts/address-lookup/address-lookup.spec.js index 2c4b4495..7d90e6b9 100644 --- a/src/layouts/address-lookup/address-lookup.spec.js +++ b/src/layouts/address-lookup/address-lookup.spec.js @@ -5,21 +5,15 @@ import addressLookup from "@/layouts/address-lookup/address-lookup.vue"; import { settleAllPromises } from "@/helpers/layout-helper.js"; import { shallowMount } from "@vue/test-utils"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; -import { storeActions } from "@/constants/store-actions"; -import { storeMutations } from "@/constants/store-mutations"; +import { useMainStore } from "@/store"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import store from "@/store"; -import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; jest.mock("@/helpers/damage-helper", () => ({ isGlassAvailableForCarId: jest.fn().mockImplementation(() => true), getDamageString: jest.fn(), })); -jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({ - navigateToHeritageFunnel: jest.fn(), -})); - // Mock our module for promises. jest.mock("@/helpers/layout-helper.js", () => ({ settleAllPromises: jest.fn(), @@ -49,8 +43,6 @@ describe("address-lookup.vue", () => { ], }); - store.commit(storeMutations.UPDATE_CAR_ID, "CARID"); - await wrapper.setData({ customerQuestions: { addressQuestions: mockRegistrationAddress, @@ -63,7 +55,8 @@ describe("address-lookup.vue", () => { // Assert expect(wrapper.findComponent({ ref: "alertNonServiceableZip" }).isVisible()).toBe(true); }); - + }); + /* test("if the address matches a different vehicle display the Matched Different VehicleAlert", async () => { // Arrange const mockRegistrationAddress = { @@ -182,8 +175,9 @@ describe("address-lookup.vue", () => { // Assert expect(wrapper.findComponent({ ref: "alertVinNotFound" }).isVisible()).toBe(true); }); + }); - +/* describe("navigation", () => { test("if the back button is clicked, navigate back", async () => { // Arrange @@ -195,7 +189,7 @@ describe("address-lookup.vue", () => { await wrapper.vm.backButtonAction(); // Assert - expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalled(); + expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); }); test("if the car entered matches one of the vehicles found and the zip is serviceable, navigate forward", async () => { @@ -291,7 +285,7 @@ describe("address-lookup.vue", () => { await wrapper.vm.forwardButtonAction(); // Assert - expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith( + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith( navigationScenarios.CLICKED_FORWARD_WITH_MULTIPLE_VEHICLES, undefined, {}, @@ -380,7 +374,7 @@ describe("address-lookup.vue", () => { await wrapper.vm.navigateForward(carsFound); // Assert - expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith( + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith( navigationScenarios.SELECTED_VIN_WITH_MISMATCHED_GLASS, undefined, {}, @@ -634,6 +628,7 @@ describe("address-lookup.vue", () => { }); }); }); + */ }); function setupMocks({ @@ -644,50 +639,52 @@ function setupMocks({ isStatePermissible = true, vinVehicles = [], carId = "C0000", -}) { - store.commit(storeMutations.RESET_STATE); +}) +{ + /* + useMainStore().validateZip = jest.fn().mockImplementation(() => { + return Promise.resolve({ + data: { + isValid: isZipValid, + isServiceable: isZipServiceable, + }, + }) + }); + + useMainStore().LOOKUP_VIN_BY_ADDRESS = jest.fn().mockImplementation(() => { + return Promise.resolve({ + data: lookupVinbyAddressResponse + ? lookupVinbyAddressResponse + : { + isStatePermissible: true, + vinVehicles: [ + { + vin: "TEST_VIN", + vehicle: { + carId: "CARID", + }, + }, + ], + }, + }) + }) +*/ + useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => { + return Promise.resolve({ + data: { + partsOrQuestions: partsOrQuestions, + }, + }) + }); + const wrapper = shallowMount( addressLookup, getMountOptions({ - actionList: [ - { - actionName: storeActions.VALIDATE_ZIP, - data: { - isValid: isZipValid, - isServiceable: isZipServiceable, - }, - }, - { - actionName: storeActions.LOOKUP_VIN_BY_ADDRESS, - data: lookupVinbyAddressResponse - ? lookupVinbyAddressResponse - : { - isStatePermissible: true, - vinVehicles: [ - { - vin: "TEST_VIN", - vehicle: { - carId: "CARID", - }, - }, - ], - }, - }, - { - actionName: storeActions.GET_PARTS_OR_QUESTIONS, - data: { - partsOrQuestions: partsOrQuestions, - }, - }, - ], router: { navigate: jest.fn(), - navigate: jest.fn(), - navigateWithSaving: jest.fn(), - navigateWithoutSaving: jest.fn(), }, - store: { - getters: { + mainStore: { + order: { vehicle: { carId: carId, registration: { @@ -723,8 +720,8 @@ function setupMocks({ wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => ""); wrapper.vm.setCmsContent = jest.fn(); - wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); - wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn(); + wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn(); + wrapper.vm.$refs.siteFooter.removeLoader = jest.fn(); return { wrapper }; } diff --git a/src/layouts/address-lookup/customer-questions/address-questions/address-questions.spec.js b/src/layouts/address-lookup/customer-questions/address-questions/address-questions.spec.js index c8d24c57..48a637aa 100644 --- a/src/layouts/address-lookup/customer-questions/address-questions/address-questions.spec.js +++ b/src/layouts/address-lookup/customer-questions/address-questions/address-questions.spec.js @@ -5,8 +5,6 @@ import alert from "@/ux-components/alert/alert"; // Supporting Files import { mount, shallowMount } from "@vue/test-utils"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; -import { storeMutations } from "@/constants/store-mutations"; -import store from "@/store"; let autocompleteElement; describe("address-questions.vue", () => { @@ -18,29 +16,6 @@ describe("address-questions.vue", () => { }); describe("initial state", () => { - test("only street address field is shown", () => { - // Arrange - const { wrapper } = setupMocks({}); - - // Assert - const streetAddressField = wrapper.findComponent({ ref: "autocomplete" }); - const cityField = wrapper.findComponent({ ref: "city" }); - const stateField = wrapper.findComponent({ ref: "state" }); - const zipCodeField = wrapper.findComponent({ ref: "zipCode" }); - - expect(streetAddressField.exists()).toBe(true); - expect(streetAddressField.isVisible()).toBe(true); - expect(cityField.exists()).toBe(true); - expect(cityField.isVisible()).toBe(false); - expect(stateField.exists()).toBe(true); - expect(stateField.isVisible()).toBe(false); - expect(zipCodeField.exists()).toBe(true); - expect(zipCodeField.isVisible()).toBe(false); - - const alerts = wrapper.findAllComponents(alert); - expect(alerts.length).toEqual(0); - }); - test("Should render addressQuestions sub-components (textbox-questions and dropdown-questions)", async () => { // Arrange const { wrapper } = setupMocks({}); @@ -57,28 +32,7 @@ describe("address-questions.vue", () => { expect(state.exists()).toBe(true); expect(zipCode.exists()).toBe(true); }); - - test("Should it set this.showAddressFields to true when the model is prepopulated", async () => { - // Arrange - // Act - const newAddressModel = { - streetAddress: "foo", - city: "foo", - state: "foo", - zipCode: "55555", - }; - const wrapper = shallowMount(addressQuestions, { - propsData: { - modelValue: newAddressModel, - }, - }); - - // Act - wrapper.vm.setupAddressLookup(); - - // Assert - expect(wrapper.vm.showAddressFields).toBe(true); - }); + }); describe("happy paths", () => { @@ -109,46 +63,6 @@ describe("address-questions.vue", () => { expect(cityField.isVisible()).toBeTruthy(); }); - test("full street address is passed in => don't load Google Autocomplete script", async () => { - // Arrange/Act - const { wrapper } = setupMocks({ - props: { - modelValue: { - streetAddress: "12345 Test Road", - city: "Tests", - state: "OH", - zipCode: "12312", - }, - }, - }); - - await wrapper.vm.$nextTick(); - - // Assert - expect(wrapper.vm.$loadScript).not.toHaveBeenCalled(); - }); - - test("address field is focused => disable autofill", async () => { - // Arrange - let focusEventCallbackFunction; - autocompleteElement.addEventListener = jest - .fn() - .mockImplementation((eventName, callbackFunction) => { - if (eventName == "focus") { - focusEventCallbackFunction = callbackFunction; - } - }); - const { wrapper } = setupMocks({}); - await wrapper.vm.$nextTick(); - - // Act - focusEventCallbackFunction(); - await wrapper.vm.$nextTick(); - - // Assert - expect(autocompleteElement.getAttribute("autocomplete")).toEqual("do-not-autofill"); - }); - test("street address is entered, user chooses good result from autocomplete results => other fields are filled in", async () => { // Arrange const { wrapper } = setupMocks({}); @@ -520,6 +434,7 @@ describe("address-questions.vue", () => { }); }); }); + }); function setupMocks({ @@ -529,8 +444,7 @@ function setupMocks({ querySelectorFunction, geocoderResult = ["1234 Test Street"], }) { - store.commit(storeMutations.RESET_STATE); - + const resultingMountOptions = getMountOptions({ ...mountOptions, router: { diff --git a/src/layouts/address-lookup/customer-questions/customer-questions.spec.js b/src/layouts/address-lookup/customer-questions/customer-questions.spec.js index 11c7fb3a..9cd7c566 100644 --- a/src/layouts/address-lookup/customer-questions/customer-questions.spec.js +++ b/src/layouts/address-lookup/customer-questions/customer-questions.spec.js @@ -22,12 +22,10 @@ describe("customerQuestions.vue", () => { const addressQuestions = wrapper.findComponent({ ref: "addressQuestions" }); const firstName = wrapper.findComponent({ ref: "firstName" }); const lastName = wrapper.findComponent({ ref: "lastName" }); - const emailAddress = wrapper.findComponent({ ref: "emailAddress" }); // Assert expect(addressQuestions.exists()).toBe(true); expect(firstName.exists()).toBe(true); expect(lastName.exists()).toBe(true); - expect(emailAddress.exists()).toBe(true); }); }); diff --git a/src/mixins/vin-pages-mixin.js b/src/mixins/vin-pages-mixin.js index 9b9de2e1..ce246f32 100644 --- a/src/mixins/vin-pages-mixin.js +++ b/src/mixins/vin-pages-mixin.js @@ -4,9 +4,7 @@ import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; export default { methods: { async navigateForwardWithSingleCarMatch() { - const store = useMainStore(); - - const result = await store.getPartsOrQuestions(); + const result = await useMainStore().getPartsOrQuestions(); const partsOrQuestions = result.data.partsOrQuestions; vehicleQuestionsMixin.methods.navigateForward(partsOrQuestions, this); diff --git a/src/mixins/vin-pages-mixin.spec.js b/src/mixins/vin-pages-mixin.spec.js index ce9c267f..bac3a3a7 100644 --- a/src/mixins/vin-pages-mixin.spec.js +++ b/src/mixins/vin-pages-mixin.spec.js @@ -4,14 +4,6 @@ import { setupMocksForJsFiles, getMountOptions } from "@/helpers/unit-test-helpe import { storeActions } from "@/constants/store-actions"; import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; -jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({ - navigateForward: jest.fn(), -})); - -jest.mock("@/helpers/heritage-integration/order-helper.js", () => ({ - saveSession: jest.fn(), -})); - describe("vin-pages-mixin", () => { afterEach(() => { jest.clearAllMocks(); From 71364d41345040ce7d1c061dd6e9f330a21d68e8 Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Tue, 17 Jan 2023 15:41:48 -0500 Subject: [PATCH 2/3] updated tests --- .../address-lookup/address-lookup.spec.js | 155 ++++++------------ src/layouts/address-lookup/address-lookup.vue | 17 +- src/mixins/vin-pages-mixin.spec.js | 30 +--- src/store/index.js | 37 +++++ src/store/store.spec.js | 62 +++++++ 5 files changed, 154 insertions(+), 147 deletions(-) diff --git a/src/layouts/address-lookup/address-lookup.spec.js b/src/layouts/address-lookup/address-lookup.spec.js index 7d90e6b9..a9822772 100644 --- a/src/layouts/address-lookup/address-lookup.spec.js +++ b/src/layouts/address-lookup/address-lookup.spec.js @@ -7,7 +7,6 @@ import { shallowMount } from "@vue/test-utils"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { useMainStore } from "@/store"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; -import store from "@/store"; jest.mock("@/helpers/damage-helper", () => ({ isGlassAvailableForCarId: jest.fn().mockImplementation(() => true), @@ -40,6 +39,12 @@ describe("address-lookup.vue", () => { carId: "C0000", }, }, + { + vin: "TEST_VIN", + vehicle: { + carId: "C0000", + }, + }, ], }); @@ -47,6 +52,7 @@ describe("address-lookup.vue", () => { customerQuestions: { addressQuestions: mockRegistrationAddress, }, + }); // Act @@ -55,8 +61,7 @@ describe("address-lookup.vue", () => { // Assert expect(wrapper.findComponent({ ref: "alertNonServiceableZip" }).isVisible()).toBe(true); }); - }); - /* + test("if the address matches a different vehicle display the Matched Different VehicleAlert", async () => { // Arrange const mockRegistrationAddress = { @@ -77,7 +82,7 @@ describe("address-lookup.vue", () => { ], }); - store.commit(storeMutations.UPDATE_CAR_ID, "CARID2"); + useMainStore().order.vehicle.carId = "CARID2"; await wrapper.setData({ customerQuestions: { @@ -125,7 +130,7 @@ describe("address-lookup.vue", () => { }, }); - store.commit(storeMutations.UPDATE_CAR_ID, "CARID"); + useMainStore().order.vehicle.carId = "CARID"; await wrapper.setData({ customerQuestions: { @@ -159,7 +164,7 @@ describe("address-lookup.vue", () => { }, }); - store.commit(storeMutations.UPDATE_CAR_ID, "CARID"); + useMainStore().order.vehicle.carId = "CARID"; await wrapper.setData({ customerQuestions: { @@ -177,7 +182,7 @@ describe("address-lookup.vue", () => { }); }); -/* + describe("navigation", () => { test("if the back button is clicked, navigate back", async () => { // Arrange @@ -256,7 +261,7 @@ describe("address-lookup.vue", () => { ], }); - store.commit(storeMutations.UPDATE_CAR_ID, "CARID_A"); + useMainStore().order.vehicle.carId = "CARID_A"; const carsFound = [ { @@ -322,7 +327,7 @@ describe("address-lookup.vue", () => { ], }); - store.commit(storeMutations.UPDATE_CAR_ID, "CARID"); + useMainStore().order.vehicle.carId = "CARID"; await wrapper.setData({ customerQuestions: { @@ -361,6 +366,8 @@ describe("address-lookup.vue", () => { isSelectedGlassAvailableForVehicle: false, }); + useMainStore().order.vehicle.carId = "CARID"; + let carsFound = [ { vin: "TEST_VIN2", @@ -397,6 +404,8 @@ describe("address-lookup.vue", () => { const { wrapper } = setupMocks({}, {}); wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn(); + useMainStore().order.vehicle.carId = "C0000"; + // Act wrapper.vm.navigateForward(carsFound); @@ -430,12 +439,15 @@ describe("address-lookup.vue", () => { const { wrapper } = setupMocks({}); wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn(); + useMainStore().order.vehicle.carId = "CARID3"; + // Act wrapper.vm.navigateForward(carsFound); // Assert expect(wrapper.vm.navigateForwardWithSingleCarMatch).toHaveBeenCalledTimes(1); }); + }); describe("registration and service zips", () => { @@ -451,9 +463,19 @@ describe("address-lookup.vue", () => { const { wrapper } = setupMocks({ isZipServiceable: true, + isStatePermissible: true, + vinVehicles: [ + { + vin: "TEST_VIN", + vehicle: { + carId: "CARID", + }, + }, + ], }); - store.commit(storeMutations.UPDATE_CAR_ID, "CARID"); + useMainStore().order.vehicle.carId = "CARID"; + useMainStore().saveRegistrationAddressLookup = jest.fn(); await wrapper.setData({ customerQuestions: { @@ -465,20 +487,8 @@ describe("address-lookup.vue", () => { await wrapper.vm.forwardButtonAction(); // Assert - expect(wrapper.vm.dispatchStoreAction).toHaveBeenCalledWith( - "lookupVinByAddress", - { - licenseLastName: undefined, - licenseState: "OH", - licenseStreetAddress: "1234 Main St", - licenseZip: "43215", - }, - false - ); - - expect(wrapper.vm.dispatchStoreAction).toHaveBeenCalledWith("validateZip", { - zip: "43215", - }); + expect(useMainStore().saveRegistrationAddressLookup).toHaveBeenCalled(); + expect(useMainStore().validateZip).toHaveBeenCalledWith({ zip: "43215" }); }); }); @@ -505,7 +515,7 @@ describe("address-lookup.vue", () => { ], }); - store.commit(storeMutations.UPDATE_CAR_ID, "CARID"); + useMainStore().order.vehicle.carId = "C0000"; await wrapper.setData({ customerQuestions: { @@ -543,7 +553,7 @@ describe("address-lookup.vue", () => { isZipServiceable: false, }); - store.commit(storeMutations.UPDATE_CAR_ID, "CARID"); + useMainStore().order.vehicle.carId = "CARID"; await wrapper.setData({ customerQuestions: { @@ -551,84 +561,17 @@ describe("address-lookup.vue", () => { }, }); + useMainStore().saveRegistrationAddressLookup = jest.fn(); + // Act await wrapper.vm.forwardButtonAction(); - //FIX THIS // Assert - expect(wrapper.vm.dispatchStoreAction).not.toHaveBeenCalledWith( - storeActions.UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION - ); - }); - - test("if registration address, service zip are provided, and user clicks continue => both zips are saved and are different", async () => { - // Arrange - const mockRegistrationAddress = { - streetAddress: "1234 Main St", - city: "Columbus", - state: "OH", - zipCode: "43215", - }; - - const { wrapper } = setupMocks({}); - wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn(); - - store.commit(storeMutations.UPDATE_CAR_ID, "CARID"); - - wrapper.vm.dispatchStoreAction = jest.fn(); - wrapper.vm.dispatchStoreAction.mockImplementation((actionName, value) => { - let data = {}; - if (actionName == storeActions.VALIDATE_ZIP) { - if (value == "43215") { - data = { - isServiceable: false, - }; - } else { - data = { - isServiceable: true, - }; - } - } else if (actionName == storeActions.LOOKUP_VIN_BY_ADDRESS) { - data = { - isStatePermissible: true, - vinVehicles: [ - { - vin: "TEST_VIN", - vehicle: { - carId: "CARID", - }, - }, - ], - }; - } - - return Promise.resolve({ data }); - }); - - await wrapper.setData({ - customerQuestions: { - addressQuestions: mockRegistrationAddress, - }, - }); - - await wrapper.vm.forwardButtonAction(); - await wrapper.setData({ - serviceZipCode: "12345", - }); - - // // Act - await wrapper.vm.forwardButtonAction(); - - // // Assert - expect(wrapper.vm.$store.getters.order.serviceLocation.zipCode).not.toEqual( - wrapper.vm.$store.getters.vehicle.registration.zipCode - ); - expect(wrapper.vm.$store.getters.vehicle.registration.zipCode).toEqual("12345"); - expect(wrapper.vm.$store.getters.order.serviceLocation.zipCode).toEqual("11111"); + expect(useMainStore().saveRegistrationAddressLookup).not.toHaveBeenCalled(); }); }); }); - */ + }); function setupMocks({ @@ -641,7 +584,7 @@ function setupMocks({ carId = "C0000", }) { - /* + useMainStore().validateZip = jest.fn().mockImplementation(() => { return Promise.resolve({ data: { @@ -651,7 +594,7 @@ function setupMocks({ }) }); - useMainStore().LOOKUP_VIN_BY_ADDRESS = jest.fn().mockImplementation(() => { + useMainStore().lookupVinByAddress = jest.fn().mockImplementation(() => { return Promise.resolve({ data: lookupVinbyAddressResponse ? lookupVinbyAddressResponse @@ -668,7 +611,7 @@ function setupMocks({ }, }) }) -*/ + useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => { return Promise.resolve({ data: { @@ -692,13 +635,11 @@ function setupMocks({ zipCode: "12345", }, }, - order: { - customer: { - emailAddress: "test@test.com", - }, - serviceLocation: { - zipCode: "11111", - }, + customer: { + emailAddress: "test@test.com", + }, + serviceLocation: { + zipCode: "11111", }, }, }, diff --git a/src/layouts/address-lookup/address-lookup.vue b/src/layouts/address-lookup/address-lookup.vue index 05e50102..1da8fc84 100644 --- a/src/layouts/address-lookup/address-lookup.vue +++ b/src/layouts/address-lookup/address-lookup.vue @@ -163,19 +163,7 @@ export default { return this.mainStore.order.vehicle.carId !== null; }, loadDefaultsFromStore() { - const data = this.mainStore.order.vehicle.registration; - this.customerQuestions = { ...this.customerQuestions, - ...{ - firstName: data.firstName, - lastName: data.lastName, - addressQuestions: { - streetAddress: data.address, - city: data.city, - state: data.state, - zipCode: data.zipCode - } - } - }; + this.customerQuestions = this.mainStore.customerDataAddressLookup; }, backButtonAction() { // route to move backwards @@ -340,8 +328,7 @@ export default { // display vehicle changed alert on that page. if ( this.isCarIdDifferent && - !this.isSelectedGlassAvailableForVehicle && - matchingCars.length === 1 + !this.isSelectedGlassAvailableForVehicle ) { this.$router.navigate( this.navigationScenarios.SELECTED_VIN_WITH_MISMATCHED_GLASS, diff --git a/src/mixins/vin-pages-mixin.spec.js b/src/mixins/vin-pages-mixin.spec.js index bac3a3a7..0f19a9b0 100644 --- a/src/mixins/vin-pages-mixin.spec.js +++ b/src/mixins/vin-pages-mixin.spec.js @@ -1,8 +1,8 @@ import vinPagesMixin from "@/mixins/vin-pages-mixin"; import { shallowMount } from "@vue/test-utils"; -import { setupMocksForJsFiles, getMountOptions } from "@/helpers/unit-test-helper.js"; -import { storeActions } from "@/constants/store-actions"; +import { getMountOptions } from "@/helpers/unit-test-helper.js"; import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; +import { useMainStore } from "@/store"; describe("vin-pages-mixin", () => { afterEach(() => { @@ -12,6 +12,7 @@ describe("vin-pages-mixin", () => { describe("navigateForwardWithSingleCarMatch", () => { test("should navigateForward", async () => { // Arrange + useMainStore().getPartsOrQuestions = () => { return { data: {partsOrQuestions: {}}} }; const { wrapper } = setupMocks({}); vehicleQuestionsMixin.methods.navigateForward = jest.fn(); @@ -24,36 +25,15 @@ describe("vin-pages-mixin", () => { }); }); -function setupMocks({ partsOrQuestions = [] }) { - const baseMixin = setupMocksForJsFiles({ - actionList: [ - { - actionName: storeActions.GET_PARTS_OR_QUESTIONS, - data: { - partsOrQuestions: partsOrQuestions, - }, - }, - ], - }); - +function setupMocks() { const mocks = getMountOptions({ router: { navigate: jest.fn(), - navigateWithSaving: jest.fn(), - navigateWithoutSaving: jest.fn(), - }, - store: { - commit: jest.fn(), - getters: { - applicationUser: { - savedSessionId: 1, - }, - }, }, }); const mockVinComponent = { - mixins: [vinPagesMixin, baseMixin.baseMixin], + mixins: [vinPagesMixin], }; const wrapper = shallowMount(mockVinComponent, mocks); diff --git a/src/store/index.js b/src/store/index.js index cc05bf84..95d626f7 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -42,6 +42,14 @@ const getDefaultState = () => { capabilityQuestionAnswers: null, }, customer: { + address: { + streetAddress: null, + city: null, + state: null, + zipCode: null, + }, + firstName: null, + lastName: null, emailAddress: null, }, serviceLocation: { @@ -109,6 +117,35 @@ export const useMainStore = defineStore({ applicationUserObj: (state) => state.applicationUser, pageData: (state) => (page) => { return state.applicationUser.pageData[page]; + }, + customerDataAddressLookup: (state) => { + if (state.order.vehicle.registration.address) + { + const registration = state.order.vehicle.registration; + return { + addressQuestions: { + streetAddress: registration.address, + city: registration.city, + state: registration.state, + zipCode: registration.zipCode, + }, + firstName: registration.firstName, + lastName: registration.lastName, + } + } + else { + const address = state.order.customer.address; + return { + addressQuestions: { + streetAddress: address.streetAddress, + city: address.city, + state: address.state, + zipCode: address.zipCode, + }, + firstName: state.order.customer.firstName, + lastName: state.order.customer.lastName, + } + } }, experimentOrder: (state) => { return { diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 1f74048d..c8721b6d 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -157,4 +157,66 @@ describe("Store", () => { expect(store.order.damage.numberOfChips).toEqual(null); }); + it("should return registration data if available", () => { + //Arrange + const expected = { + addressQuestions: { + streetAddress: "test", + city: "city", + state: "state", + zipCode: "zip", + }, + firstName: "1stName", + lastName: "Surname", + } + + store.order.vehicle.registration = { + licensePlate: null, + address: "test", + city: "city", + state: "state", + zipCode: "zip", + firstName: "1stName", + lastName: "Surname", + }; + + //Act + const actual = store.customerDataAddressLookup; + //Assert + + expect(actual).toEqual(expected); + }); + + it("should return customer data if registration data unavailable", () => { + //Arrange + const expected = { + addressQuestions: { + streetAddress: "test", + city: "city", + state: "state", + zipCode: "zip", + }, + firstName: "1stName", + lastName: "Surname", + } + + store.order.vehicle.registration.address = null; + + store.order.customer = { + licensePlate: null, + address: "test", + city: "city", + state: "state", + zipCode: "zip", + firstName: "1stName", + lastName: "Surname", + }; + + //Act + const actual = store.customerDataAddressLookup; + //Assert + + expect(actual).toEqual(expected); + }); + }); \ No newline at end of file From b56735bc6d0aa9345191fd07f4cb4e0090b88a6d Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Tue, 17 Jan 2023 17:05:14 -0500 Subject: [PATCH 3/3] corrected test --- src/layouts/address-lookup/address-lookup.spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/layouts/address-lookup/address-lookup.spec.js b/src/layouts/address-lookup/address-lookup.spec.js index a9822772..161ce9a5 100644 --- a/src/layouts/address-lookup/address-lookup.spec.js +++ b/src/layouts/address-lookup/address-lookup.spec.js @@ -7,6 +7,7 @@ import { shallowMount } from "@vue/test-utils"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { useMainStore } from "@/store"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; +import e from "express"; jest.mock("@/helpers/damage-helper", () => ({ isGlassAvailableForCarId: jest.fn().mockImplementation(() => true), @@ -472,6 +473,7 @@ describe("address-lookup.vue", () => { }, }, ], + route: { query: "address-lookup" }, }); useMainStore().order.vehicle.carId = "CARID"; @@ -582,6 +584,7 @@ function setupMocks({ isStatePermissible = true, vinVehicles = [], carId = "C0000", + route = null, }) { @@ -623,6 +626,7 @@ function setupMocks({ const wrapper = shallowMount( addressLookup, getMountOptions({ + route: route ? route : undefined, router: { navigate: jest.fn(), }, @@ -643,6 +647,7 @@ function setupMocks({ }, }, }, + }) );