From 5645139c74f78d9120eea30343cd7f784bc9592c Mon Sep 17 00:00:00 2001 From: Kirkland Brown Date: Mon, 8 Jul 2024 10:22:32 -0400 Subject: [PATCH 1/6] Updating QuestionData answer to match Question answer during deletion --- src/digital-components/question-chain/question-chain.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/digital-components/question-chain/question-chain.vue b/src/digital-components/question-chain/question-chain.vue index 5f72221f..217c6dcb 100644 --- a/src/digital-components/question-chain/question-chain.vue +++ b/src/digital-components/question-chain/question-chain.vue @@ -123,7 +123,7 @@ export default { const answeredQuestions = []; // TODO: This forEach could probably be converted into something more reactive - this.questions.forEach((q) => { + this.questions.forEach((q, index) => { // find this question and mark it as "answered" by populating answerSelected if (q.questionSequence === questionNum) { q.answerSelected = returnedAnswer; @@ -134,6 +134,7 @@ export default { // (needed in case user is changing previously answered questions) if (q.questionSequence > questionNum) { delete q.answerSelected; + delete this.questionData[index].answerSelected; } if (q.answerSelected) { answeredQuestions.push({ From fbfd196da140ff93a56413a1ebff8017ce317c99 Mon Sep 17 00:00:00 2001 From: Kirkland Brown Date: Wed, 10 Jul 2024 10:17:34 -0400 Subject: [PATCH 2/6] Reverted changes to question-chain and force matched the part questions before committing to mainStore --- src/digital-components/question-chain/question-chain.vue | 3 +-- src/layouts/part-questions/part-questions.vue | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/digital-components/question-chain/question-chain.vue b/src/digital-components/question-chain/question-chain.vue index 217c6dcb..5f72221f 100644 --- a/src/digital-components/question-chain/question-chain.vue +++ b/src/digital-components/question-chain/question-chain.vue @@ -123,7 +123,7 @@ export default { const answeredQuestions = []; // TODO: This forEach could probably be converted into something more reactive - this.questions.forEach((q, index) => { + this.questions.forEach((q) => { // find this question and mark it as "answered" by populating answerSelected if (q.questionSequence === questionNum) { q.answerSelected = returnedAnswer; @@ -134,7 +134,6 @@ export default { // (needed in case user is changing previously answered questions) if (q.questionSequence > questionNum) { delete q.answerSelected; - delete this.questionData[index].answerSelected; } if (q.answerSelected) { answeredQuestions.push({ diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index 286008c8..d20d15c4 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -126,6 +126,11 @@ export default { ); }, async forwardButtonAction() { + // match partQuestionAnswers to answerData + const questionNums = new Set(this.questionsData[0].answerData.answeredQuestions.map(obj => obj.questionNum)); + this.questionsData.partQuestions = this.questionsData[0].partQuestions.map(obj => {if(!questionNums.has(obj.questionSequence)) delete obj.answerSelected}); + this.questionsData.partQuestions = this.questionsData[0].questions.map(obj => {if(!questionNums.has(obj.questionSequence)) delete obj.answerSelected}); + const questionAnswersArray = this.questionsData.map((glass) => ({ glassLocation: glass.glassLocation, glassName: glass.glassName, From 9a2cef5bf3f2750a5131c1cb44a47c1758ebbb7c Mon Sep 17 00:00:00 2001 From: Kirkland Brown Date: Wed, 10 Jul 2024 11:44:58 -0400 Subject: [PATCH 3/6] removing unnecessary data syncing --- src/layouts/part-questions/part-questions.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index d20d15c4..5198e401 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -129,7 +129,6 @@ export default { // match partQuestionAnswers to answerData const questionNums = new Set(this.questionsData[0].answerData.answeredQuestions.map(obj => obj.questionNum)); this.questionsData.partQuestions = this.questionsData[0].partQuestions.map(obj => {if(!questionNums.has(obj.questionSequence)) delete obj.answerSelected}); - this.questionsData.partQuestions = this.questionsData[0].questions.map(obj => {if(!questionNums.has(obj.questionSequence)) delete obj.answerSelected}); const questionAnswersArray = this.questionsData.map((glass) => ({ glassLocation: glass.glassLocation, From c54294eb8787cfa250ae9a6dc8f6acb4ddcd78a2 Mon Sep 17 00:00:00 2001 From: Kirkland Brown Date: Mon, 15 Jul 2024 10:15:40 -0400 Subject: [PATCH 4/6] Refactored --- src/layouts/part-questions/part-questions.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index 5198e401..7dd217c4 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -128,7 +128,11 @@ export default { async forwardButtonAction() { // match partQuestionAnswers to answerData const questionNums = new Set(this.questionsData[0].answerData.answeredQuestions.map(obj => obj.questionNum)); - this.questionsData.partQuestions = this.questionsData[0].partQuestions.map(obj => {if(!questionNums.has(obj.questionSequence)) delete obj.answerSelected}); + this.questionsData[0].partQuestions.map(obj => { + if(!questionNums.has(obj.questionSequence)) { + delete obj.answerSelected + } + }); const questionAnswersArray = this.questionsData.map((glass) => ({ glassLocation: glass.glassLocation, From 6b1019eea68201ae36b18da29ae5e4c150cef1d7 Mon Sep 17 00:00:00 2001 From: Kirkland Brown Date: Thu, 18 Jul 2024 12:13:14 -0400 Subject: [PATCH 5/6] Corrected location to put logic --- src/layouts/part-questions/part-questions.vue | 8 -------- src/mixins/vehicle-questions-mixin.js | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index 7dd217c4..286008c8 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -126,14 +126,6 @@ export default { ); }, async forwardButtonAction() { - // match partQuestionAnswers to answerData - const questionNums = new Set(this.questionsData[0].answerData.answeredQuestions.map(obj => obj.questionNum)); - this.questionsData[0].partQuestions.map(obj => { - if(!questionNums.has(obj.questionSequence)) { - delete obj.answerSelected - } - }); - const questionAnswersArray = this.questionsData.map((glass) => ({ glassLocation: glass.glassLocation, glassName: glass.glassName, diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index c19984d3..2b9edd35 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -118,6 +118,14 @@ export default { } }); + // remove any disabled dependent answers + const answerQuestionNums = new Set(alreadyAnsweredQuestions[alreadyAnsweredQuestions.length-1].answeredQuestions.map(q => q.questionNum)); + glass.questions.map(q => { + if(!answerQuestionNums.has(q.questionSequence)) { + delete q.answerSelected + } + }); + // advance the currentGlassIndex self.currentGlassIndex = index; From 216848f7a3582bd2abfb452da7d91f7b75a3b2f0 Mon Sep 17 00:00:00 2001 From: Kirkland Brown Date: Thu, 18 Jul 2024 14:25:53 -0400 Subject: [PATCH 6/6] Changed Map to forEach and created unit test --- src/mixins/vehicle-questions-mixin.js | 2 +- src/mixins/vehicle-questions-mixin.spec.js | 74 ++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index 2b9edd35..76964e08 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -120,7 +120,7 @@ export default { // remove any disabled dependent answers const answerQuestionNums = new Set(alreadyAnsweredQuestions[alreadyAnsweredQuestions.length-1].answeredQuestions.map(q => q.questionNum)); - glass.questions.map(q => { + glass.questions.forEach(q => { if(!answerQuestionNums.has(q.questionSequence)) { delete q.answerSelected } diff --git a/src/mixins/vehicle-questions-mixin.spec.js b/src/mixins/vehicle-questions-mixin.spec.js index 0a4917ff..caa4fac6 100644 --- a/src/mixins/vehicle-questions-mixin.spec.js +++ b/src/mixins/vehicle-questions-mixin.spec.js @@ -445,6 +445,80 @@ describe('vehicle-questions-mixin', () => { expect(returnedGlass.answerData).toMatchObject({ answerResult: 'WKT D1106 C' }); }); }); + + describe('if alreadyAnsweredQuestions and dependent question has been disabled', () => { + test('should return glass with the answerSelected of partQuestions and questions reflecting the answerData (previous context is being updated to reflect answerData)', async () => { + // Arrange + const glass = { + glassName: 'Single', + glassLocation: 'Windshield', + questions: [ + { + questionSequence: 1, + questionText: + 'Is your vehicle equipped with leather seats?', + answers: [ + { + answerResult: 'FW02334', + answerText: 'Yes', + nextQuestionSequence: null + }, + { + answerResult: '', + answerText: 'No', + nextQuestionSequence: 2 + } + ] + }, + { + questionSequence: 2, + questionText: + 'Is your vehicle equipped with heated seats?', + answers: [ + { + answerResult: 'FW02334', + answerText: 'Yes', + nextQuestionSequence: null + }, + { + answerResult: 'FW02333', + answerText: 'No', + nextQuestionSequence: null + } + ] + } + ] + }; + const i = 0; + const alreadyAnsweredQuestions = [ + { + glassLocation: 'Windshield', + glassName: 'Single', + partNum: 'FW02334', + answeredQuestions: [ + { + questionText: + 'Is your vehicle equipped with leather seats?', + selectedAnswerText: 'Yes', + questionNum: 1 + } + ] + } + ]; + const { wrapper } = setupMocks({}); + + // Act + const returnedGlass = await wrapper.vm.setupInitialData( + glass, + i, + alreadyAnsweredQuestions + ); + + // Assert + expect(returnedGlass.questions[0].answerSelected).toEqual('1|answer|FW02334|Yes'); + expect(returnedGlass.questions[1].answerSelected).toBeUndefined(); + }); + }); }); describe('handleAnswerUpdates', () => {