From 668a8affb2376075f88674a57a34a49b32aff2d0 Mon Sep 17 00:00:00 2001 From: Katie Date: Thu, 18 Aug 2022 12:09:46 -0400 Subject: [PATCH 1/2] Revert "Merge pull request #673 from Safelite/revert-672-feature/CSR-111-parts" This reverts commit c5f76d24249596eacf0a3cf57ddd54172d2938cf, reversing changes made to 2e0f614e1f7fedb56e6b4e9771e76a1f8125ad1c. --- src/constants/endpoints.js | 8 + src/constants/store-actions.js | 3 + src/constants/store-mutations.js | 1 + .../capability-questions.vue | 92 +- src/layouts/part-questions/part-questions.vue | 34 +- .../vehicle-parts/vehicle-parts.spec.js | 15 +- src/layouts/vehicle-parts/vehicle-parts.vue | 45 +- src/mixins/vehicle-questions-mixin.js | 109 +- src/mixins/vehicle-questions-mixin.spec.js | 991 +++++++++++++++++- src/mixins/vin-pages-mixin.js | 32 +- src/mixins/vin-pages-mixin.spec.js | 972 +---------------- .../router-constants/navigation-scenarios.js | 15 +- src/router/router-constants/routing-table.js | 92 +- src/store/index.js | 42 +- 14 files changed, 1298 insertions(+), 1153 deletions(-) diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 8d5b33bec..9cf0b6856 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -59,6 +59,14 @@ const endpoints = { url: "/parts/api/v1/parts/parts", method: "POST", }, + GetCapabilityQuestions: { + url: "/parts/api/v1/parts/capability-questions", + method: "GET" + }, + ApplyCapabilityAnswerToPart: { + url: "/parts/api/v1/parts/apply-capability-answer-to-part", + method: "POST" + }, SaveOrder: { url: "/order/api/v1/order/save", method: "POST", diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 9f8ad36f6..a80694834 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -21,6 +21,8 @@ const storeActions = { GET_PARTS_OR_QUESTIONS: "getPartsOrQuestions", GET_PARTS: "getParts", + GET_CAPABILITY_QUESTIONS: "getCapabilityQuestions", + GET_PART_FROM_CAPABILITY_QUESTION_ANSWER: "getPartFromCapabilityQuestionAnswer", SAVE_ORDER: "saveOrder", LOAD_ORDER: "loadOrder", UPDATE_STORE_WITH_SAVE_ORDER_RESPONSE: "updateStoreWithSaveOrderResponse", @@ -55,6 +57,7 @@ const storeActions = { SAVE_REGISTRATION_ADDRESS_LOOKUP: "saveRegistrationAddressLookup", SAVE_GLASS_PARTS: "saveGlassParts", SAVE_PART_QUESTION_ANSWERS: "savePartQuestionAnswers", + SAVE_CAPABILITY_QUESTION_ANSWERS: "saveCapabilityQuestionAnswers" }; export { storeActions }; diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index cce109c43..ba0adc7cb 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -17,6 +17,7 @@ const storeMutations = { UPDATE_NUMBER_OF_CHIPS: "updateNumberOfChips", UPDATE_GLASS_TO_REPLACE: "updateGlassToReplace", UPDATE_PART_QUESTION_ANSWERS: "updatePartQuestionAnswers", + UPDATE_CAPABILITY_QUESTION_ANSWERS: "updateCapabilityQuestionAnswers", UPDATE_GLASS_PARTS: "updateGlassParts", UPDATE_OTHER_PARTS: "updateOtherParts", diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index a29aa3779..ea51194e8 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -11,7 +11,6 @@
-

CAPABILITY QUESTIONS TEMPORARY PLACEHOLDER

-
- -
+ { - if (Array.isArray(p.partQuestions) && p.partQuestions.length > 0) { - return { - glassName: p.glassName, - glassLocation: p.glassLocation, - partQuestions: p.partQuestions, - }; - } - }), - currentPartNum: 0, + selectedAnswer: [], + // TODO This shouldn't be an object with property `partQuestions` + capabilityQuestionsData: { + partQuestions: store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS).capabilityQuestions + } }; }, computed: { AlertFewMoreQuestionsHeader() { - return this.getCmsContent("AlertPartsQuestions", "HeadlineText"); + return this.getCmsContent("AdditionalPartsQuestionsAlert", "HeadlineText"); }, AlertFewMoreQuestionsCopy() { - return this.getCmsContent("AlertPartsQuestions", "BodyText"); + return this.getCmsContent("AdditionalPartsQuestionsAlert", "BodyText"); }, + windshieldPart() { + return this.pageData.partsOrQuestions.find(x => x.glassLocation === damageLocationsSelected.WINDSHIELD); + }, + windshieldPartInfo() { + return this.windshieldPart.parts[0]; + }, + pageData() { + return this.$store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS); + } }, methods: { arePagePrerequisitesValid() { - return false; // TODO - DO TRUE TEST OF PAGEDATA - // return Object.keys(store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS)).length > 0; - }, - showThisPartQuestionChain(part, i) { - if (part.partQuestions?.length < 1) { return false; } // return false if only one partQuestion - if (this.currentPartNum === i || part.answerData?.answerResult.length > 0) { return true; } - return false; - }, - backButtonAction() { - // route to move backwards - this.$router.navigate( - this.navigationScenarios.CLICKED_BACK, - this.$route - ); + const capabilityQuestionsPageData = store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS); + return capabilityQuestionsPageData && Object.keys(capabilityQuestionsPageData).length > 0; }, async forwardButtonAction() { - // TODO: TO COME - }, - }, - watch: { - selectedModel(model) { - this.capabilityQuestionsData[model.partIndex].answerData = { - answerResult: model.answerResult, - answeredQuestions: model.answeredQuestions, - } - this.currentPartNum = model.partIndex + 1; + const selectedAnswerResult1 = this.selectedAnswer.answerResult; + const selectedAnswerResult2 = this.pageData.capabilityQuestions[0].answers.find(x => x.answerResult1 === selectedAnswerResult1).answerResult2; + + this.dispatchStoreAction(storeActions.SAVE_CAPABILITY_QUESTION_ANSWERS, { + glassName: this.windshieldPart.glassName, + glassLocation: this.windshieldPart.glassLocation, + result1: selectedAnswerResult1, + result2: selectedAnswerResult2 + }); + + const partFromCapabilityQuestionAnswer = (await this.dispatchStoreAction(storeActions.GET_PART_FROM_CAPABILITY_QUESTION_ANSWER)).data; + let partsOrQuestions = this.pageData.partsOrQuestions; + partsOrQuestions.find(partOrQuestion => partOrQuestion.glassLocation === damageLocationsSelected.WINDSHIELD).parts = partFromCapabilityQuestionAnswer; + + this.navigateForward(partsOrQuestions); }, }, components: { diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index 1f8160adf..7aca0e77f 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -123,13 +123,6 @@ export default { if (this.currentPartNum === i || part.answerData?.answerResult?.length > 0) { return true; } return false; }, - backButtonAction() { - // route to move backwards - this.$router.navigate( - this.navigationScenarios.CLICKED_BACK, - this.$route - ); - }, async forwardButtonAction() { const partQuestionAnswersArray = this.partsQuestionsData.map((item) => { return { @@ -155,32 +148,7 @@ export default { }); const glassNameAndPartsForStore = partsLookup.data.glassNameAndParts; - const hasGlassLocationWithMultipleParts = this.hasGlassLocationWithMultipleParts(glassNameAndPartsForStore); - const hasChildPartQuestions = this.hasChildPartQuestions(glassNameAndPartsForStore); - const hasCapabilityQuestions = this.hasCapabilityQuestions(glassNameAndPartsForStore); - - // NAVIGATE FORWARD - if (hasGlassLocationWithMultipleParts) { - // if multiple parts on any glass - // go to vehicle-parts page and pass the partsData - this.$router.navigate(this.navigationScenarios.ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); - } else if (hasChildPartQuestions) { - // if any childpart questions - // go to molding-questions page and pass the partsData - this.$router.navigate(this.navigationScenarios.HAS_MOLDING_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); - } else if (hasCapabilityQuestions) { - // if has capability questions - // go to capability-questions page and pass the partsData - this.$router.navigate(this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); - } else { - // if single parts only - const collectedGlassParts = this.reducedGlassPartsArray(glassNameAndPartsForStore); - // save to store lineItems.glassParts - this.$store.commit(storeMutations.UPDATE_GLASS_PARTS, collectedGlassParts); - // go to heritage quote page - this.$refs.loadingModal.showModal(); - navigateToHeritageFunnel(); - } + this.navigateForward(glassNameAndPartsForStore); }, arePagePrerequisitesValid() { const partQuestionsFromPageData = store.getters.pageData(fmgPageValues.PART_QUESTIONS); diff --git a/src/layouts/vehicle-parts/vehicle-parts.spec.js b/src/layouts/vehicle-parts/vehicle-parts.spec.js index bd7911da4..2e9110d7a 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.spec.js +++ b/src/layouts/vehicle-parts/vehicle-parts.spec.js @@ -9,6 +9,7 @@ import { shallowMount } from "@vue/test-utils"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { nextTick } from "vue"; import baseMixin from "@/mixins/base-mixin.js"; +import { storeActions } from "@/constants/store-actions"; import store from "@/store"; import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; @@ -227,7 +228,7 @@ describe("vehicle-parts.vue", () => { wrapper.vm.backButtonAction(); //Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_WITH_PART_QUESTION_ANSWERS, wrapper.vm.$route); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_TO_GO_TO_PART_QUESTIONS, wrapper.vm.$route); }); @@ -266,7 +267,7 @@ describe("vehicle-parts.vue", () => { wrapper.vm.backButtonAction(); //Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS, wrapper.vm.$route); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_TO_GO_TO_VIN_LOOKUP, wrapper.vm.$route); }); @@ -311,6 +312,7 @@ describe("vehicle-parts.vue", () => { } ] }); + store.getters.lineItems = { glassParts: {} } const { wrapper } = setupMocks({ mountOptionsMockData: { @@ -367,6 +369,8 @@ describe("vehicle-parts.vue", () => { } ] }); + store.getters.lineItems = { glassParts: {} } + store.getters.vehicle = { carId: "TEST_CAR_ID" } const { wrapper } = setupMocks({ mountOptionsMockData: { @@ -382,6 +386,12 @@ describe("vehicle-parts.vue", () => { getters: store.getters, commit: store.commit }, + actionList: [ + { + actionName: storeActions.GET_CAPABILITY_QUESTIONS, + data: [] + } + ] } }); @@ -406,6 +416,7 @@ describe("vehicle-parts.vue", () => { //Arrange store.getters.pageData.mockReturnValueOnce(basePartResponse); store.getters.lineItems = { glassParts: {} } + store.getters.vehicle = { carId: "TEST_CAR_ID" } const { wrapper } = setupMocks({ mountOptionsMockData: { diff --git a/src/layouts/vehicle-parts/vehicle-parts.vue b/src/layouts/vehicle-parts/vehicle-parts.vue index c7f1424a1..a276ef132 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.vue +++ b/src/layouts/vehicle-parts/vehicle-parts.vue @@ -132,8 +132,8 @@ export default { ColorAnswerText: p.color, FeatureAnswers: [ { - FeatureAnswerText: p.description === "" ? p.color : p.description, - PartNumber: p.partNumber, + FeatureAnswerText: p.description === "" ? p.color : p.description, + PartNumber: p.partNumber, }, ], }); @@ -159,15 +159,6 @@ export default { return store.getters.damage.isRepair != null && store.getters.pageData(fmgPageValues.VEHICLE_PARTS) && Object.keys(store.getters.pageData(fmgPageValues.VEHICLE_PARTS)).length !== 0; }, - backButtonAction() { - const hasPartQuestions = this.hasPartQuestions(this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions); - const backNavigationScenario = hasPartQuestions ? this.navigationScenarios.CLICKED_BACK_WITH_PART_QUESTION_ANSWERS : this.navigationScenarios.CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS; - - this.$router.navigate( - backNavigationScenario, - this.$route - ); - }, async forwardButtonAction() { const matchedParts = []; @@ -191,10 +182,6 @@ export default { } } } - - const hasChildPartQuestions = this.hasChildPartQuestions(matchedParts); - const hasCapabilityQuestions = this.hasCapabilityQuestions(matchedParts); - // If no parts could be matched, throw an error (isForwardActionDisabled is based off of matchedParts) if (this.isForwardActionDisabled) { this.$refs.funnelFooter.removeLoader(); @@ -202,33 +189,7 @@ export default { } // Navigate to the next page - if (hasChildPartQuestions) { - this.$router.navigate( - this.navigationScenarios.HAS_MOLDING_QUESTIONS, - this.$route, - {}, - {}, - {partsOrQuestions: matchedParts} - ); - } else if (hasCapabilityQuestions) { - this.$router.navigate( - this.navigationScenarios.HAS_CAPABILITY_QUESTIONS, - this.$route, - {}, - {}, - {partsOrQuestions: matchedParts} - ); - - } else { - // if single parts only - const collectedGlassParts = this.reducedGlassPartsArray(matchedParts); - // save to store lineItems.glassParts - this.$store.commit(storeMutations.UPDATE_GLASS_PARTS, collectedGlassParts); - - // go to heritage quote page - this.$refs.loadingModal.showModal(); - navigateToHeritageFunnel(); - } + this.navigateForward(matchedParts); }, LoadInitialPartsData() { diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index 1a28fe028..a55859567 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -1,5 +1,13 @@ -export default { +import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; +import { storeMutations } from "@/constants/store-mutations.js"; +import { damageLocationsSelected } from "@/constants/damage-locations-selected"; +import { navigationScenarios } from "../router/router-constants/navigation-scenarios"; +import { storeActions } from "@/constants/store-actions"; +import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import baseMixin from "@/mixins/base-mixin.js"; +import store from "@/store"; +export default { methods: { hasPartQuestions(partsOrQuestions) { return partsOrQuestions?.some(pq => pq.partQuestions?.length > 0); @@ -17,6 +25,7 @@ export default { return pq.parts?.some(part => part.requiresCapabilityQuestions === true); }); }, + // method to only include keys listed for lineItems.glassParts in // https://safelite.atlassian.net/wiki/spaces/DC/pages/17137665/Catalog+Front-End+State#glassParts reducedGlassPartsArray(glassParts) { @@ -37,7 +46,103 @@ export default { } }); return reducedGlassParts; + }, + comparePageIndices(currentPage, fmgPage) { + const orderedVehicleQuestionPages = [ + fmgPageValues.PART_QUESTIONS, + fmgPageValues.VEHICLE_PARTS, + fmgPageValues.MOLDING_QUESTIONS, + fmgPageValues.CAPABILITY_QUESTIONS, + fmgPageValues.QUOTE + ] + + return orderedVehicleQuestionPages.indexOf(currentPage) - orderedVehicleQuestionPages.indexOf(fmgPage); + }, + currentPageComesBeforePage(currentPage = this.$route.query.fmgPage, fmgPage) { + return this.comparePageIndices(currentPage, fmgPage) < 0; + }, + currentPageComesAfterPage(currentPage = this.$route.query.fmgPage, fmgPage) { + return this.comparePageIndices(currentPage, fmgPage) > 0; + }, + // Can't use `this` because navigateForward is also called from vin-pages-mixin + async navigateForward(partsOrQuestions, vm) { + const self = vm ?? this; + const currentPage = self.$route.query.fmgPage; + + const hasPartQuestions = this.hasPartQuestions(partsOrQuestions) + const hasGlassLocationWithMultipleParts = this.hasGlassLocationWithMultipleParts(partsOrQuestions); + const hasChildPartQuestions = this.hasChildPartQuestions(partsOrQuestions); + const hasCapabilityQuestions = this.hasCapabilityQuestions(partsOrQuestions); + + if (hasPartQuestions && this.currentPageComesBeforePage(currentPage, fmgPageValues.PART_QUESTIONS)) { + self.$router.navigate(self.navigationScenarios.HAS_PART_QUESTIONS, self.$route, {}, {}, {partsOrQuestions: partsOrQuestions}); + } + else if (hasGlassLocationWithMultipleParts && this.currentPageComesBeforePage(currentPage, fmgPageValues.VEHICLE_PARTS)) { + // if multiple parts on any glass + // go to vehicle-parts page and pass the partsData + self.$router.navigate(self.navigationScenarios.HAS_MULTIPLE_PARTS_TO_CHOOSE,self.$route,{},{},{partsOrQuestions: partsOrQuestions}); + } else if (hasChildPartQuestions && this.currentPageComesBeforePage(currentPage, fmgPageValues.MOLDING_QUESTIONS)) { + // if any childpart questions + // go to molding-questions page and pass the partsData + self.$router.navigate(self.navigationScenarios.HAS_MOLDING_QUESTIONS,self.$route,{},{},{partsOrQuestions: partsOrQuestions}); + } else if (hasCapabilityQuestions && this.currentPageComesBeforePage(currentPage, fmgPageValues.CAPABILITY_QUESTIONS)) { + // if has capability questions + // go to capability-questions page and pass the partsData + const windshieldPart = partsOrQuestions.filter(x => x.glassLocation === damageLocationsSelected.WINDSHIELD)[0].parts[0]; + let capabilityQuestions = (await baseMixin.methods.dispatchStoreAction(storeActions.GET_CAPABILITY_QUESTIONS, { + carId: store.getters.vehicle.carId, + partNumber: windshieldPart.partNumber + })).data; + + capabilityQuestions.forEach(question => { + question.answers = question.answers.map(answer => { + return { + ...answer, + answerResult: answer.answerResult1 + } + }) + }); + + self.$router.navigate(self.navigationScenarios.HAS_CAPABILITY_QUESTIONS, self.$route, {}, {}, { partsOrQuestions, capabilityQuestions }); + } else { + // if single parts only + const collectedGlassParts = this.reducedGlassPartsArray(partsOrQuestions); + // save to store lineItems.glassParts + self.$store.commit(storeMutations.UPDATE_GLASS_PARTS, collectedGlassParts); + + this.$refs.loadingModal.showModal(); + navigateToHeritageFunnel(); + + // For quote pages MVP release + // self.$router.navigate(self.navigationScenarios.ANSWERED_ALL_QUESTIONS, self.$route); + } + }, + backButtonAction() { + const partsOrQuestions = this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions; + const hasPartQuestions = this.hasPartQuestions(partsOrQuestions); + const hasGlassLocationWithMultipleParts = this.hasGlassLocationWithMultipleParts(partsOrQuestions); + const hasChildPartQuestions = this.hasChildPartQuestions(partsOrQuestions); + const hasCapabilityQuestions = this.hasCapabilityQuestions(partsOrQuestions); + let backNavigationScenario = navigationScenarios.CLICKED_BACK_TO_GO_TO_VIN_LOOKUP; + + const currentPage = this.$route.query.fmgPage; + if (hasCapabilityQuestions && this.currentPageComesAfterPage(currentPage, fmgPageValues.CAPABILITY_QUESTIONS)) { + backNavigationScenario = navigationScenarios.CLICKED_BACK_TO_GO_TO_CAPABILITY_QUESTIONS; + } + else if (hasChildPartQuestions && this.currentPageComesAfterPage(currentPage, fmgPageValues.MOLDING_QUESTIONS)) { + backNavigationScenario = navigationScenarios.CLICKED_BACK_TO_GO_TO_MOLDING_QUESTIONS; + } + else if (hasGlassLocationWithMultipleParts && this.currentPageComesAfterPage(currentPage, fmgPageValues.VEHICLE_PARTS)) { + backNavigationScenario = navigationScenarios.CLICKED_BACK_TO_GO_TO_VEHICLE_PARTS; + } + else if (hasPartQuestions && this.currentPageComesAfterPage(currentPage, fmgPageValues.PART_QUESTIONS)) { + backNavigationScenario = navigationScenarios.CLICKED_BACK_TO_GO_TO_PART_QUESTIONS; + } + + this.$router.navigate( + backNavigationScenario, + this.$route + ); } } - } \ No newline at end of file diff --git a/src/mixins/vehicle-questions-mixin.spec.js b/src/mixins/vehicle-questions-mixin.spec.js index 01d41b9c8..13a2f083a 100644 --- a/src/mixins/vehicle-questions-mixin.spec.js +++ b/src/mixins/vehicle-questions-mixin.spec.js @@ -1,8 +1,22 @@ import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; import { shallowMount } from "@vue/test-utils"; import { setupMocksForJsFiles, getMountOptions } from "@/helpers/unit-test-helper.js"; +import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; +import { storeMutations } from "@/constants/store-mutations"; +import { storeActions } from "@/constants/store-actions"; +import loadingModal from '@/common-components/loading-modal/loading-modal.vue'; +import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import { navigationScenarios } from "../router/router-constants/navigation-scenarios"; + +jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({ + navigateToHeritageFunnel: jest.fn() +})); describe("vehicle-questions-mixin", () => { + afterEach(() => { + jest.clearAllMocks(); + }) + describe("hasPartQuestions", () => { test("has no part questions => return false", () => { // Arrange @@ -139,23 +153,994 @@ describe("vehicle-questions-mixin", () => { expect(hasGlassLocationWithMultipleParts).toBe(true); }); }); + + describe("navigateForward", () => { + describe("should go to parts-questions", () => { + test("single glass location has part question => go to parts-questions", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Single", + "glassLocation": "Windshield", + "parts": null, + "partQuestions": [ + { + "questionSequence": 1, + "questionText": "Is there a line running across the bottom, driver's side then up the center of the Windshield?", + "answers": [ + { + "answerText": "Yes", + "nextQuestionSequence": null, + "answerResult": "DW01144" + }, + { + "answerText": "No", + "nextQuestionSequence": null, + "answerResult": "DW01143" + } + ] + } + ] + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); + }); + + test("multiple glass locations have part questions => go to parts-questions", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Single", + "glassLocation": "Windshield", + "parts": null, + "partQuestions": [ + { + "questionSequence": 1, + "questionText": "Is there a line running across the bottom, driver's side then up the center of the Windshield?", + "answers": [ + { + "answerText": "Yes", + "nextQuestionSequence": null, + "answerResult": "DW01144" + }, + { + "answerText": "No", + "nextQuestionSequence": null, + "answerResult": "DW01143" + } + ] + } + ] + }, + { + "glassName": "Front", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DD08158GTYN", + "description": "driver side, front", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Quarter", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DQ08162GTYN", + "description": "driver side, 1 hole", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "SideDoor", + "glassLocation": "Driver", + "parts": null, + "partQuestions": [ + { + "questionSequence": 2, + "questionText": "Is this a super awesome question?", + "answers": [ + { + "answerText": "Yes", + "nextQuestionSequence": null, + "answerResult": "DW01144000" + }, + { + "answerText": "Super yes", + "nextQuestionSequence": null, + "answerResult": "DW01143001" + } + ] + } + ] + }, + { + "glassName": "Stationary", + "glassLocation": "Rear", + "parts": [ + { + "partNumber": "DB08165GTNN", + "description": "heated glass, stationary", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); + }); + + test("multiple glass locations selected, one has part question => go to parts-questions", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Single", + "glassLocation": "Windshield", + "parts": null, + "partQuestions": [ + { + "questionSequence": 1, + "questionText": "Is there a line running across the bottom, driver's side then up the center of the Windshield?", + "answers": [ + { + "answerText": "Yes", + "nextQuestionSequence": null, + "answerResult": "DW01144" + }, + { + "answerText": "No", + "nextQuestionSequence": null, + "answerResult": "DW01143" + } + ] + } + ] + }, + { + "glassName": "Front", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DD08158GTYN", + "description": "driver side, front", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Quarter", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DQ08162GTYN", + "description": "driver side, 1 hole", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "SideDoor", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DD08160GTYN", + "description": "driver side, body side, 1 hole", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Stationary", + "glassLocation": "Rear", + "parts": [ + { + "partNumber": "DB08165GTNN", + "description": "heated glass, stationary", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); + }); + + test("a selected glass location has part questions and multiple parts => go to parts-questions", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Single", + "glassLocation": "Windshield", + "parts": null, + "partQuestions": [ + { + "questionSequence": 1, + "questionText": "Is there a line running across the bottom, driver's side then up the center of the Windshield?", + "answers": [ + { + "answerText": "Yes", + "nextQuestionSequence": null, + "answerResult": "DW01144" + }, + { + "answerText": "No", + "nextQuestionSequence": null, + "answerResult": "DW01143" + } + ] + } + ] + }, + { + "glassName": "Front", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DD08158GTYN", + "description": "driver side, front", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Quarter", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DQ08162GTYN", + "description": "driver side, 1 hole", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DQ08162YPYN", + "description": "driver side, 1 hole", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "SideDoor", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DD08160GTYN", + "description": "driver side, body side, 1 hole", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DD08160YPYN", + "description": "driver side, body side, 1 hole", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Stationary", + "glassLocation": "Rear", + "parts": [ + { + "partNumber": "DB08165GTNN", + "description": "heated glass, stationary", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DB08165YPNN", + "description": "heated glass, stationary", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DB08166GTNN", + "description": "stationary", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DB08167GTNN", + "description": "heated glass, movable, 8 hole", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DB08167YPNN", + "description": "heated glass, movable, 8 hole", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); + }); + }); + + describe("should go to vehicle-parts", () => { + test("single glass location has multiple parts => go to vehicle-parts", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Stationary", + "glassLocation": "Rear", + "parts": [ + { + "partNumber": "FB25724GTYN", + "description": "heated glass, solar, antenna", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "FB25759GTYN", + "description": "heated glass, solar, antenna, w/diversity antenna", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); + }); + + test("multiple glass locations selected, one of them has multiple parts => go to vehicle parts", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Single", + "glassLocation": "Windshield", + "parts": [ + { + "partNumber": "FW03647GTNN", + "description": "solar, 3rd visor band", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": [ + { + "partNumber": "MWF03647", + "partType": "MOULDING", + "description": "Upper " + } + ] + } + ], + "partQuestions": null + }, + { + "glassName": "Back", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "FD25747GTYN", + "description": "solar, driver side, rear, ex models and above", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Front", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "FD25719GTYN", + "description": "solar, driver side, front, ex models and above", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Vent", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "FV25749GTNN", + "description": "solar, driver side, rear", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Stationary", + "glassLocation": "Rear", + "parts": [ + { + "partNumber": "FB25724GTYN", + "description": "heated glass, solar, antenna", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "FB25759GTYN", + "description": "heated glass, solar, antenna, w/diversity antenna", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); + }); + + test("multiple glass locations selected, multiple have multiple parts => go to vehicle-parts", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Single", + "glassLocation": "Windshield", + "parts": [ + { + "partNumber": "DW02101GTYN", + "description": "solar", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Back", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DD12202GTYN", + "description": "solar, driver side, rear", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DD12202YPYN", + "description": "solar, driver side, rear", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Front", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DD12198GTYN", + "description": "solar, driver side, front", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DD12200GTYN", + "description": "solar, driver side, front, laminated, soundproofing", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Quarter", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "DQ12204GTYNOEM", + "description": "solar, driver side, encap", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DQ12204YPYNOEM", + "description": "solar, driver side, encap", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DQ12205GTYNOEM", + "description": "solar, antenna, driver side, encap", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DQ12205YPYNOEM", + "description": "solar, antenna, driver side, encap", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DQ12207GTYN", + "description": "solar, driver side, encap, chrome molding", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DQ12207YPYNOEM", + "description": "solar, driver side, encap, chrome molding", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DQ12208GTYNOEM", + "description": "solar, antenna, driver side, encap, chrome molding", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DQ12208YPYNOEM", + "description": "solar, antenna, driver side, encap, chrome molding", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Stationary", + "glassLocation": "Rear", + "parts": [ + { + "partNumber": "DB12209GTYN", + "description": "heated glass, solar, 1 hole", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + }, + { + "partNumber": "DB12209YPYN", + "description": "heated glass, solar, 1 hole", + "color": "Gray Tint Privacy", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null + } + ], + "partQuestions": null + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); + }); + }); + + describe("should go to molding-questions", () => { + test("single glass location has child part questions => go to molding-questions", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Stationary", + "glassLocation": "Rear", + "parts": [ + { + "partNumber": "FB25724GTYN", + "description": "heated glass, solar, antenna", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null, + "childPartQuestions": [ + { + "questionSequence": 1, + "questionText": "Does the rubber seal around your windshield have a chrome strip running through it?", + "answers": [ + { + "answerResult": "WKT D1106 C", + "answerText": "Yes", + "nextQuestionSequence": null + }, + { + "answerResult": "WKT D1106 B", + "answerText": "No", + "nextQuestionSequence": null + } + ] + } + ] + + } + ], + "partQuestions": null + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); + }); + }); + + describe("should go to capability-questions", () => { + test("single glass location has no child part questions but requiresCapabilityQuestions is true => go to capability-questions", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Single", + "glassLocation": "Windshield", + "parts": [ + { + "partNumber": "FB25724GTYN", + "description": "heated glass, solar, antenna", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": true, + "childParts": null, + "childPartQuestions": null + } + ], + "partQuestions": null + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_CAPABILITY_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions, capabilityQuestions: [] }); + }); + }); + + describe("should go to heritage funnel", () => { + test("single glass location selected, has no part questions and has one part => go to heritage funnel", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Single", + "glassLocation": "Windshield", + "parts": [ + { + "partNumber": "FW04186GTYN", + "description": "solar, soundproofing, lane keep assist", + "color": "Green Tint", + "requiresRecalibration": true, + "requiresCapabilityQuestions": false, + "childParts": [ + { + "partNumber": "GGG 3563 KIT", + "partType": "MOULDING", + "description": "Kit, Top & Sides " + } + ] + } + ], + "partQuestions": null + } + ] + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + // Assert + expect(navigateToHeritageFunnel).toHaveBeenCalledTimes(1); + }); + + test("multiple glass locations selected, each has one part and no part questions => go to heritage funnel", async () => { + // Arrange + const partsOrQuestions = [ + { + "glassName": "Single", + "glassLocation": "Windshield", + "parts": [ + { + "partNumber": "FW04186GTYN", + "description": "solar, soundproofing, lane keep assist", + "color": "Green Tint", + "requiresRecalibration": true, + "requiresCapabilityQuestions": false, + "childParts": [ + { + "partNumber": "GGG 3563 KIT", + "partType": "MOULDING", + "description": "Kit, Top & Sides " + } + ] + } + ], + "partQuestions": null + }, + { + "glassName": "Back", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "FD25457GTYN", + "description": "solar, driver side, rear", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": false, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Front", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "FD27090GTYN", + "description": "solar, driver side, front", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": false, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Vent", + "glassLocation": "Driver", + "parts": [ + { + "partNumber": "FV25459GTNN", + "description": "solar, driver side, rear", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": false, + "childParts": null + } + ], + "partQuestions": null + }, + { + "glassName": "Stationary", + "glassLocation": "Rear", + "parts": [ + { + "partNumber": "FB25460GTYN", + "description": "heated glass, solar", + "color": "Green Tint", + "requiresRecalibration": false, + "requiresCapabilityQuestions": false, + "childParts": null + } + ], + "partQuestions": null + } + ]; + + const { wrapper } = setupMocks({ + partsOrQuestions: partsOrQuestions + }); + + wrapper.vm.$store.commit = jest.fn(); + + const collectedGlassParts = wrapper.vm.reducedGlassPartsArray(partsOrQuestions); + + // Act + await wrapper.vm.navigateForward(partsOrQuestions); + + + // Assert + expect(wrapper.vm.$store.commit).toHaveBeenCalledTimes(1); + expect(wrapper.vm.$store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_GLASS_PARTS, collectedGlassParts) + expect(wrapper.vm.$refs.loadingModal.showModal).toHaveBeenCalledTimes(1); + expect(navigateToHeritageFunnel).toHaveBeenCalledTimes(1); + }); + }); + }) }); -function setupMocks({}) { - const baseMixin = setupMocksForJsFiles({}); +function setupMocks({ fmgPage = fmgPageValues.VIN_LOOKUP }) { + const baseMixin = setupMocksForJsFiles({ + actionList: [{ + actionName: storeActions.GET_CAPABILITY_QUESTIONS, + data: [], + }] + }); const mocks = getMountOptions({ router: { navigate: jest.fn() }, + store: { + commit: jest.fn(), + dispatch: jest.fn() + }, + route: { + query: { + fmgPage + } + } }); + // store.dispatch = jest.fn(); + const mockVehicleQuestionComponent = { - template: '
', + components: { loadingModal }, + template: '', mixins: [vehicleQuestionsMixin, baseMixin.baseMixin] }; const wrapper = shallowMount(mockVehicleQuestionComponent, mocks); + wrapper.vm.$refs.loadingModal.showModal = jest.fn(); + return { wrapper }; } \ No newline at end of file diff --git a/src/mixins/vin-pages-mixin.js b/src/mixins/vin-pages-mixin.js index a7ba799a2..817aa7b7e 100644 --- a/src/mixins/vin-pages-mixin.js +++ b/src/mixins/vin-pages-mixin.js @@ -1,43 +1,13 @@ import { storeActions } from "@/constants/store-actions.js"; -import { storeMutations } from "@/constants/store-mutations.js"; -import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; export default { - mixins: [vehicleQuestionsMixin], methods: { async navigateForwardWithSingleCarMatch() { const result = await this.dispatchStoreAction(storeActions.GET_PARTS_OR_QUESTIONS); - const partsOrQuestions = result.data.partsOrQuestions; - const hasPartsQuestions = this.hasPartQuestions(partsOrQuestions); - const hasGlassLocationWithMultipleParts = this.hasGlassLocationWithMultipleParts(partsOrQuestions); - const hasChildPartQuestions = this.hasChildPartQuestions(partsOrQuestions); - const hasCapabilityQuestions = this.hasCapabilityQuestions(partsOrQuestions); - - if (hasPartsQuestions) { - this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, this.$route, {}, {}, result.data); - } - else if (hasGlassLocationWithMultipleParts) { - this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, this.$route, {}, {}, result.data); - } - else if (hasChildPartQuestions) { - this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, this.$route, {}, {}, result.data); - } - else if (hasCapabilityQuestions) { - this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_CAPABILITY_QUESTIONS, this.$route, {}, {}, result.data); - } - else { - // if single parts only - const collectedGlassParts = this.reducedGlassPartsArray(result.data.partsOrQuestions); - // save to store lineItems.glassParts - this.$store.commit(storeMutations.UPDATE_GLASS_PARTS, collectedGlassParts); - - // go to heritage quote page - this.$refs.loadingModal.showModal(); - navigateToHeritageFunnel(); - } + vehicleQuestionsMixin.methods.navigateForward(partsOrQuestions, this); }, } } \ No newline at end of file diff --git a/src/mixins/vin-pages-mixin.spec.js b/src/mixins/vin-pages-mixin.spec.js index bfb1c4c06..4759eb5dc 100644 --- a/src/mixins/vin-pages-mixin.spec.js +++ b/src/mixins/vin-pages-mixin.spec.js @@ -2,14 +2,11 @@ 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 { storeMutations } from "@/constants/store-mutations"; -import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; -import store from "@/store"; import loadingModal from '@/common-components/loading-modal/loading-modal.vue'; -import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({ - navigateToHeritageFunnel: jest.fn() + navigateForward: jest.fn() })); describe("vin-pages-mixin", () => { @@ -18,955 +15,17 @@ describe("vin-pages-mixin", () => { }) describe("navigateForwardWithSingleCarMatch", () => { - describe("should go to parts-questions", () => { - test("single glass location has part question => go to parts-questions", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Single", - "glassLocation": "Windshield", - "parts": null, - "partQuestions": [ - { - "questionSequence": 1, - "questionText": "Is there a line running across the bottom, driver's side then up the center of the Windshield?", - "answers": [ - { - "answerText": "Yes", - "nextQuestionSequence": null, - "answerResult": "DW01144" - }, - { - "answerText": "No", - "nextQuestionSequence": null, - "answerResult": "DW01143" - } - ] - } - ] - } - ]; + test("should navigateForward", async () => { + // Arrange + const { wrapper } = setupMocks({}); + vehicleQuestionsMixin.methods.navigateForward = jest.fn(); - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); + // Act + await wrapper.vm.navigateForwardWithSingleCarMatch(); - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); - }); - - test("multiple glass locations have part questions => go to parts-questions", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Single", - "glassLocation": "Windshield", - "parts": null, - "partQuestions": [ - { - "questionSequence": 1, - "questionText": "Is there a line running across the bottom, driver's side then up the center of the Windshield?", - "answers": [ - { - "answerText": "Yes", - "nextQuestionSequence": null, - "answerResult": "DW01144" - }, - { - "answerText": "No", - "nextQuestionSequence": null, - "answerResult": "DW01143" - } - ] - } - ] - }, - { - "glassName": "Front", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DD08158GTYN", - "description": "driver side, front", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Quarter", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DQ08162GTYN", - "description": "driver side, 1 hole", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "SideDoor", - "glassLocation": "Driver", - "parts": null, - "partQuestions": [ - { - "questionSequence": 2, - "questionText": "Is this a super awesome question?", - "answers": [ - { - "answerText": "Yes", - "nextQuestionSequence": null, - "answerResult": "DW01144000" - }, - { - "answerText": "Super yes", - "nextQuestionSequence": null, - "answerResult": "DW01143001" - } - ] - } - ] - }, - { - "glassName": "Stationary", - "glassLocation": "Rear", - "parts": [ - { - "partNumber": "DB08165GTNN", - "description": "heated glass, stationary", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - } - ]; - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); - }); - - test("multiple glass locations selected, one has part question => go to parts-questions", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Single", - "glassLocation": "Windshield", - "parts": null, - "partQuestions": [ - { - "questionSequence": 1, - "questionText": "Is there a line running across the bottom, driver's side then up the center of the Windshield?", - "answers": [ - { - "answerText": "Yes", - "nextQuestionSequence": null, - "answerResult": "DW01144" - }, - { - "answerText": "No", - "nextQuestionSequence": null, - "answerResult": "DW01143" - } - ] - } - ] - }, - { - "glassName": "Front", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DD08158GTYN", - "description": "driver side, front", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Quarter", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DQ08162GTYN", - "description": "driver side, 1 hole", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "SideDoor", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DD08160GTYN", - "description": "driver side, body side, 1 hole", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Stationary", - "glassLocation": "Rear", - "parts": [ - { - "partNumber": "DB08165GTNN", - "description": "heated glass, stationary", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - } - ]; - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); - }); - - test("a selected glass location has part questions and multiple parts => go to parts-questions", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Single", - "glassLocation": "Windshield", - "parts": null, - "partQuestions": [ - { - "questionSequence": 1, - "questionText": "Is there a line running across the bottom, driver's side then up the center of the Windshield?", - "answers": [ - { - "answerText": "Yes", - "nextQuestionSequence": null, - "answerResult": "DW01144" - }, - { - "answerText": "No", - "nextQuestionSequence": null, - "answerResult": "DW01143" - } - ] - } - ] - }, - { - "glassName": "Front", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DD08158GTYN", - "description": "driver side, front", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Quarter", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DQ08162GTYN", - "description": "driver side, 1 hole", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DQ08162YPYN", - "description": "driver side, 1 hole", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "SideDoor", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DD08160GTYN", - "description": "driver side, body side, 1 hole", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DD08160YPYN", - "description": "driver side, body side, 1 hole", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Stationary", - "glassLocation": "Rear", - "parts": [ - { - "partNumber": "DB08165GTNN", - "description": "heated glass, stationary", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DB08165YPNN", - "description": "heated glass, stationary", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DB08166GTNN", - "description": "stationary", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DB08167GTNN", - "description": "heated glass, movable, 8 hole", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DB08167YPNN", - "description": "heated glass, movable, 8 hole", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - } - ]; - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); - }); - }); - - describe("should go to vehicle-parts", () => { - test("single glass location has multiple parts => go to vehicle-parts", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Stationary", - "glassLocation": "Rear", - "parts": [ - { - "partNumber": "FB25724GTYN", - "description": "heated glass, solar, antenna", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "FB25759GTYN", - "description": "heated glass, solar, antenna, w/diversity antenna", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - } - ]; - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); - }); - - test("multiple glass locations selected, one of them has multiple parts => go to vehicle parts", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Single", - "glassLocation": "Windshield", - "parts": [ - { - "partNumber": "FW03647GTNN", - "description": "solar, 3rd visor band", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": [ - { - "partNumber": "MWF03647", - "partType": "MOULDING", - "description": "Upper " - } - ] - } - ], - "partQuestions": null - }, - { - "glassName": "Back", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "FD25747GTYN", - "description": "solar, driver side, rear, ex models and above", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Front", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "FD25719GTYN", - "description": "solar, driver side, front, ex models and above", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Vent", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "FV25749GTNN", - "description": "solar, driver side, rear", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Stationary", - "glassLocation": "Rear", - "parts": [ - { - "partNumber": "FB25724GTYN", - "description": "heated glass, solar, antenna", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "FB25759GTYN", - "description": "heated glass, solar, antenna, w/diversity antenna", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - } - ]; - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); - }); - - test("multiple glass locations selected, multiple have multiple parts => go to vehicle-parts", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Single", - "glassLocation": "Windshield", - "parts": [ - { - "partNumber": "DW02101GTYN", - "description": "solar", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Back", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DD12202GTYN", - "description": "solar, driver side, rear", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DD12202YPYN", - "description": "solar, driver side, rear", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Front", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DD12198GTYN", - "description": "solar, driver side, front", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DD12200GTYN", - "description": "solar, driver side, front, laminated, soundproofing", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Quarter", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "DQ12204GTYNOEM", - "description": "solar, driver side, encap", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DQ12204YPYNOEM", - "description": "solar, driver side, encap", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DQ12205GTYNOEM", - "description": "solar, antenna, driver side, encap", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DQ12205YPYNOEM", - "description": "solar, antenna, driver side, encap", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DQ12207GTYN", - "description": "solar, driver side, encap, chrome molding", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DQ12207YPYNOEM", - "description": "solar, driver side, encap, chrome molding", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DQ12208GTYNOEM", - "description": "solar, antenna, driver side, encap, chrome molding", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DQ12208YPYNOEM", - "description": "solar, antenna, driver side, encap, chrome molding", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Stationary", - "glassLocation": "Rear", - "parts": [ - { - "partNumber": "DB12209GTYN", - "description": "heated glass, solar, 1 hole", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - }, - { - "partNumber": "DB12209YPYN", - "description": "heated glass, solar, 1 hole", - "color": "Gray Tint Privacy", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null - } - ], - "partQuestions": null - } - ]; - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); - }); - }); - - describe("should go to molding-questions", () => { - test("single glass location has child part questions => go to molding-questions", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Stationary", - "glassLocation": "Rear", - "parts": [ - { - "partNumber": "FB25724GTYN", - "description": "heated glass, solar, antenna", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null, - "childPartQuestions": [ - { - "questionSequence": 1, - "questionText": "Does the rubber seal around your windshield have a chrome strip running through it?", - "answers": [ - { - "answerResult": "WKT D1106 C", - "answerText": "Yes", - "nextQuestionSequence": null - }, - { - "answerResult": "WKT D1106 B", - "answerText": "No", - "nextQuestionSequence": null - } - ] - } - ] - - } - ], - "partQuestions": null - } - ]; - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); - }); - }); - - describe("should go to capability-questions", () => { - test("single glass location has no child part questions but requiresCapabilityQuestions is true => go to capability-questions", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Stationary", - "glassLocation": "Rear", - "parts": [ - { - "partNumber": "FB25724GTYN", - "description": "heated glass, solar, antenna", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": true, - "childParts": null, - "childPartQuestions": null - } - ], - "partQuestions": null - } - ]; - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.SELECTED_VIN_WITH_CAPABILITY_QUESTIONS, wrapper.vm.$route, {}, {}, { partsOrQuestions }); - }); - }); - - describe("should go to heritage funnel", () => { - test("single glass location selected, has no part questions and has one part => go to heritage funnel", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Single", - "glassLocation": "Windshield", - "parts": [ - { - "partNumber": "FW04186GTYN", - "description": "solar, soundproofing, lane keep assist", - "color": "Green Tint", - "requiresRecalibration": true, - "requiresCapabilityQuestions": false, - "childParts": [ - { - "partNumber": "GGG 3563 KIT", - "partType": "MOULDING", - "description": "Kit, Top & Sides " - } - ] - } - ], - "partQuestions": null - } - ] - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - // Assert - expect(navigateToHeritageFunnel).toHaveBeenCalledTimes(1); - }); - - test("multiple glass locations selected, each has one part and no part questions => go to heritage funnel", async () => { - // Arrange - const partsOrQuestions = [ - { - "glassName": "Single", - "glassLocation": "Windshield", - "parts": [ - { - "partNumber": "FW04186GTYN", - "description": "solar, soundproofing, lane keep assist", - "color": "Green Tint", - "requiresRecalibration": true, - "requiresCapabilityQuestions": false, - "childParts": [ - { - "partNumber": "GGG 3563 KIT", - "partType": "MOULDING", - "description": "Kit, Top & Sides " - } - ] - } - ], - "partQuestions": null - }, - { - "glassName": "Back", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "FD25457GTYN", - "description": "solar, driver side, rear", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": false, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Front", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "FD27090GTYN", - "description": "solar, driver side, front", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": false, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Vent", - "glassLocation": "Driver", - "parts": [ - { - "partNumber": "FV25459GTNN", - "description": "solar, driver side, rear", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": false, - "childParts": null - } - ], - "partQuestions": null - }, - { - "glassName": "Stationary", - "glassLocation": "Rear", - "parts": [ - { - "partNumber": "FB25460GTYN", - "description": "heated glass, solar", - "color": "Green Tint", - "requiresRecalibration": false, - "requiresCapabilityQuestions": false, - "childParts": null - } - ], - "partQuestions": null - } - ]; - - const { wrapper } = setupMocks({ - partsOrQuestions: partsOrQuestions - }); - - wrapper.vm.$store.commit = jest.fn(); - - const collectedGlassParts = wrapper.vm.reducedGlassPartsArray(partsOrQuestions); - - // Act - await wrapper.vm.navigateForwardWithSingleCarMatch(); - - - // Assert - expect(wrapper.vm.$store.commit).toHaveBeenCalledTimes(1); - expect(wrapper.vm.$store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_GLASS_PARTS, collectedGlassParts) - expect(wrapper.vm.$refs.loadingModal.showModal).toHaveBeenCalledTimes(1); - expect(navigateToHeritageFunnel).toHaveBeenCalledTimes(1); - }); - }); + // Assert + expect(vehicleQuestionsMixin.methods.navigateForward).toHaveBeenCalled(); + }) }); }); @@ -982,14 +41,7 @@ function setupMocks({ partsOrQuestions = [] }) { ], }); - const mocks = getMountOptions({ - router: { - navigate: jest.fn() - }, - store: { - commit: jest.fn() - } - }); + const mocks = getMountOptions({}); const mockVinComponent = { components: { loadingModal }, diff --git a/src/router/router-constants/navigation-scenarios.js b/src/router/router-constants/navigation-scenarios.js index 2bd259909..7cca25d09 100644 --- a/src/router/router-constants/navigation-scenarios.js +++ b/src/router/router-constants/navigation-scenarios.js @@ -8,10 +8,10 @@ const navigationScenarios = { CLICKED_FORWARD: "CLICKED_FORWARD", CLICKED_FORWARD_WITH_VIN: "CLICKED_FORWARD_WITH_VIN", SELECTED_PARTS: "SELECTED_PARTS", - SELECTED_VIN_WITH_PART_QUESTIONS: "SELECTED_VIN_WITH_PART_QUESTIONS", - SELECTED_VIN_WITH_MULTIPLE_PARTS: "SELECTED_VIN_WITH_MULTIPLE_PARTS", - SELECTED_VIN_WITH_MOLDING_QUESTIONS: "SELECTED_VIN_WITH_MOLDING_QUESTIONS", - SELECTED_VIN_WITH_CAPABILITY_QUESTIONS: "SELECTED_VIN_WITH_CAPABILITY_QUESTIONS", + SELECTED_VIN_WITH_PART_QUESTIONS: "HAS_PART_QUESTIONS", + SELECTED_VIN_WITH_MULTIPLE_PARTS: "HAS_MULTIPLE_PARTS_TO_CHOOSE", + SELECTED_VIN_WITH_MOLDING_QUESTIONS: "HAS_MOLDING_QUESTIONS", + SELECTED_VIN_WITH_CAPABILITY_QUESTIONS: "HAS_CAPABILITY_QUESTIONS", CONTINUING_WITH_SINGLE_PART: "CONTINUING_WITH_SINGLE_PART", CONTINUING_WITH_MULTIPLE_VEHICLES: "CONTINUING_WITH_MULTIPLE_VEHICLES", SELECTED_VIN_HAS_MISMATCHED_GLASS: "SELECTED_VIN_HAS_MISMATCHED_GLASS", @@ -24,8 +24,15 @@ const navigationScenarios = { SELECTED_PROVIDE_VIN_DIFFERENT_WAY: "SELECTED_PROVIDE_VIN_DIFFERENT_WAY", CLICKED_BACK_WITH_PART_QUESTION_ANSWERS: "CLICKED_BACK_WITH_PART_QUESTION_ANSWERS", CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS: "CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS", + ANSWERED_ALL_QUESTIONS: "ANSWERED_ALL_QUESTIONS", + HAS_PART_QUESTIONS: "HAS_PART_QUESTIONS", + HAS_MULTIPLE_PARTS_TO_CHOOSE: "HAS_MULTIPLE_PARTS_TO_CHOOSE", HAS_MOLDING_QUESTIONS: "HAS_MOLDING_QUESTIONS", HAS_CAPABILITY_QUESTIONS: "HAS_CAPABILITY_QUESTIONS", + CLICKED_BACK_TO_GO_TO_VIN_LOOKUP: "CLICKED_BACK_TO_GO_TO_VIN_LOOKUP", + CLICKED_BACK_TO_GO_TO_PART_QUESTIONS: "CLICKED_BACK_TO_GO_TO_PART_QUESTIONS", + CLICKED_BACK_TO_GO_TO_VEHICLE_PARTS: "CLICKED_BACK_TO_GO_TO_VEHICLE_PARTS", + CLICKED_BACK_TO_GO_TO_MOLDING_QUESTIONS: "CLICKED_BACK_TO_GO_TO_MOLDING_QUESTIONS" }; export { navigationScenarios }; diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index 37fb1c13e..34c5263cf 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -69,27 +69,6 @@ const routingTable = function(store) { }, ], }, - { - fmgPageValue: fmgPageValues.VEHICLE_PARTS, - maps: [ - { - scenario: navigationScenarios.SELECTED_PARTS, - destinationFmgPageValue: fmgPageValues.QUOTE, - }, - { - scenario: navigationScenarios.CLICKED_FORWARD, - destinationFmgPageValue: fmgPageValues.REVEAL, - }, - { - scenario: navigationScenarios.CLICKED_BACK_WITH_PART_QUESTION_ANSWERS, - destinationFmgPageValue: fmgPageValues.PART_QUESTIONS, - }, - { - scenario: navigationScenarios.CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS, - destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, - }, - ], - }, { fmgPageValue: fmgPageValues.REVEAL, maps: [ @@ -256,11 +235,11 @@ const routingTable = function(store) { fmgPageValue: fmgPageValues.PART_QUESTIONS, maps: [ { - scenario: navigationScenarios.CLICKED_BACK, + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_VIN_LOOKUP, destinationFmgPageValue: fmgPageValues.VIN_LOOKUP }, { - scenario: navigationScenarios.ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS, + scenario: navigationScenarios.HAS_MULTIPLE_PARTS_TO_CHOOSE, destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS }, { @@ -272,31 +251,92 @@ const routingTable = function(store) { destinationFmgPageValue: fmgPageValues.CAPABILITY_QUESTIONS, }, { - scenario: navigationScenarios.ANSWERED_QUESTIONS_WITH_SINGLE_PART, + scenario: navigationScenarios.ANSWERED_ALL_QUESTIONS, destinationFmgPageValue: fmgPageValues.QUOTE, }, ] }, + { + fmgPageValue: fmgPageValues.VEHICLE_PARTS, + maps: [ + { + scenario: navigationScenarios.SELECTED_PARTS, + destinationFmgPageValue: fmgPageValues.QUOTE, + }, + { + scenario: navigationScenarios.CLICKED_FORWARD, + destinationFmgPageValue: fmgPageValues.REVEAL, + }, + { + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_PART_QUESTIONS, + destinationFmgPageValue: fmgPageValues.PART_QUESTIONS, + }, + { + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_VIN_LOOKUP, + destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, + }, + { + scenario: navigationScenarios.HAS_MOLDING_QUESTIONS, + destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS, + }, + { + scenario: navigationScenarios.HAS_CAPABILITY_QUESTIONS, + destinationFmgPageValue: fmgPageValues.CAPABILITY_QUESTIONS, + }, + { + scenario: navigationScenarios.ANSWERED_ALL_QUESTIONS, + destinationFmgPageValue: fmgPageValues.QUOTE, + }, + ], + }, { fmgPageValue: fmgPageValues.MOLDING_QUESTIONS, maps: [ { - scenario: navigationScenarios.CLICKED_BACK, + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_VIN_LOOKUP, + destinationFmgPageValue: fmgPageValues.VIN_LOOKUP + }, + { + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_PART_QUESTIONS, + destinationFmgPageValue: fmgPageValues.PART_QUESTIONS + }, + { + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_VEHICLE_PARTS, destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS }, { scenario: navigationScenarios.HAS_CAPABILITY_QUESTIONS, destinationFmgPageValue: fmgPageValues.CAPABILITY_QUESTIONS, }, + { + scenario: navigationScenarios.ANSWERED_ALL_QUESTIONS, + destinationFmgPageValue: fmgPageValues.QUOTE, + } ] }, { fmgPageValue: fmgPageValues.CAPABILITY_QUESTIONS, maps: [ { - scenario: navigationScenarios.CLICKED_BACK, + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_VIN_LOOKUP, + destinationFmgPageValue: fmgPageValues.VIN_LOOKUP + }, + { + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_PART_QUESTIONS, + destinationFmgPageValue: fmgPageValues.PART_QUESTIONS + }, + { + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_VEHICLE_PARTS, destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS }, + { + scenario: navigationScenarios.CLICKED_BACK_TO_GO_TO_MOLDING_QUESTIONS, + destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS + }, + { + scenario: navigationScenarios.ANSWERED_ALL_QUESTIONS, + destinationFmgPageValue: fmgPageValues.QUOTE + }, ] }, ]; diff --git a/src/store/index.js b/src/store/index.js index 0220bf97e..b8b5ffe16 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -49,6 +49,7 @@ const getDefaultState = () => { numberOfChips: null, glassToReplace: null, partQuestionAnswers: null, + capabilityQuestionAnswers: null }, lineItems: { glassParts: null @@ -126,6 +127,9 @@ export const mutations = { updatePartQuestionAnswers(state, answersArray) { state.order.damage.partQuestionAnswers = answersArray; }, + updateCapabilityQuestionAnswers(state, answersArray) { + state.order.damage.capabilityQuestionAnswers = answersArray; + }, updateGlassParts(state, partsData) { state.order.lineItems.glassParts = partsData; }, @@ -277,6 +281,7 @@ export const mutations = { resetGlassPartsState(state) { state.order.lineItems.glassParts = null; state.order.damage.partQuestionAnswers = null; + state.order.damage.capabilityQuestionAnswers = null; state.applicationUser.pageData[fmgPageValues.PART_QUESTIONS] = null; state.applicationUser.pageData[fmgPageValues.VEHICLE_PARTS] = null; state.applicationUser.pageData[fmgPageValues.MOLDING_QUESTIONS] = null; @@ -737,6 +742,29 @@ export const actions = { }); }, + getCapabilityQuestions(context, { carId, partNumber }) { + return globalMethods.callHttpClient({ + method: endpoints.GetCapabilityQuestions.method, + endpoint: `${endpoints.GetCapabilityQuestions.url}/${carId}/${partNumber}`, + }) + }, + + getPartFromCapabilityQuestionAnswer(context, selectedAnswerResult1) { + const pageData = context.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS); + + const part = pageData.partsOrQuestions.find(x => x.glassLocation === damageLocationsSelected.WINDSHIELD).parts[0]; + const capabilityQuestionAnswers = context.getters.damage.capabilityQuestionAnswers; + + return globalMethods.callHttpClient({ + method: endpoints.ApplyCapabilityAnswerToPart.method, + endpoint: endpoints.ApplyCapabilityAnswerToPart.url, + payload: { + part, + capabilityAnswerResults: capabilityQuestionAnswers + } + }) + }, + // Order API Actions saveOrder(context) { const vehicle = context.getters.vehicle; @@ -967,10 +995,22 @@ export const actions = { } }, savePartQuestionAnswers(context, partQuestionAnswersArray) { + // if part question answers have changed, reset subsequent question answers + const previousResultsArray = context.getters.damage.partQuestionAnswers; + const havePartQuestionAnswersChanged = previousResultsArray.length !== partQuestionAnswersArray.length || + !previousResultsArray.every((x, i) => x.result === partQuestionAnswersArray[i].result); + + if (havePartQuestionAnswersChanged) { + context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null); + } + //Save new values context.commit(storeMutations.UPDATE_PART_QUESTION_ANSWERS, partQuestionAnswersArray); }, - + saveCapabilityQuestionAnswers(context, capabilityQuestionAnswers) { + //Save new values + context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, capabilityQuestionAnswers); + }, // Misc order actions saveServiceLocation(context, serviceLocationInfo) { context.commit(storeMutations.UPDATE_SERVICE_LOCATION, serviceLocationInfo); From ad4ac40c8b1ba846c3ff361c3a71d66486c227ed Mon Sep 17 00:00:00 2001 From: Katie Date: Thu, 18 Aug 2022 12:13:40 -0400 Subject: [PATCH 2/2] CSR-111-parts Fix loadingModal issue for vin-pages --- src/mixins/vehicle-questions-mixin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index a55859567..9164045c9 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -110,7 +110,7 @@ export default { // save to store lineItems.glassParts self.$store.commit(storeMutations.UPDATE_GLASS_PARTS, collectedGlassParts); - this.$refs.loadingModal.showModal(); + self.$refs.loadingModal.showModal(); navigateToHeritageFunnel(); // For quote pages MVP release