From 6491b940443d66878fc71a0dc7237fd997d6db38 Mon Sep 17 00:00:00 2001 From: CarlNation Date: Tue, 13 Sep 2022 08:02:05 -0400 Subject: [PATCH] CSR-779 Repair view of estimate page --- .../heritage-integration/navigation-helper.js | 2 +- src/layouts/estimate/estimate.spec.js | 14 ++ src/layouts/estimate/estimate.vue | 141 ++++++++++++++++-- src/layouts/vin-lookup/vin-lookup.spec.js | 5 +- src/layouts/vin-lookup/vin-lookup.vue | 20 +-- src/mixins/base-mixin.js | 19 +++ src/mixins/base-mixin.spec.js | 19 +++ 7 files changed, 188 insertions(+), 32 deletions(-) diff --git a/src/helpers/heritage-integration/navigation-helper.js b/src/helpers/heritage-integration/navigation-helper.js index 6079c5375..0630d8b65 100644 --- a/src/helpers/heritage-integration/navigation-helper.js +++ b/src/helpers/heritage-integration/navigation-helper.js @@ -95,7 +95,7 @@ async function getLatestPageForRedirection() { else if (partQuestionsComponent.methods.arePagePrerequisitesValid()) { return fmgPageValues.PART_QUESTIONS; } - else if (vinLookupComponent.methods.arePagePrerequisitesValid()) { + else if (vinLookupComponent.methods.arePagePrerequisitesValid() && !store.getters.damage.isRepair) { return fmgPageValues.VIN_LOOKUP; } else { diff --git a/src/layouts/estimate/estimate.spec.js b/src/layouts/estimate/estimate.spec.js index a24bc22b7..1843670ec 100644 --- a/src/layouts/estimate/estimate.spec.js +++ b/src/layouts/estimate/estimate.spec.js @@ -146,6 +146,20 @@ describe("estimate.vue", () => { }); + test("Changing zip should reset alert", async () => { + //Arrange + const { wrapper } = setupMocks({}); + + //Act + wrapper.vm.displayNonServiceableZipAlert = "true"; + wrapper.vm.serviceZipCode = "43015"; + + await wrapper.vm.$nextTick(); + + //Assert + expect(wrapper.vm.displayNonServiceableZipAlert).toEqual(false); + }); + }); function setupMocks({ diff --git a/src/layouts/estimate/estimate.vue b/src/layouts/estimate/estimate.vue index aae192291..cfd904da1 100644 --- a/src/layouts/estimate/estimate.vue +++ b/src/layouts/estimate/estimate.vue @@ -6,26 +6,78 @@ v-slot="{ meta }" >
+
- - +
+ + +
+
+ +
+
+ +
+
+
+
+ +
+
+ + +
0; }, @@ -90,6 +159,31 @@ export default { ); }, async forwardButtonAction() { + if (this.isRepair){ + const zipCodeData = await this.getZipCodeData(this.serviceZipCode); + //todo: validation + await this.dispatchStoreAction(storeActions.SAVE_EMAIL, this.emailAddress, false); + await this.dispatchStoreAction(storeActions.SAVE_SERVICE_LOCATION, { + zipCode: this.serviceZipCode, + state: zipCodeData.state, + }, false); + + if (!zipCodeData.isZipValid) { + this.displayInvalidZipAlert = true; + return this.$refs.funnelFooter.removeLoader(); + } + this.displayInvalidZipAlert = false; + + if (!zipCodeData.isZipServiceable) { + this.displayNonServiceableZipAlert = true; + return this.$refs.funnelFooter.removeLoader(); + } + this.displayNonServiceableZipAlert = false; + + this.$refs.loadingModal.showModal(); + navigateToHeritageFunnel(); + } + if (this.selectedVinLookupMethod === vinLookupMethodSelections.MANUALVIN) { await this.dispatchStoreAction(storeActions.CLEAR_VIN); return this.$router.navigateWithSaving( @@ -112,13 +206,28 @@ export default { }, }, computed: { + AlertNonServiceableZipHeader(){ + console.log(this.getCmsContent("AlertNonServiceableZipWidget", "HeadlineText")); + return this.getCmsContent("AlertNonServiceableZipWidget", "HeadlineText").replaceAll("{custom:serviceZip}", this.serviceZipCode); + }, + AlertNonServiceableZipBody(){ + return this.getCmsContent("AlertNonServiceableZipWidget", "BodyText"); + }, questionText() { return this.getCmsContent("VinLookupMethod", "QuestionText"); }, answersFromCms() { return this.getCmsContent("VinLookupMethod", "Answers"); }, + isRepair() { + return store.getters.damage.isRepair; + }, }, + watch: { + serviceZipCode() { + this.displayNonServiceableZipAlert = false; + }, + }, components: { funnelHeader, vehicleBanner, @@ -127,6 +236,8 @@ export default { buttonQuestion, Form, alert, + textboxQuestion, + loadingModal, }, }; diff --git a/src/layouts/vin-lookup/vin-lookup.spec.js b/src/layouts/vin-lookup/vin-lookup.spec.js index 60188bae8..d0d20a531 100644 --- a/src/layouts/vin-lookup/vin-lookup.spec.js +++ b/src/layouts/vin-lookup/vin-lookup.spec.js @@ -224,10 +224,6 @@ function setupMocks({ customMountOptions }) { function mockOutPromises(carId = 'C00000') { const apiResponses = { - serviceZipValidationResponse: { - isValid: true, - isServiceable: true - }, vehicleLookupResponse: { carId: carId } @@ -239,6 +235,7 @@ function mockOutPromises(carId = 'C00000') { function mockOutStubFunctions(wrapper) { wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn(); + wrapper.vm.getZipCodeData = jest.fn().mockReturnValue({ isValid: true, isServiceable: true, state: "OH" }); } const mockMixin = { diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 21d06ff56..4f2748a5e 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -221,15 +221,10 @@ export default { async forwardButtonAction() { // If this is a new VIN Lookup, do both a Vehicle Lookup and a Zip Validation if (!this.vinPopulatedOnPageLoad) { - const serviceZipValidationResponse = this.dispatchStoreAction(storeActions.VALIDATE_ZIP, { zip: this.serviceZipCode }); const vehicleLookupResponse = this.dispatchStoreAction(storeActions.LOOKUP_VEHICLE_BY_VIN, { vin: this.vin }); // Settle promises and get results const promiseResultMap = [ - { - resultKey: "serviceZipValidationResponse", - promise: serviceZipValidationResponse, - }, { resultKey: "vehicleLookupResponse", promise: vehicleLookupResponse, @@ -237,9 +232,10 @@ export default { ]; const resultMap = await settleAllPromises(promiseResultMap); + const zipCodeData = await this.getZipCodeData(this.serviceZipCode); // If a Service Zip is entered and it is an invalid zip code (ex. 11111) then show an alert - const isZipValid = resultMap.serviceZipValidationResponse.isValid; + const isZipValid = zipCodeData.isValid; if (this.serviceZipCode && !isZipValid) { this.displayInvalidZipAlert = true; return this.$refs.funnelFooter.removeLoader(); @@ -247,14 +243,14 @@ export default { this.displayInvalidZipAlert = false; // If either lookup fails, remove the loader and stop processing the page. - if (!resultMap.vehicleLookupResponse || !resultMap.serviceZipValidationResponse.isServiceable) { + if (!resultMap.vehicleLookupResponse || !zipCodeData.isServiceable) { // If the vehicle result is undefined, the vin entered was invalid. if(!resultMap.vehicleLookupResponse) { this.displayVinNotFoundAlert = true; } // Check if Service Zip entered is serviceable, if not display an alert - if (!resultMap.serviceZipValidationResponse.isServiceable) { + if (!zipCodeData.isServiceable) { this.displayNonServiceableZipAlert = true; } @@ -288,7 +284,7 @@ export default { await this.dispatchStoreAction(storeActions.SAVE_EMAIL, this.emailAddress, false); await this.dispatchStoreAction(storeActions.SAVE_SERVICE_LOCATION, { zipCode: this.serviceZipCode, - state: resultMap.serviceZipValidationResponse.state, + state: zipCodeData.state, }, false); return await this.navigateForward(); @@ -296,10 +292,10 @@ export default { } // If a VIN has already been found. Validate the Service Zip (in case of changes) - const zipValidationResponse = await this.dispatchStoreAction(storeActions.VALIDATE_ZIP, {zip: this.serviceZipCode}); + const zipCodeData = await this.getZipCodeData(this.serviceZipCode); // Check if Service Zip entered is serviceable - if (zipValidationResponse.data.isServiceable) { + if (zipCodeData.isServiceable) { // If the Service Zip entered is serviceable then save the Zip Info and Email Address and navigate forward if (this.$store.getters.order.serviceLocation.zipCode != this.serviceZipCode) { const vehicleRegistrationInfo = this.$store.getters.vehicle.registration; @@ -314,7 +310,7 @@ export default { else { await this.dispatchStoreAction(storeActions.SAVE_SERVICE_LOCATION, { zipCode: this.serviceZipCode, - state: zipValidationResponse.data.state + state: zipCodeData.state }, false); } } diff --git a/src/mixins/base-mixin.js b/src/mixins/base-mixin.js index 5a82145c0..b19b458da 100644 --- a/src/mixins/base-mixin.js +++ b/src/mixins/base-mixin.js @@ -6,6 +6,7 @@ import { vehicleCategories } from "@/constants/vehicle-categories.js"; import { routerParams } from "@/router/router-constants/router-params"; import { queryStrings } from "@/constants/query-strings"; import { dynamicStrings } from "@/constants/dynamic-strings"; +import { settleAllPromises } from "@/helpers/layout-helper"; export default { data() { @@ -47,6 +48,24 @@ export default { const footerInfoBox = document.querySelector(".footer#infoBox"); return footerInfoBox ? footerInfoBox.offsetHeight : 0; }, + async getZipCodeData(zipCode) { + const serviceZipValidationResponse = this.dispatchStoreAction(storeActions.VALIDATE_ZIP, { zip: zipCode }); + + const promiseResultMap = [ + { + resultKey: "serviceZipValidationResponse", + promise: serviceZipValidationResponse, + } + ]; + + const resultMap = await settleAllPromises(promiseResultMap); + + return { + isZipValid: resultMap.serviceZipValidationResponse.isValid, + isZipServiceable: resultMap.serviceZipValidationResponse.isServiceable, + state: resultMap.serviceZipValidationResponse.state + }; + } }, computed: { storeActions() { diff --git a/src/mixins/base-mixin.spec.js b/src/mixins/base-mixin.spec.js index b0c8b26f3..9c7ebcd90 100644 --- a/src/mixins/base-mixin.spec.js +++ b/src/mixins/base-mixin.spec.js @@ -95,6 +95,25 @@ describe("baseMixin.js", () => { // Assert expect(global.document.querySelector).toBeCalledWith("[data-focus-target='fieldOne']"); }); + + test("getZipCodeData calls dispatch", () => { + const mixIn = getMixInInstance({}); + mixIn.methods.dispatchStoreAction = jest.fn(); + mixIn.methods.dispatchStoreAction.mockReturnValue({ isValid:true, isServiceable:true, state:"OH" }); + const type = ""; + const payload = { zip: 43015 }; + + const mockData = { + actionList: [{ + actionName: storeActions.VALIDATE_ZIP + }], + } + + mixIn.methods.getZipCodeData(type, payload); + + expect(mixIn.methods.dispatchStoreAction).toBeCalled(); + }); + }); function getMixInInstance({ isDispatchSuccess = true }) {