Merge pull request #709 from Safelite/feature/CSR-111-parts-resetting

Feature/csr 111 parts resetting
This commit is contained in:
katieoh-safelite 2022-08-31 11:18:51 -04:00 committed by GitHub
commit b791320b1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 15 deletions

View file

@ -137,7 +137,7 @@ export default {
glass.answerData = {}; 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); await this.dispatchStoreAction(this.storeActions.SAVE_MOLDING_QUESTION_ANSWERS, questionAnswersArray, false);
// get parts from the questionAnswers // get parts from the questionAnswers
@ -460,7 +460,7 @@ export default {
// add answerData to current glass // add answerData to current glass
glass.answerData = { glass.answerData = {
answerResult: savedPart.result, answerResult: savedPart.partNum,
answeredQuestions: savedPart.answeredQuestions answeredQuestions: savedPart.answeredQuestions
} }
} }

View file

@ -122,7 +122,7 @@ export default {
} }
}, },
backButtonAction() { 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 hasPartQuestions = this.hasPartQuestions(partsOrQuestions);
const hasGlassLocationWithMultipleParts = this.hasGlassLocationWithMultipleParts(partsOrQuestions); const hasGlassLocationWithMultipleParts = this.hasGlassLocationWithMultipleParts(partsOrQuestions);
const hasChildPartQuestions = this.hasChildPartQuestions(partsOrQuestions); const hasChildPartQuestions = this.hasChildPartQuestions(partsOrQuestions);

View file

@ -225,7 +225,7 @@ export const mutations = {
}, },
// applicationUser MUTATIONS // applicationUser MUTATIONS
updateSaveOrderPromise(state, saveOrderPromise){ updateSaveOrderPromise(state, saveOrderPromise) {
state.applicationUser.saveOrderPromise = saveOrderPromise; state.applicationUser.saveOrderPromise = saveOrderPromise;
}, },
updateSavedSessionId(state, savedSessionId) { updateSavedSessionId(state, savedSessionId) {
@ -392,7 +392,7 @@ export const getters = {
parentAccountNumber: state.order.accountNumber, parentAccountNumber: state.order.accountNumber,
isCoverageVerified: state.order.payment.insuranceCoverage.isVerified, isCoverageVerified: state.order.payment.insuranceCoverage.isVerified,
orderPartNumbers: [...getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, "partNumber"), ...getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.otherParts, "partNumber")], 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, hasRecalibrationPart: getAllValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, "requiresRecalibration")?.length > 0,
selectedMultiGlass: state.order.damage.glassToReplace?.length > 1, selectedMultiGlass: state.order.damage.glassToReplace?.length > 1,
selectedWindshieldGlass: getAllValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, "glassLocation").includes(damageLocationsSelected.WINDSHIELD), selectedWindshieldGlass: getAllValuesOfPropertyInArrayOfObjects(state.order.damage.glassToReplace, "glassLocation").includes(damageLocationsSelected.WINDSHIELD),
@ -1020,12 +1020,15 @@ export const actions = {
}, },
resetMoldingAndCapabilityQuestionAnswersIfNeeded(context, matchedParts) { resetMoldingAndCapabilityQuestionAnswersIfNeeded(context, matchedParts) {
const previousResultsArray = [{ parts: context.getters.lineItems.glassParts }]; 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) { 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 currentlySelectedPartNumbers = getAllPartNumbers(matchedParts);
const haveSelectedVehiclePartsChanged = previouslySelectedPartNumbers !== currentlySelectedPartNumbers; const haveSelectedVehiclePartsChanged = previouslySelectedPartNumbers !== currentlySelectedPartNumbers;
@ -1040,15 +1043,10 @@ export const actions = {
}, },
saveMoldingQuestionAnswers(context, moldingQuestionAnswers) { saveMoldingQuestionAnswers(context, moldingQuestionAnswers) {
const previousResultsArray = context.getters.damage.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 || const haveMoldingQuestionAnswersChanged = previousResultsArray?.length !== moldingQuestionAnswers.length ||
!previousResultsArray.every((x, i) => !previousResultsArray.every((x, i) => x.partNum === moldingQuestionAnswers[i].partNum);
x.answeredQuestions &&
x.answeredQuestions.length === moldingQuestionAnswers[i].answeredQuestions?.length &&
x.answeredQuestions.every((y, j) => y.selectedAnswerText === moldingQuestionAnswers[i].answeredQuestions[j].selectedAnswerText));
if (haveMoldingQuestionAnswersChanged) { if (haveMoldingQuestionAnswersChanged) {
// TODO reset glass parts
context.commit(storeMutations.UPDATE_GLASS_PARTS, null); context.commit(storeMutations.UPDATE_GLASS_PARTS, null);
context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null); context.commit(storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS, null);
context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.CAPABILITY_QUESTIONS, data: null }); context.commit(storeMutations.UPDATE_PAGE_DATA, { page: fmgPageValues.CAPABILITY_QUESTIONS, data: null });

View file

@ -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")
})
}); });