diff --git a/jest.config.js b/jest.config.js index cf903b82e..ded486df9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -28,8 +28,7 @@ module.exports = { testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"], coverageThreshold: { global: { - // TODO after release/2022.09.15, raise this back up!! - statements: 80, + statements: 85, // Got the go ahead from Mark to temporarily lower this. Taking out initialize component made the year,make,model and style coverage drop a bit. Once unit tests for license plate lookup, vin lookup and address lookup are in the coverage should go back up to 90 }, }, diff --git a/src/layouts/estimate/estimate.spec.js b/src/layouts/estimate/estimate.spec.js index 1843670ec..5bb575684 100644 --- a/src/layouts/estimate/estimate.spec.js +++ b/src/layouts/estimate/estimate.spec.js @@ -36,48 +36,6 @@ describe("estimate.vue", () => { //Assesrt expect(wrapper.emitted()["update:modelValue"][0]).toEqual([{ modelValue: ["Provide my license plate # Most accurate VIN match"] }]); }); - test("isRepair is set to true, arePagePrerequisitesValid should return true", async () => { - - //Arrange - const { wrapper } = setupMocks({}); - - //Act - store.commit( storeMutations.UPDATE_IS_REPAIR, true ); - - let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); - - //Assert - expect(arePagePrerequisitesValid).toBe(true); - }); - test("isRepair is set to true, arePagePrerequisitesValid should return true", async () => { - - //Arrange - const { wrapper } = setupMocks({}); - - //Act - store.commit( storeMutations.UPDATE_IS_REPAIR, true ); - - let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); - - //Assert - expect(arePagePrerequisitesValid).toBe(true); - }); - test.todo("isRepair is false and there are no lineItems => should return false") - test.todo("isRepair is false and lineItems is null => should return false") - test.todo("isRepair is false are there are lineItems => should return true") - test("isRepair is set to null, arePagePrerequisitesValid should return false", async () => { - - //Arrange - const { wrapper } = setupMocks({}); - - //Act - store.commit( storeMutations.UPDATE_IS_REPAIR, null ); - - let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); - - //Assert - expect(arePagePrerequisitesValid).toBe(false); - }); test("After selecting provide my home address on ForwardButtonAction triggers a router.navigateWithSaving", async () => { @@ -132,20 +90,104 @@ describe("estimate.vue", () => { test("Provide my license plate on ForwardButtonAction triggers a router.navigateWithSaving", async () => { - //Arrange - const { wrapper } = setupMocks({}); - await wrapper.setData({ - selectedVinLookupMethod: vinLookupMethodSelections.LICENSEPLATE - }) - - //Act - wrapper.vm.forwardButtonAction(); - - //Assert - expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalled(); + //Arrange + const { wrapper } = setupMocks({}); + await wrapper.setData({ + selectedVinLookupMethod: vinLookupMethodSelections.LICENSEPLATE + }) + + //Act + wrapper.vm.forwardButtonAction(); + + //Assert + expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalled(); }); + describe("arePagePrerequisitesValid", () => { + beforeEach(() => { + store.commit(storeMutations.UPDATE_IS_REPAIR, false); + store.commit(storeMutations.UPDATE_GLASS_TO_REPLACE, null); + }) + + test("isRepair is false and there are no glassToReplace => should return false", () => { + // Arrange + const { wrapper } = setupMocks({}); + store.commit(storeMutations.UPDATE_IS_REPAIR, false); + store.commit(storeMutations.UPDATE_GLASS_TO_REPLACE, []); + + // Act + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + + // Assert + expect(arePagePrerequisitesValid).toBe(false); + }) + + test("isRepair is false and glassToReplace is null => should return false", () => { + // Arrange + const { wrapper } = setupMocks({}); + store.commit(storeMutations.UPDATE_IS_REPAIR, false); + store.commit(storeMutations.UPDATE_GLASS_TO_REPLACE, null); + + // Act + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + + // Assert + expect(arePagePrerequisitesValid).toBe(false); + }) + + test("isRepair is false are there is one glassToReplace => should return true", () => { + // Arrange + const { wrapper } = setupMocks({}); + store.commit(storeMutations.UPDATE_IS_REPAIR, false); + store.commit(storeMutations.UPDATE_GLASS_TO_REPLACE, [{glassLocation: "TEST", glassName: "NAME"}]); + + // Act + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + + // Assert + expect(arePagePrerequisitesValid).toBe(true); + }) + + test("isRepair is false are there are multiple glassToReplace => should return true", () => { + // Arrange + const { wrapper } = setupMocks({}); + store.commit(storeMutations.UPDATE_IS_REPAIR, false); + store.commit(storeMutations.UPDATE_GLASS_TO_REPLACE, [{glassLocation: "TEST1", glassName: "NAME1"}, {glassLocation: "TEST2", glassName: "NAME2"}, {glassLocation: "TEST3", glassName: "NAME3"}]); + + // Act + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + + // Assert + expect(arePagePrerequisitesValid).toBe(true); + }) + + test("isRepair is set to null => arePagePrerequisitesValid should return false", async () => { + // Arrange + const { wrapper } = setupMocks({}); + store.commit(storeMutations.UPDATE_IS_REPAIR, null); + + // Act + console.log(store.getters.damage) + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + + // Assert + expect(arePagePrerequisitesValid).toBe(false); + }); + + test("isRepair is set to true => arePagePrerequisitesValid should return true", async () => { + // Arrange + const { wrapper } = setupMocks({}); + store.commit(storeMutations.UPDATE_IS_REPAIR, true); + + // Act + let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + + // Assert + expect(arePagePrerequisitesValid).toBe(true); + }); + }) + test("Changing zip should reset alert", async () => { //Arrange const { wrapper } = setupMocks({}); diff --git a/src/layouts/vehicle-parts/vehicle-parts.spec.js b/src/layouts/vehicle-parts/vehicle-parts.spec.js index 14c83cfdb..d1eaa8df6 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.spec.js +++ b/src/layouts/vehicle-parts/vehicle-parts.spec.js @@ -236,7 +236,7 @@ describe("vehicle-parts.vue", () => { wrapper.vm.backButtonAction(); //Assert - expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_TO_GO_TO_PART_QUESTIONS, wrapper.vm.$route); + expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_WITH_PART_QUESTIONS, wrapper.vm.$route); }); @@ -277,7 +277,7 @@ describe("vehicle-parts.vue", () => { wrapper.vm.backButtonAction(); //Assert - expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_TO_GO_TO_VIN_LOOKUP, wrapper.vm.$route); + expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_WITH_NO_QUESTIONS, wrapper.vm.$route); }); diff --git a/src/layouts/vehicle-style/vehicle-style.spec.js b/src/layouts/vehicle-style/vehicle-style.spec.js index 1dd3a6774..e97b14882 100644 --- a/src/layouts/vehicle-style/vehicle-style.spec.js +++ b/src/layouts/vehicle-style/vehicle-style.spec.js @@ -10,6 +10,9 @@ import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { storeActions } from "@/constants/store-actions"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import baseMixin from "@/mixins/base-mixin.js"; +import router from "@/router" +import store from "@/store" +import { storeMutations } from "@/constants/store-mutations"; // Mock our module for promises. jest.mock("@/helpers/layout-helper.js", () => ({ @@ -21,25 +24,16 @@ jest.mock("@/helpers/cms-content-helper", () => ({ fetchCmsContentForPage: jest.fn(), })); -// Mock Store -jest.mock("@/store", () => ({ - getters: { - vehicle: { - model: "TL", - }, - applicationUser:{ - pageData: { - "part-questions": null, - "vehicle-make": {}, - "vehicle-model": {}, - "vehicle-style": {}, - "vehicle-damage": {} - } - } - }, +// Mock fetchCmsContentForPage +jest.mock("@/router", () => ({ + overrideNavigation: jest.fn(), })); describe("vehicle-style.vue", () => { + beforeEach(() => { + jest.clearAllMocks(); + }) + test("Style question component is initized with api data", async (done) => { //Arrange const styleQuestionInitialData = ["2 Door", "4 Door"]; @@ -63,9 +57,7 @@ describe("vehicle-style.vue", () => { done(); }); }); -}); -describe("vehicle-style.vue", () => { test("BackButtonAction triggers a router.navigateWithoutSaving change", async (done) => { //Arrange const { wrapper, apiPromise } = setupMocks({ @@ -95,20 +87,12 @@ describe("vehicle-style.vue", () => { done(); }); }); -}); -describe("vehicle-style.vue", () => { - test("selectVehicle triggers a dispatchStoreAction commit", async (done) => { + test("setVehicle triggers a dispatchStoreAction commit", async (done) => { //Arrange const { wrapper, apiPromise } = setupMocks({ pageHeaderWidgetHeaderText: "Select a style to get started", mountOptionsMockData: { - store: { - commit: jest.fn(), - getters: { - vehicle: {}, - }, - }, actionList: [ { actionName: storeActions.SET_VEHICLE, @@ -134,9 +118,7 @@ describe("vehicle-style.vue", () => { done(); }); }); -}); -describe("vehicle-style.vue", () => { test("Model set, arePagePrerequisitesValid should be true ", async () => { //Arrange const { wrapper } = setupMocks({}); @@ -155,7 +137,61 @@ describe("vehicle-style.vue", () => { //Assert expect(arePagePrerequisitesValid).toBe(true); }); + + test("there is only one vehicle style => autoselect and move to vehicle damage", async () => { + //Arrange + const { wrapper } = setupMocks({ + styleQuestionInitialData: ["2 door sedan"], + }); + + // Act + await vehicleStyle.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "vehicle-style" } }, + undefined, + (c) => c(wrapper.vm) + ); + + // Assert + expect(store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_STYLE, "2 door sedan"); + expect(router.overrideNavigation).toHaveBeenCalled(); + }) + + test("there is only one vehicle style and vehicle-damage was visited => don't autoselect or move to vehicle damage", async () => { + //Arrange + const { wrapper } = setupMocks({ + styleQuestionInitialData: ["2 door sedan"], + mountOptionsMockData: { + store: { + getters: { + applicationUser: { + pageData: { + "part-questions": null, + "vehicle-make": {}, + "vehicle-model": {}, + "vehicle-style": {}, + "vehicle-damage": {} + } + } + } + } + } + }); + + // Act + await vehicleStyle.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "vehicle-style" } }, + undefined, + (c) => c(wrapper.vm) + ); + + // Assert + expect(store.commit).not.toHaveBeenCalledWith(storeMutations.UPDATE_STYLE, "2 door sedan"); + expect(router.overrideNavigation).not.toHaveBeenCalled(); + }) }); + function setupMocks({ vehicleStyleQuestionCmsContent = {}, styleQuestionInitialData = {}, @@ -190,7 +226,26 @@ function setupMocks({ initializeComponent: jest.fn(), }; - const mountOptions = getMountOptions(mountOptionsMockData); + store.commit = jest.fn(); + store.dispatch = jest.fn(); + store.getters = mountOptionsMockData.store?.getters ?? { + vehicle: { + model: "TL", + }, + applicationUser: { + pageData: { + "part-questions": null, + "vehicle-make": {}, + "vehicle-model": {}, + "vehicle-style": {}, + } + } + } + + const mountOptions = getMountOptions({ + ...mountOptionsMockData, + store + }); const wrapper = shallowMount(vehicleStyle, mountOptions); wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent; diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index b86914520..4a31c06cc 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -26,6 +26,7 @@