From e35fe3fb1b619d1bbff1426caf5d7c72ad79c42c Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Thu, 11 Jan 2024 07:48:49 -0500 Subject: [PATCH 1/2] CSR-1610: copy fix updates into other question pages --- .../capability-questions.vue | 7 ++- .../molding-questions/molding-questions.vue | 7 ++- src/layouts/part-questions/part-questions.vue | 6 +- src/mixins/vehicle-questions-mixin.js | 9 +++ src/mixins/vehicle-questions-mixin.spec.js | 55 +++++++++++++++++++ 5 files changed, 77 insertions(+), 7 deletions(-) diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index 717865e41..e02035804 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -5,11 +5,13 @@ :isMetaValid="meta.valid" :alertFewMoreQuestionsHeader="AlertFewMoreQuestionsHeader" :alertFewMoreQuestionsCopy="AlertFewMoreQuestionsCopy" + v-if="questionsData" :questionsData="questionsData" validationRules="questions-required" v-model="selectedAnswers" @forwardButtonAction="forwardButtonAction" @back-click="navigateBack" + :key="currentGlassIndex" :index="currentGlassIndex" /> @@ -55,7 +57,7 @@ export default { }, data() { return { - questionsData: [], + questionsData: null, selectedAnswers: {}, currentGlassIndex: 0, }; @@ -120,6 +122,9 @@ export default { return updatedGlass; }); + + // if no preanswered questions then make sure index starts with the correct value + this.currentGlassIndex = this.calculateQuestionIndex(this.currentGlassIndex, this.questionsData); }, async forwardButtonAction() { const questionAnswersArray = this.questionsData.map((glass) => { diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index ee1b33a9f..243919447 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -5,11 +5,13 @@ :isMetaValid="meta.valid" :alertFewMoreQuestionsHeader="AlertFewMoreQuestionsHeader" :alertFewMoreQuestionsCopy="AlertFewMoreQuestionsCopy" + v-if="questionsData" :questionsData="questionsData" validationRules="questions-required" v-model="selectedAnswers" @forwardButtonAction="forwardButtonAction" @back-click="navigateBack" + :key="currentGlassIndex" :index="currentGlassIndex" /> @@ -55,7 +57,7 @@ export default { }, data() { return { - questionsData: [], + questionsData: null, selectedAnswers: {}, currentGlassIndex: 0, }; @@ -119,6 +121,9 @@ export default { return updatedGlass; }); + + // if no preanswered questions then make sure index starts with the correct value + this.currentGlassIndex = this.calculateQuestionIndex(this.currentGlassIndex, this.questionsData); }, async forwardButtonAction() { const questionAnswersArray = this.questionsData.map((glass) => { diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index d9fbd369d..de3792d97 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -121,11 +121,7 @@ export default { }); // if no preanswered questions then make sure index starts with the correct value - if (this.currentGlassIndex === 0) { - this.currentGlassIndex = this.questionsData?.findIndex( - (glass) => glass.questions?.length > 0 - ); - } + this.currentGlassIndex = this.calculateQuestionIndex(this.currentGlassIndex, this.questionsData); }, async forwardButtonAction() { const questionAnswersArray = this.questionsData.map((glass) => { diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index d79e4f5b3..9614baf66 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -146,6 +146,15 @@ export default { return glass; }, + calculateQuestionIndex(currentGlassIndex, questionsData) { + // if no preanswered questions then make sure index starts with the correct value + if (currentGlassIndex === 0) { + return questionsData?.findIndex( + (glass) => glass.questions?.length > 0 + ); + } + return currentGlassIndex; + }, handleCompletedQuestionChainAnswers(answer, glassKey, vm) { // 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 diff --git a/src/mixins/vehicle-questions-mixin.spec.js b/src/mixins/vehicle-questions-mixin.spec.js index f87d7efdc..5d0153e7b 100644 --- a/src/mixins/vehicle-questions-mixin.spec.js +++ b/src/mixins/vehicle-questions-mixin.spec.js @@ -411,6 +411,61 @@ describe("vehicle-questions-mixin", () => { }); }); + describe("calculateQuestionIndex", () => { + describe("if currentGlassIndex is zero...", () => { + test("should return index of first glass piece with questions", () => { + // Arrange + const questionsData = [ + { + glassName: "Single", + glassLocation: "Windshield", + }, + { + glassName: "Front", + glassLocation: "Driver", + questions: [ + "example question" + ] + }, + ]; + const glassIndex = 0; + const { wrapper } = setupMocks({}); + + // Act + const returnedIndex = wrapper.vm.calculateQuestionIndex(glassIndex, questionsData); + + // Assert + expect(returnedIndex).toBe(1); + }); + }); + describe("if currentGlassIndex is NOT zero...", () => { + test("should return currentGlassIndex value", () => { + // Arrange + const questionsData = [ + { + glassName: "Single", + glassLocation: "Windshield", + }, + { + glassName: "Front", + glassLocation: "Driver", + questions: [ + "example question" + ] + }, + ]; + const glassIndex = 1; + const { wrapper } = setupMocks({}); + + // Act + const returnedIndex = wrapper.vm.calculateQuestionIndex(glassIndex, questionsData); + + // Assert + expect(returnedIndex).toBe(1); + }); + }); + }); + describe("handleCompletedQuestionChainAnswers", () => { describe("selectedAnswers", () => { test("should be cleared to be empty", () => { From 2fbc4e3bd589ed6046e1f59554041ae0b84dccf5 Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Thu, 11 Jan 2024 11:10:12 -0500 Subject: [PATCH 2/2] CSR-1610: prettier 'fixes' --- src/layouts/capability-questions/capability-questions.vue | 5 ++++- src/layouts/molding-questions/molding-questions.vue | 5 ++++- src/layouts/part-questions/part-questions.vue | 5 ++++- src/mixins/vehicle-questions-mixin.js | 4 +--- src/mixins/vehicle-questions-mixin.spec.js | 8 ++------ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index e02035804..e46629bf1 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -124,7 +124,10 @@ export default { }); // if no preanswered questions then make sure index starts with the correct value - this.currentGlassIndex = this.calculateQuestionIndex(this.currentGlassIndex, this.questionsData); + this.currentGlassIndex = this.calculateQuestionIndex( + this.currentGlassIndex, + this.questionsData + ); }, async forwardButtonAction() { const questionAnswersArray = this.questionsData.map((glass) => { diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index 243919447..b2d6804bc 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -123,7 +123,10 @@ export default { }); // if no preanswered questions then make sure index starts with the correct value - this.currentGlassIndex = this.calculateQuestionIndex(this.currentGlassIndex, this.questionsData); + this.currentGlassIndex = this.calculateQuestionIndex( + this.currentGlassIndex, + this.questionsData + ); }, async forwardButtonAction() { const questionAnswersArray = this.questionsData.map((glass) => { diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index de3792d97..9f4a13902 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -121,7 +121,10 @@ export default { }); // if no preanswered questions then make sure index starts with the correct value - this.currentGlassIndex = this.calculateQuestionIndex(this.currentGlassIndex, this.questionsData); + this.currentGlassIndex = this.calculateQuestionIndex( + this.currentGlassIndex, + this.questionsData + ); }, async forwardButtonAction() { const questionAnswersArray = this.questionsData.map((glass) => { diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index 9614baf66..d0fd9dd1b 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -149,9 +149,7 @@ export default { calculateQuestionIndex(currentGlassIndex, questionsData) { // if no preanswered questions then make sure index starts with the correct value if (currentGlassIndex === 0) { - return questionsData?.findIndex( - (glass) => glass.questions?.length > 0 - ); + return questionsData?.findIndex((glass) => glass.questions?.length > 0); } return currentGlassIndex; }, diff --git a/src/mixins/vehicle-questions-mixin.spec.js b/src/mixins/vehicle-questions-mixin.spec.js index 5d0153e7b..56f4425cc 100644 --- a/src/mixins/vehicle-questions-mixin.spec.js +++ b/src/mixins/vehicle-questions-mixin.spec.js @@ -423,9 +423,7 @@ describe("vehicle-questions-mixin", () => { { glassName: "Front", glassLocation: "Driver", - questions: [ - "example question" - ] + questions: ["example question"], }, ]; const glassIndex = 0; @@ -449,9 +447,7 @@ describe("vehicle-questions-mixin", () => { { glassName: "Front", glassLocation: "Driver", - questions: [ - "example question" - ] + questions: ["example question"], }, ]; const glassIndex = 1;