diff --git a/jest.config.js b/jest.config.js index e75fc82ab..b594d4aef 100644 --- a/jest.config.js +++ b/jest.config.js @@ -11,11 +11,9 @@ module.exports = { "!src/constants/*.js", "!src/router/**/*.js", "!src/helpers/unit-test-helper.js", - "!src/helpers/damage-helper.js", "!src/layouts/component-test/component-test.vue", "!src/layouts/form-test/form-test.vue", "!src/layouts/vin-lookup/vin-lookup.vue", - "!src/layouts/license-plate-lookup/license-plate-lookup.vue", "!src/layouts/vehicle-damage/windshield-damage-type-question/windshield-damage-type-question.vue", "!src/layouts/vehicle-damage/windshield-options/windshield-options.vue", "!src/layouts/part-questions/**/*.vue", @@ -28,7 +26,6 @@ module.exports = { "!src/common-components/dropdown-question/dropdown-question.vue", "!src/common-components/textbox-question/textbox-question.vue", "!src/helpers/validation-rules.js", - "!src/helpers/damage-helper.js", // END ], //! means exclude from coverage. testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"], diff --git a/src/helpers/damage-helper.js b/src/helpers/damage-helper.js index e56761dc5..443712991 100644 --- a/src/helpers/damage-helper.js +++ b/src/helpers/damage-helper.js @@ -3,7 +3,24 @@ import baseMixin from "@/mixins/base-mixin.js"; import { storeActions } from "@/constants/store-actions"; export function getDamageString() { - return store.getters.damage.glassToReplace.length > 1 ? "match" : store.getters.damage.glassToReplace[0].location; + const damageLocations = store.getters.damage.glassToReplace; + let returnString; + if(damageLocations.length > 1){ + returnString = "match" + } else { + switch(damageLocations[0]?.location) { + case "Windshield": + returnString = "windshield" + break; + case "Driver": + case "Passenger": + returnString = "side window" + break; + case "Rear": + returnString = "rear window" + } + } + return returnString; } export async function isGlassAvailableForCarId(carId){ diff --git a/src/helpers/damage-helper.spec.js b/src/helpers/damage-helper.spec.js index ad5f8f878..2a46978dc 100644 --- a/src/helpers/damage-helper.spec.js +++ b/src/helpers/damage-helper.spec.js @@ -1,16 +1,91 @@ import {getDamageString, isGlassAvailableForCarId} from "./damage-helper"; -//import baseMixin from "@/mixins/base-mixin.js"; +import store from "@/store"; -jest.mock("@/store", () => ({ - getters: {damage: { - glassToReplace: [{location: "Windshield", name: "windshield"}] - } - } - })); +// Mock basemixin. +jest.mock("@/mixins/base-mixin.js", () => ({ + methods: { + dispatchStoreAction: jest.fn().mockImplementation(() => { return { + data: { + windshieldOptions: {availableReplacementOptions: ["windshield"]} + } + } }), + }, +})); describe("damage-helper.js", () => { - it("Should return damage getter info", () => { + it("Should return match when multiple selected damage options are in the store", () => { + + // Arrange / Act + store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}, {location: "Passenger", name: "sideWindow"}]; + const damage = getDamageString(); - expect(damage).toEqual("Windshield") + + // Assert + expect(damage).toEqual("match"); }); - }); \ No newline at end of file + }); + + describe("damage-helper.js", () => { + it("Should return windshield when Windshield is the only selected damage option in the store", () => { + + // Arrange / Act + store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}]; + + const damage = getDamageString(); + + // Assert + expect(damage).toEqual("windshield"); + }); + }); + + describe("damage-helper.js", () => { + it("Should return side window when Driver or Passenger is the only selected damage option in the store", () => { + + // Arrange / Act + store.getters.damage.glassToReplace = [{location: "Passenger", name: "sideWindow"}]; + + const damage = getDamageString(); + + // Assert + expect(damage).toEqual("side window"); + }); + }); + + describe("damage-helper.js", () => { + it("Should return rear window when Rear is the only selected damage option in the store", () => { + + // Arrange / Act + store.getters.damage.glassToReplace = [{location: "Rear", name: "rear"}]; + + const damage = getDamageString(); + + // Assert + expect(damage).toEqual("rear window"); + }); + }); + + describe("damage-helper.js", () => { + it("Should return true if no mismatches between each array exist", async () => { + // Arrange + store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}]; + + // Act + const isGlassAvailable = await isGlassAvailableForCarId(); + + // Assert + expect(isGlassAvailable).toEqual(true); + }); + }); + + describe("damage-helper.js", () => { + it("Should return false if any mismatches between each array exist", async () => { + // Arrange + store.getters.damage.glassToReplace = [{location: "Windshield", name: "sideWindow"}]; + + const isGlassAvailable = await isGlassAvailableForCarId(); + + // Assert + expect(isGlassAvailable).toEqual(false); + }); + }); + diff --git a/src/helpers/heritage-integration/navigation-helper.js b/src/helpers/heritage-integration/navigation-helper.js index 61c07203d..c7cf34940 100644 --- a/src/helpers/heritage-integration/navigation-helper.js +++ b/src/helpers/heritage-integration/navigation-helper.js @@ -140,4 +140,4 @@ function isVinRelatedPage(toRoute) { fmgPageValue === fmgPageValues.ADDRESS_LOOKUP || fmgPageValue === fmgPageValues.ADDRESS_VEHICLES || fmgPageValue === fmgPageValues.ESTIMATE; -} +} \ No newline at end of file diff --git a/src/helpers/heritage-integration/navigation-helper.spec.js b/src/helpers/heritage-integration/navigation-helper.spec.js index fd06920c2..01bf5dcdc 100644 --- a/src/helpers/heritage-integration/navigation-helper.spec.js +++ b/src/helpers/heritage-integration/navigation-helper.spec.js @@ -367,4 +367,4 @@ describe("navigateToHeritageFunnel", () => { }) ); }); -}); +}); \ No newline at end of file diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.spec.js b/src/layouts/license-plate-lookup/license-plate-lookup.spec.js index 6e6de9349..609ddcf2e 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.spec.js +++ b/src/layouts/license-plate-lookup/license-plate-lookup.spec.js @@ -1,5 +1,5 @@ // Components -import vehicleDamage from "@/layouts/license-plate-lookup/license-plate-lookup.vue"; +import licensePlateLookup from "@/layouts/license-plate-lookup/license-plate-lookup.vue"; // Supporting Files import { settleAllPromises } from "@/helpers/layout-helper.js"; @@ -8,10 +8,7 @@ import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { shallowMount, flushPromises } from "@vue/test-utils"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { nextTick } from "vue"; -import { storeActions } from "@/constants/store-actions"; -import { storeMutations } from "@/constants/store-mutations"; import store from "@/store"; -import { validate } from "vee-validate"; // Mock our module for promises. jest.mock("@/helpers/layout-helper.js", () => ({ @@ -29,25 +26,15 @@ jest.mock("@/store", () => ({ dispatch: jest.fn(), getters: { order: { - customer: { - emailAddress: "test@test.com" - }, - serviceLocation: { - zipCode: "43443" - } + customer: { emailAddress: "test@test.com"}, + serviceLocation: {zip: "11111"}, }, vehicle: { - carId: "C00000000", - image: "test.jpg", - payment: { - insuranceCoverage: { - isVerified: false - } - }, + carId: "TESTID", registration: { - licensePlate: "HWV4445", - zipCode: "43224" - } + licensePlate: "TESTPLATE", + zipCode: "12345", + }, }, eventBusItem: jest.fn(), damage: { @@ -62,7 +49,7 @@ describe("license-plate-lookup.vue", () => { const { wrapper } = setupMocks({}); //Act - vehicleDamage.beforeRouteEnter.call( + licensePlateLookup.beforeRouteEnter.call( wrapper.vm, { query: { fmgPage: "license-plate-lookup" } }, undefined, @@ -84,7 +71,7 @@ describe("license-plate-lookup.vue", () => { const { wrapper } = setupMocks({}); //Act - vehicleDamage.beforeRouteEnter.call( + licensePlateLookup.beforeRouteEnter.call( wrapper.vm, { query: { fmgPage: "license-plate-lookup" } }, undefined, @@ -99,6 +86,340 @@ describe("license-plate-lookup.vue", () => { }); }); +describe("license-plate-lookup.vue", () => { + test("getLicensePlateFromStore returns store license plate", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + // ACT + const licensePlate = wrapper.vm.getLicensePlateFromStore(); + + // Assert + expect(licensePlate).toEqual("TESTPLATE"); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("getRegistrationZipFromStore returns store registration zip", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + // ACT + const registrationZip = wrapper.vm.getRegistrationZipFromStore(); + + // Assert + expect(registrationZip).toEqual("12345"); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("getEmailFromStore returns store customer email", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + // ACT + const customerEmail = wrapper.vm.getEmailFromStore(); + + // Assert + expect(customerEmail).toEqual("test@test.com"); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("getServiceZipFromStore returns store service zip", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + // ACT + const serviceZip = wrapper.vm.getServiceZipFromStore(); + + // Assert + expect(serviceZip).toEqual("11111"); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("Navigate forward should be called and isCarId should be set to false when data entered matches store data on forwardButtonAction click", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + wrapper.vm.validateZip = jest.fn().mockImplementation(() => { + return {data: {isServiceable: true}}; + }); + wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => { + return ''; + }); + const vinLookup = {data: {vehicle: {carId: "TESTID"}}} + wrapper.vm.lookupVin = jest.fn().mockImplementation(() => { + return {catch: () => vinLookup}; + }); + wrapper.vm.navigateForward = jest.fn(); + + //Act + licensePlateLookup.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "license-plate-lookup" } }, + undefined, + (c) => c(wrapper.vm) + ); + + await wrapper.vm.forwardButtonAction(); + + //Assert + expect(wrapper.vm.navigateForward).toHaveBeenCalled(); + expect(wrapper.vm.isCarIdDifferent).toEqual(false); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("Function should stop and datam isRegistrationZipServicable should be set to false when service zip entered returns false on forwardButtonAction click", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + wrapper.vm.validateZip = jest.fn().mockImplementation(() => { + return {data: {isServiceable: false}}; + }); + wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => { + return ''; + }); + wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn(); + //Act + licensePlateLookup.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "license-plate-lookup" } }, + undefined, + (c) => c(wrapper.vm) + ); + + await wrapper.vm.forwardButtonAction(); + + //Assert + expect(wrapper.vm.isRegistrationZipServicable).toEqual(false); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("Function should stop and datam isCarIdDifferent should be set to true when carId entered doesn't match store carId or previously entered carId on forwardButtonAction click", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + wrapper.vm.validateZip = jest.fn().mockImplementation(() => { + return {data: {isServiceable: true}}; + }); + wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => { + return ''; + }); + const vinLookup = {data: {vehicle: {carId: "TESTID1"}}} + wrapper.vm.lookupVin = jest.fn().mockImplementation(() => { + return {catch: () => vinLookup}; + }); + wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn(); + wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); + + //Act + licensePlateLookup.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "license-plate-lookup" } }, + undefined, + (c) => c(wrapper.vm) + ); + + await wrapper.vm.forwardButtonAction(); + + //Assert + expect(wrapper.vm.isCarIdDifferent).toEqual(true); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("Navigate forward should be called and isCarId should be set to true when carId entered matches previously entered carId and rest of data entered matches store data on forwardButtonAction click", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + wrapper.vm.validateZip = jest.fn().mockImplementation(() => { + return {data: {isServiceable: true}}; + }); + wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => { + return ''; + }); + const vinLookup = {data: {vehicle: {carId: "TESTID1"}}} + wrapper.vm.lookupVin = jest.fn().mockImplementation(() => { + return {catch: () => vinLookup}; + }); + wrapper.vm.previouslyEnteredCarId = "TESTID1"; + wrapper.vm.navigateForward = jest.fn(); + + //Act + licensePlateLookup.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "license-plate-lookup" } }, + undefined, + (c) => c(wrapper.vm) + ); + + await wrapper.vm.forwardButtonAction(); + + //Assert + expect(wrapper.vm.navigateForward).toHaveBeenCalled(); + expect(wrapper.vm.isCarIdDifferent).toEqual(true); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("Button Text should revert to initial value when licensePlate textfield has new text", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + //Act + wrapper.vm.licensePlate = "NEWPLATE"; + wrapper.vm.getCmsContent = jest.fn(); + wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); + await wrapper.vm.$nextTick(); + + //Assert + expect(wrapper.vm.$refs.funnelFooter.updateButtonText).toHaveBeenCalled(); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("Button Text should revert to initial value when registrationZip textfield has new text", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + //Act + wrapper.vm.registrationZip = "55555"; + wrapper.vm.getCmsContent = jest.fn(); + wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); + await wrapper.vm.$nextTick(); + + //Assert + expect(wrapper.vm.$refs.funnelFooter.updateButtonText).toHaveBeenCalled(); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("Button Text should revert to initial value when serviceZip textfield has new text", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + //Act + wrapper.vm.serviceZip = "55555"; + wrapper.vm.getCmsContent = jest.fn(); + wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); + await wrapper.vm.$nextTick(); + + //Assert + expect(wrapper.vm.$refs.funnelFooter.updateButtonText).toHaveBeenCalled(); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("Dispatch reset damage and dependencies should be called if isCarIdDifferent is true and isSelectedGlassAvailableForVehicle is false when updateCustomerInfo is called", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + //Act + wrapper.vm.isCarIdDifferent = true; + wrapper.vm.isSelectedGlassAvailableForVehicle = false; + wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => { + return ''; + }); + store.commit = jest.fn(); + store.dispatch = jest.fn(); + + const vehicleInfo = {year: "2020", make: "honda", model: "civic", style: "2 door", carId: "TestId", category: "testCat", imageUrl: "image.jpg", imageVifNumber: "123", imageColor: "blue"} + await wrapper.vm.updateCustomerInfo('vin', vehicleInfo, 'registrationState'); + + //Assert + expect(store.dispatch).toHaveBeenCalled(); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("NavigateAfterSave should be called if isCarIdDifferent is true and isSelectedGlassAvailableForVehicle is false when navigateForward is called", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + //Act + wrapper.vm.isCarIdDifferent = true; + wrapper.vm.isSelectedGlassAvailableForVehicle = false; + wrapper.vm.$router.navigateAfterSave = jest.fn(); + wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => { + return ''; + }); + store.dispatch = jest.fn(); + + await wrapper.vm.navigateForward(); + + //Assert + expect(wrapper.vm.$router.navigateAfterSave).toHaveBeenCalled(); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("navigateAfterSaveToHeritageFunnel should be called if isCarIdDifferent is false or isSelectedGlassAvailableForVehicle is true when navigateForward is called", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + //Act + wrapper.vm.isCarIdDifferent = false; + wrapper.vm.$router.navigateAfterSaveToHeritageFunnel = jest.fn(); + wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => { + return ''; + }); + + await wrapper.vm.navigateForward(); + + //Assert + expect(wrapper.vm.$router.navigateAfterSaveToHeritageFunnel).toHaveBeenCalled(); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("dispatch non blocking store action called on validate zip", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + //Act + await wrapper.vm.validateZip("12345"); + + + //Assert + expect(baseMixin.methods.dispatchStoreAction).toHaveBeenCalled(); + }); +}); + +describe("license-plate-lookup.vue", () => { + test("dispatch non blocking store action called on lookup vin", async () => { + + // Arrange + const { wrapper } = setupMocks({}); + + //Act + await wrapper.vm.lookupVin("zzz123fqsfwg"); + + + //Assert + expect(baseMixin.methods.dispatchStoreAction).toHaveBeenCalled(); + }); +}); + + function setupMocks({ pageHeaderWidgetHeaderText = {}, @@ -106,12 +427,8 @@ function setupMocks({ router: { navigate: jest.fn(), }, - store: { - getters: { - vehicle: {}, - payment: { insuranceCoverage: { isVerified: false } }, - }, - }, + licensePlate: "TESTPLATE", + registrationZip: "12345" }, }) { //Mock api responses @@ -139,7 +456,7 @@ function setupMocks({ const mountOptions = getMountOptions(mountOptionsMockData); mountOptions['attachTo'] = document.body; // append wrapper to document.body to test DOM methods - const wrapper = shallowMount(vehicleDamage, mountOptions); + const wrapper = shallowMount(licensePlateLookup, mountOptions); wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent; diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.vue b/src/layouts/license-plate-lookup/license-plate-lookup.vue index cce368d5c..356a8ec9e 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.vue +++ b/src/layouts/license-plate-lookup/license-plate-lookup.vue @@ -1,95 +1,40 @@ + diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index 80d7818d1..f087cac08 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -117,18 +117,6 @@ const routingTable = [ scenario: navigationScenarios.CLICKED_BACK, destinationFmgPageValue: fmgPageValues.ESTIMATE, }, - { - scenario: navigationScenarios.CONTINUING_WITH_PARTS_QUESTION, - destinationFmgPageValue: fmgPageValues.PART_QUESTIONS, - }, - { - scenario: navigationScenarios.CONTINUING_WITH_MULTIPLE_PARTS, - destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS, - }, - { - scenario: navigationScenarios.CONTINUING_WITH_SINGLE_PART, - destinationFmgPageValue: fmgPageValues.REVEAL, - }, { scenario: navigationScenarios.CLICKED_FORWARD, destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, diff --git a/src/ux-components/alert/alert.spec.js b/src/ux-components/alert/alert.spec.js index 17ed6988a..6f4bb9822 100644 --- a/src/ux-components/alert/alert.spec.js +++ b/src/ux-components/alert/alert.spec.js @@ -47,6 +47,21 @@ describe("alert.vue", () => { expect(wrapperDiv.classes()).toContain('warning') }); + it("Should update alert Headline to manualHeadline datam entered and alert copy to manualCopy datam entered when no cmsWidgetName entered", async () => { + // Arrange + const wrapper = shallowMount(alert, { + propsData: { + manualHeadline: 'testHeader', + manualCopy: 'testCopy' + }, + mixins: [mockMixin] + }); + + // Assert + expect(wrapper.vm.alertHeadline).toBe("testHeader"); + expect(wrapper.vm.alertCopy).toBe("testCopy"); + }); + }); const mockMixin = {