From 6e0c9688d33a01d2ce63023d481d58e73639b56b Mon Sep 17 00:00:00 2001 From: Katie Date: Tue, 30 Aug 2022 13:12:18 -0400 Subject: [PATCH 1/3] CSR-111 Reset answers if they change --- src/constants/store-actions.js | 1 + src/layouts/vehicle-parts/vehicle-parts.vue | 2 + src/store/index.js | 53 ++++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 8d03c5b95..b77b1456f 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -58,6 +58,7 @@ const storeActions = { SAVE_REGISTRATION_ADDRESS_LOOKUP: "saveRegistrationAddressLookup", SAVE_GLASS_PARTS: "saveGlassParts", SAVE_PART_QUESTION_ANSWERS: "savePartQuestionAnswers", + RESET_MOLDING_AND_CAPABILITY_QUESTIONS_IF_NEEDED: "resetMoldingAndCapabilityQuestionAnswersIfNeeded", SAVE_MOLDING_QUESTION_ANSWERS: "saveMoldingQuestionAnswers", SAVE_CAPABILITY_QUESTION_ANSWERS: "saveCapabilityQuestionAnswers" }; diff --git a/src/layouts/vehicle-parts/vehicle-parts.vue b/src/layouts/vehicle-parts/vehicle-parts.vue index a276ef132..6f81b0003 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.vue +++ b/src/layouts/vehicle-parts/vehicle-parts.vue @@ -188,6 +188,8 @@ export default { throw new Error("Could not match any parts to the selected parts"); } + await this.dispatchStoreAction(this.storeActions.RESET_MOLDING_AND_CAPABILITY_QUESTIONS_IF_NEEDED, matchedParts, false); + // Navigate to the next page this.navigateForward(matchedParts); }, diff --git a/src/store/index.js b/src/store/index.js index 76ce9c3a9..5f044c449 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1007,20 +1007,69 @@ export const actions = { !previousResultsArray.every((x, i) => x.result === partQuestionAnswersArray[i].result); if (havePartQuestionAnswersChanged) { + context.commit(storeMutations.UPDATE_GLASS_PARTS, null); context.commit(storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS, null); context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null); - state.applicationUser.pageData[fmgPageValues.MOLDING_QUESTIONS] = null; - state.applicationUser.pageData[fmgPageValues.CAPABILITY_QUESTIONS] = null; + context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.VEHICLE_PARTS, data: null }); + context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.MOLDING_QUESTIONS, data: null }); + context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.CAPABILITY_QUESTIONS, data: null }); } //Save new values context.commit(storeMutations.UPDATE_PART_QUESTION_ANSWERS, partQuestionAnswersArray); }, + resetMoldingAndCapabilityQuestionAnswersIfNeeded(context, matchedParts) { + const previousResultsArray = [{ parts: context.getters.lineItems.glassParts }]; + + function getAllPartNumbers(partsOrQuestions) { + return [...partsOrQuestions].map(glass => glass.parts).flat().map(part => part.partNumber).sort().join(","); + } + + const previouslySelectedPartNumbers = getAllPartNumbers(previousResultsArray); + const currentlySelectedPartNumbers = getAllPartNumbers(matchedParts); + + const haveSelectedVehiclePartsChanged = previouslySelectedPartNumbers !== currentlySelectedPartNumbers; + + if (haveSelectedVehiclePartsChanged) { + context.commit(storeMutations.UPDATE_GLASS_PARTS, null); + context.commit(storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS, null); + context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null); + context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.MOLDING_QUESTIONS, data: null }); + context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.CAPABILITY_QUESTIONS, data: null }); + } + + console.log(previousResultsArray) + console.log(matchedParts) + console.log(haveSelectedVehiclePartsChanged) + }, 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)); + + 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 }); + } + //Save new values context.commit(storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS, moldingQuestionAnswers); }, saveCapabilityQuestionAnswers(context, capabilityQuestionAnswers) { + const previousResultsArray = context.getters.damage.capabilityQuestionAnswers; + const haveCapabilityQuestionAnswersChanged = previousResultsArray?.length !== capabilityQuestionAnswers.length || + !previousResultsArray.every((x, i) => x.result === capabilityQuestionAnswers[i].result); + + if (haveCapabilityQuestionAnswersChanged) { + context.commit(storeMutations.UPDATE_GLASS_PARTS, null); + } + //Save new values context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, capabilityQuestionAnswers); }, From 18103993998f8b0c8f1e536aab82d438d8cd312b Mon Sep 17 00:00:00 2001 From: Katie Date: Tue, 30 Aug 2022 13:54:42 -0400 Subject: [PATCH 2/3] CSR-111 Fix vehicle-parts answer change check logic --- src/store/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 5f044c449..1b2c1dbcd 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1022,7 +1022,7 @@ export const actions = { const previousResultsArray = [{ parts: context.getters.lineItems.glassParts }]; function getAllPartNumbers(partsOrQuestions) { - return [...partsOrQuestions].map(glass => glass.parts).flat().map(part => part.partNumber).sort().join(","); + return [...partsOrQuestions].map(glass => glass.parts).flat().map(part => part.partNumber).filter(partNumber => !partNumber.toUpperCase().includes("FEE")).sort().join(","); } const previouslySelectedPartNumbers = getAllPartNumbers(previousResultsArray); @@ -1037,10 +1037,6 @@ export const actions = { context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.MOLDING_QUESTIONS, data: null }); context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.CAPABILITY_QUESTIONS, data: null }); } - - console.log(previousResultsArray) - console.log(matchedParts) - console.log(haveSelectedVehiclePartsChanged) }, saveMoldingQuestionAnswers(context, moldingQuestionAnswers) { const previousResultsArray = context.getters.damage.moldingQuestionAnswers; From cba4f5ee3d17b2eaa884a14eb1264eee1f0c1845 Mon Sep 17 00:00:00 2001 From: Katie Date: Tue, 30 Aug 2022 14:22:10 -0400 Subject: [PATCH 3/3] CSR-111 Temporarily lower test coverage threhold --- jest.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index c18fd3125..d9da86118 100644 --- a/jest.config.js +++ b/jest.config.js @@ -25,7 +25,8 @@ module.exports = { testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"], coverageThreshold: { global: { - statements: 84, + // TODO after release/2022.09.15, raise this back up!! + statements: 80, // Got the go ahead from Mark to temporarily lower this. Taking out initialize component made the year,make,model and style coverage drop a bit. Once unit tests for license plate lookup, vin lookup and address lookup are in the coverage should go back up to 90 }, },