From 49347eb4bef6f55f3dc154dab46da1436ce0cc1f Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Wed, 26 Jul 2023 10:30:28 -0400 Subject: [PATCH 01/11] Unit Tests - Initial setup --- .../time-slot-modal-question.spec.js | 487 ++++++++++++++++++ .../time-slot-modal-question.vue | 4 +- 2 files changed, 489 insertions(+), 2 deletions(-) create mode 100644 src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.spec.js diff --git a/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.spec.js b/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.spec.js new file mode 100644 index 000000000..07c81ff0b --- /dev/null +++ b/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.spec.js @@ -0,0 +1,487 @@ +import { shallowMount, flushPromises } from "@vue/test-utils"; +import { getMountOptions } from "@/helpers/unit-test-helper.js"; +import { applicationConfig } from "@/constants/application-config"; +import { storeActions } from "@/constants/store-actions"; +import timeSlotModalQuestion from "@/layouts/schedule/time-slot-modal-question/time-slot-modal-question.vue"; +import store from "@/store"; +import * as navigateToHeritage from "@/helpers/heritage-integration/navigation-helper"; +import { nextTick } from "vue"; + +// jest.mock("@/store", () => ({ +// commit: jest.fn(), +// dispatch: jest.fn(), +// })); + +// Mock fetchCmsContentForPage +// jest.mock("@/helpers/cms-content-helper", () => ({ +// fetchCmsContentForPage: () => Promise.resolve("content"), +// })); + +// jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({ +// navigateToHeritageFunnel: jest.fn(), +// })); + +// jest.mock( +// "@/store", +// () => { +// return {}; +// }, +// { virtual: true } +// ); + +// START beforeRouteEnter mock arranging // +// jest.mock("@/mixins/base-mixin", () => ({ +// methods: { +// dispatchStoreAction(action, items, encode) { +// if (action === mockPriceOrderStoreAction) return items; +// else return mockStoreActionResults[action]; +// }, +// getTierOnePackagePrice() { +// return mockTierOnePrice; +// }, +// filterOutFees() { +// return null; +// } +// }, +// })); +// let mockTierOnePrice = 501; + +// const mockPriceOrderStoreAction = storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA; +// const mockStoreActionResults = {}; + +// mockStoreActionResults[storeActions.GET_WIPERS] = Promise.resolve([ +// { partNumber: "SBB24", partType: "FRONT WIPER" }, +// ]); +// mockStoreActionResults[storeActions.GET_RAIN_DEFENSE] = Promise.resolve({ +// partNumber: "RAIN DEFENSE", +// partType: "RAIN DEFENSE", +// }); +// mockStoreActionResults[storeActions.GET_SUPPORTING_ITEMS] = Promise.resolve([ +// { partNumber: "WSREPAIR", partType: "WSREPAIR" }, +// ]); +// END beforeRouteEnter mock arranging + +store.getters = { + order: { + payment: { + insuranceCoverage: {}, + isInsurance: false, + parentAccountNumber: applicationConfig.CASH_PARENT_ACCOUNT_NUMBER, + }, + }, +}; + +afterEach(() => { + // reset store after each test + store.getters = { + order: { + payment: { + parentAccountNumber: applicationConfig.CASH_PARENT_ACCOUNT_NUMBER, + }, + }, + payment: { + insuranceCoverage: {}, + isInsurance: false, + }, + }; +}); + +describe("time-slot-modal-list-button-question.vue", () => { + test.only("IsInsurance false should navigateWithSaving", async () => { + //Arrange + const { wrapper } = setupMocks({ + customMountOptions: { + router: { + navigateWithSaving: jest.fn(), + }, + }, + }); + + store.getters.payment = { + insuranceCoverage: {}, + isInsurance: false, + }; + // wrapper.vm.dispatchStoreAction = jest.fn(() => { + // return { + // data: [], + // }; + // }); + + // wrapper.vm.modal = { + // openModal() { return null}, + // closeModal() {return null}, + // }; + wrapper.vm.dateAndTimeSlotData.timeSlots = [{ + + }]; + wrapper.vm.$refs.timeSlots.closeModal = jest.fn(); + wrapper.vm.selectedTimeSlotId = "testRouteCodeId"; + + //await nextTick(); + + wrapper.vm.setSelectedTimeSlot(); + + //Act + //await wrapper.vm.forwardButtonAction(); + const expectedEmit = + //Assert + expect(wrapper.emitted()["update:modelValue"]).toEqual(expectedEmit); + }); +}); + +// describe("quote.vue", () => { +// test("IsInsurance false should navigateWithSaving", async () => { +// //Arrange +// const { wrapper } = setupMocks({ +// customMountOptions: { +// router: { +// navigateWithSaving: jest.fn(), +// }, +// route: { quote }, +// }, +// }); + +// store.getters.payment = { +// insuranceCoverage: {}, +// isInsurance: false, +// }; + +// wrapper.vm.dispatchStoreAction = jest.fn(() => { +// return { +// data: [], +// }; +// }); + +// wrapper.vm.pricedGlassParts = []; + +// //Act +// await wrapper.vm.forwardButtonAction(); + +// //Assert +// expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalled(); +// }); + +// test("IsInsurance true should navigateToHeritageFunnel", async () => { +// //Arrange +// const { wrapper } = setupMocks({ +// customMountOptions: { +// router: { +// navigateWithSaving: jest.fn(), +// }, +// route: { quote }, +// }, +// }); + +// store.getters.payment = { +// insuranceCoverage: {}, +// isInsurance: true, +// }; + +// wrapper.vm.dispatchStoreAction = jest.fn(() => { +// return { +// data: [], +// }; +// }); + +// wrapper.vm.pricedGlassParts = []; + +// //Act +// await wrapper.vm.forwardButtonAction(); + +// //Assert +// expect(navigateToHeritage.navigateToHeritageFunnel).toHaveBeenCalled(); +// }); +// test("should pass arePagePrerequisitesValid with a repair order", () => { +// //Arrange +// const { wrapper } = setupMocks({}); +// store.getters = { +// order: { +// serviceLocation: { +// zipCode: "12345", +// zipCodeCtu: "value", +// }, +// damage: { +// isRepair: true, +// }, +// referralNumber: "1234567", +// }, +// payment: { +// insuranceCoverage: { +// isVerified: false, +// }, +// }, +// }; + +// let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + +// expect(arePagePrerequisitesValid).toBe(true); +// }); +// test("should pass arePagePrerequisitesValid with a replace order", () => { +// //Arrange +// const { wrapper } = setupMocks({}); +// store.getters = { +// order: { +// serviceLocation: { +// zipCode: "12345", +// zipCodeCtu: "value", +// }, +// damage: { +// isRepair: false, +// }, +// referralNumber: "1234567", +// lineItems: { +// glassParts: ["item", "item2"], +// }, +// }, +// payment: { +// insuranceCoverage: { +// isVerified: false, +// }, +// }, +// }; + +// let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + +// expect(arePagePrerequisitesValid).toBe(true); +// }); +// test("should fail arePagePrerequisitesValid without glass parts or flagged as repair", () => { +// //Arrange +// const { wrapper } = setupMocks({}); +// store.getters = { +// order: { +// serviceLocation: { +// zipCode: "12345", +// zipCodeCtu: "value", +// }, +// damage: { +// isRepair: false, +// }, +// referralNumber: "1234567", +// }, +// }; + +// let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); + +// expect(arePagePrerequisitesValid).toBe(false); +// }); +// test("should have non-null values for necessary data members after 'beforeRouteEnter'", async () => { +// //Arrange +// const { wrapper } = setupMocks({}); + +// store.getters = { +// order: { +// lineItems: { +// glassParts: ["item", "item2"], +// }, +// }, +// }; + +// //mock this to avoid needing to populate this.$route in an unrelated test +// wrapper.vm.getDefaultIsInsuranceSelectedValue = jest.fn(); + +// //Act +// await quote.beforeRouteEnter.call( +// wrapper.vm, +// { query: { fmgPage: "quote" } }, +// undefined, +// (c) => c(wrapper.vm) +// ); + +// //Assert +// expect(wrapper.vm.pricedGlassParts !== null).toBe(true); +// expect(wrapper.vm.supportingItems !== null).toBe(true); +// expect(wrapper.vm.availableLineItems !== null).toBe(true); +// // This should have its own test +// //expect(vm.isInsuranceSelected !== null).toBe(true); +// }); +// test("should default to insurance if query param 'isInsurance' is true", async () => { +// //Arrange +// const { wrapper } = setupMocks({}); + +// store.getters = { +// order: { +// lineItems: { +// glassParts: ["item", "item2"], +// }, +// payment: { +// isInsurance: null, +// }, +// }, +// }; +// wrapper.vm.$route = { query: { isInsurance: "true" } }; + +// //Act +// await quote.beforeRouteEnter.call( +// wrapper.vm, +// { query: { fmgPage: "quote" } }, +// undefined, +// (c) => c(wrapper.vm) +// ); + +// //Assert +// expect(wrapper.vm.isInsuranceSelected).toBe(true); +// }); +// test("should default to cash if query param 'isInsurance' is false", async () => { +// //Arrange +// const { wrapper } = setupMocks({}); + +// store.getters = { +// order: { +// lineItems: { +// glassParts: ["item", "item2"], +// }, +// payment: { +// isInsurance: null, +// }, +// }, +// }; +// wrapper.vm.$route = { query: { isInsurance: "false" } }; + +// //Act +// await quote.beforeRouteEnter.call( +// wrapper.vm, +// { query: { fmgPage: "quote" } }, +// undefined, +// (c) => c(wrapper.vm) +// ); + +// //Assert +// expect(wrapper.vm.isInsuranceSelected).toBe(false); +// }); +// test("should default to insurance if insurance selection is saved to store", async () => { +// //Arrange +// const { wrapper } = setupMocks({}); + +// store.getters = { +// order: { +// lineItems: { +// glassParts: ["item", "item2"], +// }, +// payment: { +// isInsurance: true, +// }, +// }, +// }; +// // Ensure that query param isn't overriding selection +// wrapper.vm.$route = { query: null }; + +// //Act +// await quote.beforeRouteEnter.call( +// wrapper.vm, +// { query: { fmgPage: "quote" } }, +// undefined, +// (c) => c(wrapper.vm) +// ); + +// //Assert +// expect(wrapper.vm.isInsuranceSelected).toBe(true); +// }); +// test("should default to cash if cash selection is saved to store", async () => { +// //Arrange +// const { wrapper } = setupMocks({}); + +// store.getters = { +// order: { +// lineItems: { +// glassParts: ["item", "item2"], +// }, +// payment: { +// isInsurance: false, +// }, +// }, +// }; +// // Ensure that query param isn't overriding selection +// wrapper.vm.$route = { query: null }; + +// //Act +// await quote.beforeRouteEnter.call( +// wrapper.vm, +// { query: { fmgPage: "quote" } }, +// undefined, +// (c) => c(wrapper.vm) +// ); + +// //Assert +// expect(wrapper.vm.isInsuranceSelected).toBe(false); +// }); +// test("should default to cash if total economy package price is under $500", async () => { +// // Also needs no query parameter or previous selection in store to be present +// //Arrange +// const { wrapper } = setupMocks({}); + +// store.getters = { +// order: { +// lineItems: { +// glassParts: ["item", "item2"], +// }, +// payment: { +// isInsurance: null, // Ensure that previous selection isn't overriding selection +// }, +// }, +// }; +// mockTierOnePrice = 200; +// // Ensure that query param isn't overriding selection +// wrapper.vm.$route = { query: null }; + +// //Act +// await quote.beforeRouteEnter.call( +// wrapper.vm, +// { query: { fmgPage: "quote" } }, +// undefined, +// (c) => c(wrapper.vm) +// ); + +// //Assert +// expect(wrapper.vm.isInsuranceSelected).toBe(false); +// }); +// test("should default to insurance if total economy package price is over $500", async () => { +// // Also needs no query parameter or previous selection in store to be present +// //Arrange +// const { wrapper } = setupMocks({}); + +// store.getters = { +// order: { +// lineItems: { +// glassParts: ["item", "item2"], +// }, +// payment: { +// isInsurance: null, // Ensure that previous selection isn't overriding selection +// }, +// }, +// }; +// mockTierOnePrice = 505; +// // Ensure that query param isn't overriding selection +// wrapper.vm.$route = { query: null }; + +// //Act +// await quote.beforeRouteEnter.call( +// wrapper.vm, +// { query: { fmgPage: "quote" } }, +// undefined, +// (c) => c(wrapper.vm) +// ); + +// //Assert +// expect(wrapper.vm.isInsuranceSelected).toBe(true); +// }); +// }); + +function setupMocks({ customMountOptions }) { + const mountOptions = getMountOptions({ + ...customMountOptions, + }); + mountOptions.global.mocks["$store"] = store; + mountOptions["attachTo"] = document.body; + mountOptions.mixins = [{ + methods: { + getCmsContent: jest.fn() + } + }]; + + + const questionText = "Question Text"; + + const wrapper = shallowMount(timeSlotModalQuestion, mountOptions); + wrapper.vm.setCmsContent = jest.fn(); + return { wrapper }; +} diff --git a/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.vue b/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.vue index 13f33ae05..724facf6c 100644 --- a/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.vue +++ b/src/layouts/schedule/time-slot-modal-question/time-slot-modal-question.vue @@ -150,7 +150,7 @@ export default { return this.modelValue?.routeCode; }, set: function (newValue) { - // Button Question only supports Number, or String data types so we must get the full object to emit + // Button Question only supports Number, or String data types so we must convert to the full object before emitting this.selectedValue = this.getSelectedTimeSlotObject(newValue); }, }, @@ -326,7 +326,7 @@ export default { } }, modal() { - return this.$refs["timeSlots"]; + return this.$refs[this.modalName]; }, }, methods: { From 5c70ff81fd1c3ce77f0ed073f1dcd72b98b97df8 Mon Sep 17 00:00:00 2001 From: Sneha Date: Thu, 27 Jul 2023 15:35:00 +0530 Subject: [PATCH 02/11] 1418 --- .../vehicle-question/vehicle-question.vue | 14 +++++--- src/layouts/vehicle/vehicle.vue | 33 +++++++++++-------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/layouts/vehicle/vehicle-question/vehicle-question.vue b/src/layouts/vehicle/vehicle-question/vehicle-question.vue index 283f26811..9f5fc52a9 100644 --- a/src/layouts/vehicle/vehicle-question/vehicle-question.vue +++ b/src/layouts/vehicle/vehicle-question/vehicle-question.vue @@ -8,6 +8,8 @@ + + diff --git a/src/layouts/vehicle/vehicle-question/vehicle-question.vue b/src/layouts/vehicle/vehicle-question/vehicle-question.vue index 9f5fc52a9..f2863564d 100644 --- a/src/layouts/vehicle/vehicle-question/vehicle-question.vue +++ b/src/layouts/vehicle/vehicle-question/vehicle-question.vue @@ -1,67 +1,29 @@ - - diff --git a/src/layouts/vehicle/vehicle-question/vehicle-question.vue b/src/layouts/vehicle/vehicle-question/vehicle-question.vue index f2863564d..79b58bfaa 100644 --- a/src/layouts/vehicle/vehicle-question/vehicle-question.vue +++ b/src/layouts/vehicle/vehicle-question/vehicle-question.vue @@ -1,9 +1,9 @@