CSR-803: vehicle-questions-mixin updates
This commit is contained in:
parent
f24083e5cc
commit
b39463e650
2 changed files with 47 additions and 46 deletions
|
|
@ -150,7 +150,7 @@ export default {
|
||||||
|
|
||||||
return glass;
|
return glass;
|
||||||
},
|
},
|
||||||
handleAnswerUpdates(answer, glassKey, vm) {
|
handleCompletedQuestionChainAnswers(answer, glassKey, vm) {
|
||||||
// only runs when all questions in a question-chain have been answered
|
// only runs when all questions in a question-chain have been answered
|
||||||
// when selectedAnswers updates, user has completed this part's question chain and has a final answer
|
// when selectedAnswers updates, user has completed this part's question chain and has a final answer
|
||||||
// (does not get run for each invididual question's answer, only when
|
// (does not get run for each invididual question's answer, only when
|
||||||
|
|
@ -176,51 +176,39 @@ export default {
|
||||||
self.selectedAnswers = {};
|
self.selectedAnswers = {};
|
||||||
|
|
||||||
// loop through every answered question on the currently answered glass part
|
// loop through every answered question on the currently answered glass part
|
||||||
answer.answeredQuestions?.forEach((answeredQuestion) => {
|
answer.answeredQuestions?.forEach((answeredQuestion, answeredQuestionIndex) => {
|
||||||
/* answeredQuestion example format:
|
/* answeredQuestion example format:
|
||||||
{
|
{
|
||||||
"questionText": "Is your Grand Cherokee the Laredo model?",
|
"questionText": "Is your Grand Cherokee the Laredo model?",
|
||||||
|
"selectedAnswer": "1|nextQuestion|3|Yes",
|
||||||
"selectedAnswerText": "Yes",
|
"selectedAnswerText": "Yes",
|
||||||
"questionNum": 1,
|
"questionNum": 1,
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const answeredQuestionText = answeredQuestion.questionText.toUpperCase();
|
const answeredQuestionText = answeredQuestion.questionText.toUpperCase();
|
||||||
const answeredQuestionAnswer = answeredQuestion.selectedAnswerText.toUpperCase();
|
const answeredQuestionAnswer = answeredQuestion.selectedAnswer.toUpperCase();
|
||||||
|
const answeredQuestionAnswerText =
|
||||||
|
answeredQuestion.selectedAnswerText.toUpperCase();
|
||||||
|
const answeredQuestionNum = answeredQuestion.questionNum;
|
||||||
|
|
||||||
// HANDLE DUPLICATE QUESTIONS
|
// HANDLE DUPLICATE QUESTIONS
|
||||||
|
|
||||||
// loop through all glass data
|
// loop through all glass data
|
||||||
self.questionsData.forEach((glass, glassIndex) => {
|
self.questionsData.forEach((glass, glassIndex) => {
|
||||||
/* glass example format:
|
if (glassIndex === answer.index) {
|
||||||
{
|
glass.questions.forEach((question, questionIndex) => {
|
||||||
"glassName": "Single",
|
// clear out any previously set answers on first pass with first answered question
|
||||||
"glassLocation": "Windshield",
|
if (answeredQuestionIndex === 0) question.answerSelected = null;
|
||||||
"parts": null,
|
|
||||||
"questions": [
|
|
||||||
{
|
|
||||||
"questionSequence": 1,
|
|
||||||
"questionText": "Is your vehicle equipped with a black dotted pattern behind the rear view mirror, known as a third visor frit?",
|
|
||||||
"answers": [
|
|
||||||
{
|
|
||||||
"answerResult": "DW01537",
|
|
||||||
"answerText": "Yes",
|
|
||||||
"nextQuestionSequence": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"answerResult": "DW01537b",
|
|
||||||
"answerText": "No",
|
|
||||||
"nextQuestionSequence": null
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"answerKey": "Windshield-Single",
|
|
||||||
"answerData": null
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// limit duplicate search to glass pieces that follow after the currently being answered glass piece
|
if (answeredQuestionNum - 1 === questionIndex) {
|
||||||
|
// on the right question
|
||||||
|
question.answerSelected = answeredQuestionAnswer;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// limit duplicate search to glass pieces that are in or follow after the currently being answered glass piece
|
||||||
if (glassIndex > answer.index) {
|
if (glassIndex > answer.index) {
|
||||||
let indexToSuppressTo;
|
let indexToSuppressTo;
|
||||||
// reset this glass piece, in case user is changing their previous answers
|
// reset this glass piece, in case user is changing their previous answers
|
||||||
|
|
@ -229,8 +217,8 @@ export default {
|
||||||
|
|
||||||
// loop through this glass piece's questions, looking for a questionText match
|
// loop through this glass piece's questions, looking for a questionText match
|
||||||
glass.questions.forEach((question, questionIndex) => {
|
glass.questions.forEach((question, questionIndex) => {
|
||||||
// clear out any previously set answers
|
// clear out any previously set answers on first pass with first answer
|
||||||
question.answerSelected = null;
|
if (answeredQuestionIndex === 0) question.answerSelected = null;
|
||||||
|
|
||||||
// clear or set suppressThisQuestion property for each question
|
// clear or set suppressThisQuestion property for each question
|
||||||
if (indexToSuppressTo && questionIndex + 1 < indexToSuppressTo) {
|
if (indexToSuppressTo && questionIndex + 1 < indexToSuppressTo) {
|
||||||
|
|
@ -245,7 +233,9 @@ export default {
|
||||||
|
|
||||||
// handle matching answer in duplicated question
|
// handle matching answer in duplicated question
|
||||||
question.answers.forEach((ans) => {
|
question.answers.forEach((ans) => {
|
||||||
if (ans.answerText.toUpperCase() === answeredQuestionAnswer) {
|
if (
|
||||||
|
ans.answerText.toUpperCase() === answeredQuestionAnswerText
|
||||||
|
) {
|
||||||
matchedAnswer = ans;
|
matchedAnswer = ans;
|
||||||
ans.selected = true;
|
ans.selected = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -339,7 +329,7 @@ export default {
|
||||||
glass.isSuppressedPart = true;
|
glass.isSuppressedPart = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}); // DONE looping through glass.questions
|
||||||
|
|
||||||
// Update key to force re-render of glass piece with duplicate question in case user changes previous related answer in the chain
|
// Update key to force re-render of glass piece with duplicate question in case user changes previous related answer in the chain
|
||||||
self.questionsData[glassIndex].key =
|
self.questionsData[glassIndex].key =
|
||||||
|
|
@ -469,6 +459,7 @@ export default {
|
||||||
},
|
},
|
||||||
// Can't use `this` because navigateForward is also called from quote
|
// Can't use `this` because navigateForward is also called from quote
|
||||||
navigateBack(vm) {
|
navigateBack(vm) {
|
||||||
|
console.log("VQM = = navigateBack() run ");
|
||||||
const self = vm ?? this;
|
const self = vm ?? this;
|
||||||
const partsOrQuestions = (
|
const partsOrQuestions = (
|
||||||
self.$store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS) ??
|
self.$store.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS) ??
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("handleAnswerUpdates", () => {
|
describe("handleCompletedQuestionChainAnswers", () => {
|
||||||
describe("selectedAnswers", () => {
|
describe("selectedAnswers", () => {
|
||||||
test("should be cleared to be empty", () => {
|
test("should be cleared to be empty", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -419,6 +419,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test duplicate question 1?",
|
questionText: "Test duplicate question 1?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|Yes",
|
||||||
selectedAnswerText: "Yes",
|
selectedAnswerText: "Yes",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -438,7 +439,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.handleAnswerUpdates(answer, "", wrapper.vm);
|
wrapper.vm.handleCompletedQuestionChainAnswers(answer, "", wrapper.vm);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.selectedAnswers).toMatchObject({});
|
expect(wrapper.vm.selectedAnswers).toMatchObject({});
|
||||||
|
|
@ -453,6 +454,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test duplicate question 1?",
|
questionText: "Test duplicate question 1?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|Yes",
|
||||||
selectedAnswerText: "Yes",
|
selectedAnswerText: "Yes",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -477,7 +479,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.handleAnswerUpdates(answer, "", wrapper.vm);
|
wrapper.vm.handleCompletedQuestionChainAnswers(answer, "", wrapper.vm);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.questionsData[1].answerData).toEqual(null);
|
expect(wrapper.vm.questionsData[1].answerData).toEqual(null);
|
||||||
|
|
@ -489,6 +491,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test duplicate question 1?",
|
questionText: "Test duplicate question 1?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|Yes",
|
||||||
selectedAnswerText: "Yes",
|
selectedAnswerText: "Yes",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -514,7 +517,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.handleAnswerUpdates(answer, "", wrapper.vm);
|
wrapper.vm.handleCompletedQuestionChainAnswers(answer, "", wrapper.vm);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.questionsData[1].isSuppressedPart).toEqual(null);
|
expect(wrapper.vm.questionsData[1].isSuppressedPart).toEqual(null);
|
||||||
|
|
@ -526,6 +529,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test duplicate question 1?",
|
questionText: "Test duplicate question 1?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|Yes",
|
||||||
selectedAnswerText: "Yes",
|
selectedAnswerText: "Yes",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -587,7 +591,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.handleAnswerUpdates(answer, "", wrapper.vm);
|
wrapper.vm.handleCompletedQuestionChainAnswers(answer, "", wrapper.vm);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.questionsData[1].questions[0].answerSelected).toEqual(null);
|
expect(wrapper.vm.questionsData[1].questions[0].answerSelected).toEqual(null);
|
||||||
|
|
@ -603,6 +607,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test duplicate question 1?",
|
questionText: "Test duplicate question 1?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|No",
|
||||||
selectedAnswerText: "No",
|
selectedAnswerText: "No",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -661,7 +666,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm);
|
wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
|
||||||
const glassWithDuplicate = wrapper.vm.questionsData[1];
|
const glassWithDuplicate = wrapper.vm.questionsData[1];
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
|
@ -675,6 +680,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test duplicate question 1?",
|
questionText: "Test duplicate question 1?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|No",
|
||||||
selectedAnswerText: "No",
|
selectedAnswerText: "No",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -731,7 +737,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm);
|
wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
|
||||||
const duplicateQuestion = wrapper.vm.questionsData[1].questions[0];
|
const duplicateQuestion = wrapper.vm.questionsData[1].questions[0];
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
|
@ -746,6 +752,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test duplicate question 1?",
|
questionText: "Test duplicate question 1?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|No",
|
||||||
selectedAnswerText: "No",
|
selectedAnswerText: "No",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -835,7 +842,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm);
|
wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
|
||||||
const nextQuestionAfterDuplicate = wrapper.vm.questionsData[1].questions[2];
|
const nextQuestionAfterDuplicate = wrapper.vm.questionsData[1].questions[2];
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
|
@ -849,6 +856,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test question 3?",
|
questionText: "Test question 3?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|No",
|
||||||
selectedAnswerText: "No",
|
selectedAnswerText: "No",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -969,7 +977,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm);
|
wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
|
||||||
const duplicatedQuestion = wrapper.vm.questionsData[1].questions[2];
|
const duplicatedQuestion = wrapper.vm.questionsData[1].questions[2];
|
||||||
const duplicatedQuestionAnswer = duplicatedQuestion.answers.filter((a) => {
|
const duplicatedQuestionAnswer = duplicatedQuestion.answers.filter((a) => {
|
||||||
return a.selected;
|
return a.selected;
|
||||||
|
|
@ -997,6 +1005,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test duplicate question 1?",
|
questionText: "Test duplicate question 1?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|No",
|
||||||
selectedAnswerText: "No",
|
selectedAnswerText: "No",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -1085,7 +1094,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm);
|
wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(
|
expect(
|
||||||
|
|
@ -1109,6 +1118,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
answeredQuestions: [
|
answeredQuestions: [
|
||||||
{
|
{
|
||||||
questionText: "Test question 3?",
|
questionText: "Test question 3?",
|
||||||
|
selectedAnswer: "1|nextQuestion|3|No",
|
||||||
selectedAnswerText: "No",
|
selectedAnswerText: "No",
|
||||||
questionNum: 1,
|
questionNum: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -1197,7 +1207,7 @@ describe("vehicle-questions-mixin", () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm);
|
await wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
|
||||||
|
|
||||||
const questionsToTest = wrapper.vm.questionsData[1].questions;
|
const questionsToTest = wrapper.vm.questionsData[1].questions;
|
||||||
const answerLeadingToDuplicate = questionsToTest[0].answers[1];
|
const answerLeadingToDuplicate = questionsToTest[0].answers[1];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue