diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index 19d468411..91dcf5e40 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -137,7 +137,7 @@ export default { glass.answerData = {}; }); - // save to vuex store as order.damage.partQuestionAnswers (array) + // save to vuex store as order.damage.moldingQuestionArrays (array) await this.dispatchStoreAction(this.storeActions.SAVE_MOLDING_QUESTION_ANSWERS, questionAnswersArray, false); // get parts from the questionAnswers @@ -460,7 +460,7 @@ export default { // add answerData to current glass glass.answerData = { - answerResult: savedPart.result, + answerResult: savedPart.partNum, answeredQuestions: savedPart.answeredQuestions } } diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index 06776174f..616c1fb5e 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -122,7 +122,7 @@ export default { } }, backButtonAction() { - const partsOrQuestions = this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions; + const partsOrQuestions = (this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS) ?? this.$store.getters.pageData(fmgPageValues.VEHICLE_PARTS))?.partsOrQuestions; const hasPartQuestions = this.hasPartQuestions(partsOrQuestions); const hasGlassLocationWithMultipleParts = this.hasGlassLocationWithMultipleParts(partsOrQuestions); const hasChildPartQuestions = this.hasChildPartQuestions(partsOrQuestions); diff --git a/src/store/index.js b/src/store/index.js index 1b2c1dbcd..cfb5e1dff 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -225,7 +225,7 @@ export const mutations = { }, // applicationUser MUTATIONS - updateSaveOrderPromise(state, saveOrderPromise){ + updateSaveOrderPromise(state, saveOrderPromise) { state.applicationUser.saveOrderPromise = saveOrderPromise; }, updateSavedSessionId(state, savedSessionId) { @@ -392,7 +392,7 @@ export const getters = { parentAccountNumber: state.order.accountNumber, isCoverageVerified: state.order.payment.insuranceCoverage.isVerified, orderPartNumbers: [...getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, "partNumber"), ...getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.otherParts, "partNumber")], - orderPartTypes: [...getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, "recalibrationType"), ...getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.otherParts, "recalibrationType")], + orderPartTypes: [...getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, "recalibrationType"), ...getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.otherParts, "recalibrationType")], hasRecalibrationPart: getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, "requiresRecalibration")?.length > 0, selectedMultiGlass: state.order.damage.glassToReplace?.length > 1, selectedWindshieldGlass: getAllValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, "glassLocation").includes(damageLocationsSelected.WINDSHIELD), @@ -760,7 +760,7 @@ export const actions = { const part = pageData.partsOrQuestions.find(x => x.glassLocation === glassLocation).parts[0]; const capabilityQuestionAnswers = context.getters.damage.capabilityQuestionAnswers; const capabilityQuestionAnswersForPart = capabilityQuestionAnswers.find(x => x.glassLocation === glassLocation); - + return globalMethods.callHttpClient({ method: endpoints.GetPartFromCapabilityAnswer.method, endpoint: endpoints.GetPartFromCapabilityAnswer.url, @@ -1020,12 +1020,15 @@ export const actions = { }, resetMoldingAndCapabilityQuestionAnswersIfNeeded(context, matchedParts) { const previousResultsArray = [{ parts: context.getters.lineItems.glassParts }]; - + const partsOrQuestionsDataToCompareWith = context.getters.pageData(fmgPageValues.MOLDING_QUESTIONS)?.partsOrQuestions ?? context.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS)?.partsOrQuestions ?? []; + function getAllPartNumbers(partsOrQuestions) { - return [...partsOrQuestions].map(glass => glass.parts).flat().map(part => part.partNumber).filter(partNumber => !partNumber.toUpperCase().includes("FEE")).sort().join(","); + return partsOrQuestions[0].parts + ? [...partsOrQuestions].map(glass => glass.parts).flat().map(part => part.partNumber).filter(partNumber => !partNumber.toUpperCase().includes("FEE")).sort().join(",") + : [] } - const previouslySelectedPartNumbers = getAllPartNumbers(previousResultsArray); + const previouslySelectedPartNumbers = getAllPartNumbers(partsOrQuestionsDataToCompareWith); const currentlySelectedPartNumbers = getAllPartNumbers(matchedParts); const haveSelectedVehiclePartsChanged = previouslySelectedPartNumbers !== currentlySelectedPartNumbers; @@ -1040,15 +1043,10 @@ export const actions = { }, saveMoldingQuestionAnswers(context, moldingQuestionAnswers) { const previousResultsArray = context.getters.damage.moldingQuestionAnswers; - // TODO NOT ACCURATE!! answerData/answerQuestions keeps changing, partNum is undefined a lot const haveMoldingQuestionAnswersChanged = previousResultsArray?.length !== moldingQuestionAnswers.length || - !previousResultsArray.every((x, i) => - x.answeredQuestions && - x.answeredQuestions.length === moldingQuestionAnswers[i].answeredQuestions?.length && - x.answeredQuestions.every((y, j) => y.selectedAnswerText === moldingQuestionAnswers[i].answeredQuestions[j].selectedAnswerText)); + !previousResultsArray.every((x, i) => x.partNum === moldingQuestionAnswers[i].partNum); if (haveMoldingQuestionAnswersChanged) { - // TODO reset glass parts context.commit(storeMutations.UPDATE_GLASS_PARTS, null); context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null); context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.CAPABILITY_QUESTIONS, data: null }); diff --git a/src/store/store.spec.js b/src/store/store.spec.js index a69be855b..cec370042 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1154,6 +1154,49 @@ describe("Actions", () => { ]); }); }) + + describe("savePartQuestionAnswers", () => { + test.todo("saves partQuestionAnswers") + + test.todo("there are no previous answers => resets necessary fields") + + // mix up the order to make sure sort is working + test.todo("previous answers match current answers => does not reset fields") + + test.todo("previous answers does not match current answers => resets necessary fields") + }) + + describe("resetMoldingAndCapabilityQuestionAnswersIfNeeded", () => { + test.todo("there are no saved parts => resets necessary fields") + + // make sure you check the different variations where molding-questions and capability-questions do or don't have pageData + // mix up the order to make sure sort is working + test.todo("previously saved parts match selected parts => does not reset fields") + + test.todo("previously saved parts do not match selected parts => resets necessary fields") + }) + + describe("saveMoldingQuestionAnswers", () => { + test.todo("saves moldingQuestionAnswers") + + test.todo("there are no previous answers => resets necessary fields") + + // mix up the order to make sure sort is working + test.todo("previous answers match current answers => does not reset fields") + + test.todo("previous answers does not match current answers => resets necessary fields") + }) + + describe("saveCapabilityQuestionAnswers", () => { + test.todo("saves capabilityQuestionAnswers") + + test.todo("there are no previous answers => resets necessary fields") + + // mix up the order to make sure sort is working + test.todo("previous answers match current answers => does not reset fields") + + test.todo("previous answers does not match current answers => resets necessary fields") + }) });