From e6b27f2098c453514cbe52bc645f61b38cb62310 Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Sat, 5 Nov 2022 20:28:08 -0400 Subject: [PATCH] CSR-803: prettify formatting changes --- .../question-chain/question-chain.vue | 2 +- .../capability-questions.vue | 59 +- .../molding-questions/molding-questions.vue | 47 +- src/layouts/part-questions/part-questions.vue | 59 +- src/mixins/vehicle-questions-mixin.js | 72 +- src/mixins/vehicle-questions-mixin.spec.js | 983 +++++++++--------- 6 files changed, 627 insertions(+), 595 deletions(-) diff --git a/src/common-components/question-chain/question-chain.vue b/src/common-components/question-chain/question-chain.vue index 7c9767d47..bc707f239 100644 --- a/src/common-components/question-chain/question-chain.vue +++ b/src/common-components/question-chain/question-chain.vue @@ -90,7 +90,7 @@ export default { "buttonId": "Driver-Front-1-1|answer|DD11132|Yes" } */ - + question.answerSelected = returnedAnswer; const isQuestionChainComplete = this.getQuestionChainAnswerIfComplete(returnedAnswer); diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index 0f7a0e57e..98ecc31f6 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -1,22 +1,16 @@ @@ -81,25 +75,30 @@ export default { // are there alreadyAnsweredQuestions? const alreadyAnsweredQuestions = store.getters.damage.capabilityQuestionAnswers; - this.questionsData = this.pageData.partsOrQuestions.filter((x) => x.capabilityQuestions).map((glass, i) => { - // NOTE: questions for property "questions" can differ between layouts - glass.questions = glass.capabilityQuestions; - glass.answerKey = glass.glassLocation + "-" + glass.glassName; - // reset selectedAnswers for this glass - this.selectedAnswers2[glass.answerKey] = []; + this.questionsData = this.pageData.partsOrQuestions + .filter((x) => x.capabilityQuestions) + .map((glass, i) => { + // NOTE: questions for property "questions" can differ between layouts + glass.questions = glass.capabilityQuestions; + glass.answerKey = glass.glassLocation + "-" + glass.glassName; + // reset selectedAnswers for this glass + this.selectedAnswers2[glass.answerKey] = []; - const updatedGlass = this.setupInitialData(glass, i, alreadyAnsweredQuestions); + const updatedGlass = this.setupInitialData(glass, i, alreadyAnsweredQuestions); - // Set up watch for each set of glass questions - this.$watch("selectedAnswers2." + glass.answerKey, (newValue) => { - if (newValue && Object.keys(newValue).length > 0) { - this.handleAnswerUpdates(newValue, glass.answerKey); - } - }, { deep: true }); - - return updatedGlass; - }); + // Set up watch for each set of glass questions + this.$watch( + "selectedAnswers2." + glass.answerKey, + (newValue) => { + if (newValue && Object.keys(newValue).length > 0) { + this.handleAnswerUpdates(newValue, glass.answerKey); + } + }, + { deep: true } + ); + return updatedGlass; + }); }, methods: { arePagePrerequisitesValid() { @@ -114,9 +113,13 @@ export default { const questionAnswersArray = this.questionsData.map((glass) => { // get answerResult2 of returned answer let selectedAnswerResult2; - glass.questions.forEach(q => { - const idx = q.answers.findIndex(a => a.answerResult === glass.answerData.answerResult); - if (idx !== -1) { selectedAnswerResult2 = q.answers[idx].answerResult2 } + glass.questions.forEach((q) => { + const idx = q.answers.findIndex( + (a) => a.answerResult === glass.answerData.answerResult + ); + if (idx !== -1) { + selectedAnswerResult2 = q.answers[idx].answerResult2; + } }); return { diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index 9f0362b44..3670f9cc1 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -1,22 +1,16 @@ @@ -81,24 +75,29 @@ export default { // are there alreadyAnsweredQuestions? const alreadyAnsweredQuestions = store.getters.damage.moldingQuestionAnswers; - this.questionsData = this.pageData.partsOrQuestions.filter(x => x.parts[0].childPartQuestions.length).map((glass, i) => { - // NOTE: questions for property "questions" can differ between layouts - glass.questions = glass.parts[0].childPartQuestions; - glass.answerKey = glass.glassLocation + "-" + glass.glassName; - // reset selectedAnswers for this glass - this.selectedAnswers2[glass.answerKey] = []; + this.questionsData = this.pageData.partsOrQuestions + .filter((x) => x.parts[0].childPartQuestions.length) + .map((glass, i) => { + // NOTE: questions for property "questions" can differ between layouts + glass.questions = glass.parts[0].childPartQuestions; + glass.answerKey = glass.glassLocation + "-" + glass.glassName; + // reset selectedAnswers for this glass + this.selectedAnswers2[glass.answerKey] = []; - const updatedGlass = this.setupInitialData(glass, i, alreadyAnsweredQuestions); + const updatedGlass = this.setupInitialData(glass, i, alreadyAnsweredQuestions); - this.$watch("selectedAnswers2." + glass.answerKey, (newValue) => { - if (newValue && Object.keys(newValue).length > 0) { - this.handleAnswerUpdates(newValue, glass.answerKey); - } - }, { deep: true }); - - return updatedGlass; - }); + this.$watch( + "selectedAnswers2." + glass.answerKey, + (newValue) => { + if (newValue && Object.keys(newValue).length > 0) { + this.handleAnswerUpdates(newValue, glass.answerKey); + } + }, + { deep: true } + ); + return updatedGlass; + }); }, methods: { arePagePrerequisitesValid() { diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index 02200585f..961fa825d 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -1,22 +1,16 @@ @@ -81,25 +75,30 @@ export default { // are there alreadyAnsweredQuestions? const alreadyAnsweredQuestions = store.getters.damage.partQuestionAnswers; - this.questionsData = this.pageData.partsOrQuestions.filter(x => x.partQuestions).map((glass, i) => { - // NOTE: questions for property "questions" can differ between layouts - glass.questions = glass.partQuestions; - glass.answerKey = glass.glassLocation + "-" + glass.glassName; - // reset selectedAnswers for this glass - this.selectedAnswers[glass.answerKey] = []; + this.questionsData = this.pageData.partsOrQuestions + .filter((x) => x.partQuestions) + .map((glass, i) => { + // NOTE: questions for property "questions" can differ between layouts + glass.questions = glass.partQuestions; + glass.answerKey = glass.glassLocation + "-" + glass.glassName; + // reset selectedAnswers for this glass + this.selectedAnswers[glass.answerKey] = []; - const updatedGlass = this.setupInitialData(glass, i, alreadyAnsweredQuestions); + const updatedGlass = this.setupInitialData(glass, i, alreadyAnsweredQuestions); - // Set up watch for each set of glass questions - this.$watch("selectedAnswers." + glass.answerKey, (newValue) => { - if (newValue && Object.keys(newValue).length > 0) { - this.handleAnswerUpdates(newValue, glass.answerKey); - } - }, {deep: true}); - - return updatedGlass; - }); + // Set up watch for each set of glass questions + this.$watch( + "selectedAnswers." + glass.answerKey, + (newValue) => { + if (newValue && Object.keys(newValue).length > 0) { + this.handleAnswerUpdates(newValue, glass.answerKey); + } + }, + { deep: true } + ); + return updatedGlass; + }); }, methods: { arePagePrerequisitesValid() { @@ -130,10 +129,11 @@ export default { ); // call API parts method - const partsLookup = await this.dispatchStoreAction(this.storeActions.GET_PARTS) - .catch(() => { + const partsLookup = await this.dispatchStoreAction(this.storeActions.GET_PARTS).catch( + () => { return this.$refs.funnelFooter.removeLoader(); - }); + } + ); const glassPiecePartsForStore = partsLookup.data.glassPieceParts; @@ -146,4 +146,3 @@ export default { }, }; - diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index a362ec2c6..2d16dd2e4 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -81,7 +81,9 @@ export default { !answeredGlass.glassName || !answeredGlass.answeredQuestions || (!answeredGlass.result && !answeredGlass.partNum) - ) { return } + ) { + return; + } // test if glass parts match if ( @@ -96,9 +98,12 @@ export default { return; } // determine which answer was previously chosen - const chosenAns = glass.questions[answeredQuestion.questionNum - 1].answers.find((a) => { + const chosenAns = glass.questions[ + answeredQuestion.questionNum - 1 + ].answers.find((a) => { return ( - a.answerText.toUpperCase() === answeredQuestion.selectedAnswerText.toUpperCase() + a.answerText.toUpperCase() === + answeredQuestion.selectedAnswerText.toUpperCase() ); }); // set the answerString to use for answerSelected @@ -109,10 +114,13 @@ export default { } // mark this question as answered (question-chain will read this) - glass.questions[answeredQuestion.questionNum - 1].answerSelected = answerString; + glass.questions[answeredQuestion.questionNum - 1].answerSelected = + answerString; // mark this question as suppressed if needed (question-chain uses this) if (answeredQuestion.suppressThisQuestion) { - glass.questions[answeredQuestion.questionNum - 1].suppressThisQuestion = true; + glass.questions[ + answeredQuestion.questionNum - 1 + ].suppressThisQuestion = true; } }); @@ -137,10 +145,10 @@ export default { handleAnswerUpdates(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 - // (does not get run for each invididual question's answer, only when + // (does not get run for each invididual question's answer, only when // all relevant questions for the current part have been answered) - /* answer example format: + /* answer example format: { "answerResult": "DD11132", "answeredQuestions": [ @@ -161,7 +169,6 @@ export default { // loop through every answered question on the currently answered glass part answer.answeredQuestions?.forEach((answeredQuestion) => { - /* answeredQuestion example format: { "questionText": "Is your Grand Cherokee the Laredo model?", @@ -177,7 +184,6 @@ export default { // loop through all glass pieces data self.questionsData.forEach((glassPiece, pieceIndex) => { - /* glassPiece example format: { "glassName": "Single", @@ -205,10 +211,9 @@ export default { "answerData": null } */ - + // limit duplicate search to glass pieces that follow after the currently being answered glass piece if (pieceIndex > answer.glassIndex) { - let indexToSuppressTo; // reset this glass piece, in case user is changing their previous answers glassPiece.answerData = null; @@ -216,7 +221,6 @@ export default { // loop through this glass piece's questions, looking for a questionText match glassPiece.questions.forEach((question, questionIndex) => { - // clear out any previously set answers question.answerSelected = null; @@ -244,10 +248,17 @@ export default { // handle duplicate's nextQuestion logic on other related questions if (matchedAnswer.nextQuestionSequence) { // clear any suppression on the nextQuestion - glassPiece.questions[matchedAnswer.nextQuestionSequence - 1].suppressThisQuestion = null; + glassPiece.questions[ + matchedAnswer.nextQuestionSequence - 1 + ].suppressThisQuestion = null; // if the duplicate is 1ST question in array, set indexToSuppressTo if (questionIndex === 0) { - if (!indexToSuppressTo || matchedAnswer.nextQuestionSequence < indexToSuppressTo) { indexToSuppressTo = matchedAnswer.nextQuestionSequence} + if ( + !indexToSuppressTo || + matchedAnswer.nextQuestionSequence < indexToSuppressTo + ) { + indexToSuppressTo = matchedAnswer.nextQuestionSequence; + } } } @@ -255,7 +266,10 @@ export default { glassPiece.questions.forEach((q) => { q.answers.forEach((a) => { // revert any previously set nextQuestion logic modifications - if (a.originalNextQuestionSequence === question.questionSequence) { + if ( + a.originalNextQuestionSequence === + question.questionSequence + ) { // restore original nextQuestionSequence a.nextQuestionSequence = a.originalNextQuestionSequence; self.originalNextQuestionSequence = null; @@ -271,18 +285,22 @@ export default { // update questions that lead to duplicated question if (matchedAnswer.nextQuestionSequence) { - a.originalNextQuestionSequence = a.nextQuestionSequence; - a.nextQuestionSequence = matchedAnswer.nextQuestionSequence; + a.originalNextQuestionSequence = + a.nextQuestionSequence; + a.nextQuestionSequence = + matchedAnswer.nextQuestionSequence; } else { - a.originalNextQuestionSequence = a.nextQuestionSequence; + a.originalNextQuestionSequence = + a.nextQuestionSequence; a.nextQuestionSequence = null; - a.originalAnswerResult = a.originalAnswerResult || a.answerResult; + a.originalAnswerResult = + a.originalAnswerResult || a.answerResult; a.answerResult = matchedAnswer.answerResult; } } }); }); - + // suppress current question question.suppressThisQuestion = true; @@ -303,30 +321,30 @@ export default { }; // set the answerData (used as indicator that it has been already answered) glassPiece.answerData = { - answerResult: matchedAnswer.nextQuestionSequence ? matchedAnswer.nextQuestionSequence : matchedAnswer.answerResult, + answerResult: matchedAnswer.nextQuestionSequence + ? matchedAnswer.nextQuestionSequence + : matchedAnswer.answerResult, answeredQuestions: [answeredQuestionObj], }; // suppress this glass piece because it has an answer glassPiece.isSuppressedPart = true; } - } }); // Update key to force re-render of glass piece with duplicate question in case user changes previous related answer in the chain - self.questionsData[pieceIndex].key = self.questionsData[pieceIndex].key + Date.now().toString(); + self.questionsData[pieceIndex].key = + self.questionsData[pieceIndex].key + Date.now().toString(); } - }); - }); // set final answer data for the current answered glass part self.questionsData[answer.glassIndex].answerData = { answerResult: answer.answerResult, answeredQuestions: answer.answeredQuestions, - } + }; // this part has been fully answered, so advance to next part's question chain for (let i = answer.glassIndex + 1; i < this.questionsData.length; i++) { @@ -336,7 +354,6 @@ export default { break; } } - }, // Can't use `this` because navigateForward is also called from vin-pages-mixin async navigateForward(partsOrQuestions, vm) { @@ -427,7 +444,6 @@ export default { { partsOrQuestions } ); } else { - // if single parts only const collectedGlassParts = this.reducedGlassPartsArray(partsOrQuestions); diff --git a/src/mixins/vehicle-questions-mixin.spec.js b/src/mixins/vehicle-questions-mixin.spec.js index 41ddc8ea2..4be7dec0f 100644 --- a/src/mixins/vehicle-questions-mixin.spec.js +++ b/src/mixins/vehicle-questions-mixin.spec.js @@ -364,7 +364,8 @@ describe("vehicle-questions-mixin", () => { questions: [ { questionSequence: 1, - questionText: "Does the rubber seal around your windshield have a chrome strip running through it?", + questionText: + "Does the rubber seal around your windshield have a chrome strip running through it?", answers: [ { answerResult: "WKT D1106 C", @@ -388,7 +389,8 @@ describe("vehicle-questions-mixin", () => { partNum: "WKT D1106 C", answeredQuestions: [ { - questionText: "Does the rubber seal around your windshield have a chrome strip running through it?", + questionText: + "Does the rubber seal around your windshield have a chrome strip running through it?", selectedAnswerText: "Yes", questionNum: 1, }, @@ -415,30 +417,30 @@ describe("vehicle-questions-mixin", () => { test("should be cleared to be empty", () => { // Arrange const answer = { - "answerResult": "DD11132", - "answeredQuestions": [ + answerResult: "DD11132", + answeredQuestions: [ { - "questionText": "Test duplicate question 1?", - "selectedAnswerText": "Yes", - "questionNum": 1, - } + questionText: "Test duplicate question 1?", + selectedAnswerText: "Yes", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); - wrapper.vm.selectedAnswers = { "test": "mockSelectedAnswers" }; + wrapper.vm.selectedAnswers = { test: "mockSelectedAnswers" }; wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "questions": [], - "answerData": "testAnswerData1" - } + glassLocation: "Windshield", + glassName: "Single", + questions: [], + answerData: "testAnswerData1", + }, ]; // Act - wrapper.vm.handleAnswerUpdates(answer, '', wrapper.vm); + wrapper.vm.handleAnswerUpdates(answer, "", wrapper.vm); // Assert expect(wrapper.vm.selectedAnswers).toMatchObject({}); @@ -449,35 +451,35 @@ describe("vehicle-questions-mixin", () => { test("should have answerData cleared", () => { // Arrange const answer = { - "answerResult": "DD11132", - "answeredQuestions": [ + answerResult: "DD11132", + answeredQuestions: [ { - "questionText": "Test duplicate question 1?", - "selectedAnswerText": "Yes", - "questionNum": 1, - } + questionText: "Test duplicate question 1?", + selectedAnswerText: "Yes", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "questions": [], - "answerData": "testAnswerData1" + glassLocation: "Windshield", + glassName: "Single", + questions: [], + answerData: "testAnswerData1", }, { - "glassLocation": "Driver", - "glassName": "Front", - "questions": [], - "answerData": "testAnswerData2" - } + glassLocation: "Driver", + glassName: "Front", + questions: [], + answerData: "testAnswerData2", + }, ]; // Act - wrapper.vm.handleAnswerUpdates(answer, '', wrapper.vm); + wrapper.vm.handleAnswerUpdates(answer, "", wrapper.vm); // Assert expect(wrapper.vm.questionsData[1].answerData).toEqual(null); @@ -485,36 +487,36 @@ describe("vehicle-questions-mixin", () => { test("should have isSuppressedPart cleared", () => { // Arrange const answer = { - "answerResult": "DD11132", - "answeredQuestions": [ + answerResult: "DD11132", + answeredQuestions: [ { - "questionText": "Test duplicate question 1?", - "selectedAnswerText": "Yes", - "questionNum": 1, - } + questionText: "Test duplicate question 1?", + selectedAnswerText: "Yes", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "questions": [], - "answerData": "testAnswerData1" + glassLocation: "Windshield", + glassName: "Single", + questions: [], + answerData: "testAnswerData1", }, { - "glassLocation": "Driver", - "glassName": "Front", - "questions": [], - "answerData": "testAnswerData2", - isSuppressedPart: true - } + glassLocation: "Driver", + glassName: "Front", + questions: [], + answerData: "testAnswerData2", + isSuppressedPart: true, + }, ]; // Act - wrapper.vm.handleAnswerUpdates(answer, '', wrapper.vm); + wrapper.vm.handleAnswerUpdates(answer, "", wrapper.vm); // Assert expect(wrapper.vm.questionsData[1].isSuppressedPart).toEqual(null); @@ -522,70 +524,72 @@ describe("vehicle-questions-mixin", () => { test("should set answerSelected for each glass part question to null ", () => { // Arrange const answer = { - "answerResult": "DD11132", - "answeredQuestions": [ + answerResult: "DD11132", + answeredQuestions: [ { - "questionText": "Test duplicate question 1?", - "selectedAnswerText": "Yes", - "questionNum": 1, - } + questionText: "Test duplicate question 1?", + selectedAnswerText: "Yes", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "questions": [], - "answerData": "testAnswerData1" + glassLocation: "Windshield", + glassName: "Single", + questions: [], + answerData: "testAnswerData1", }, { - "glassLocation": "Driver", - "glassName": "Front", - "questions": [ + glassLocation: "Driver", + glassName: "Front", + questions: [ { - "questionSequence": 1, - "questionText": "Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?", - "answers": [ + questionSequence: 1, + questionText: + "Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?", + answers: [ { - "answerResult": "", - "answerText": "Yes", - "nextQuestionSequence": 2 + answerResult: "", + answerText: "Yes", + nextQuestionSequence: 2, }, { - "answerResult": "", - "answerText": "No", - "nextQuestionSequence": 3 - } + answerResult: "", + answerText: "No", + nextQuestionSequence: 3, + }, ], - "answerSelected": "456" + answerSelected: "456", }, { - "questionSequence": 2, - "questionText": "Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?", - "answers": [ + questionSequence: 2, + questionText: + "Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?", + answers: [ { - "answerResult": "FW04848", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "FW04848", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "FW04846", - "answerText": "No", - "nextQuestionSequence": null - } + answerResult: "FW04846", + answerText: "No", + nextQuestionSequence: null, + }, ], - "answerSelected": "789" - } + answerSelected: "789", + }, ], - "answerData": "testAnswerData2" - } + answerData: "testAnswerData2", + }, ]; // Act - wrapper.vm.handleAnswerUpdates(answer, '', wrapper.vm); + wrapper.vm.handleAnswerUpdates(answer, "", wrapper.vm); // Assert expect(wrapper.vm.questionsData[1].questions[0].answerSelected).toEqual(null); @@ -594,250 +598,248 @@ describe("vehicle-questions-mixin", () => { }); describe("if there is a duplicate question", () => { - test("then the glass piece's key should be updated", () => { // Arrange const answerNo = { - "answerResult": "456", - "answeredQuestions": [ + answerResult: "456", + answeredQuestions: [ { - "questionText": "Test duplicate question 1?", - "selectedAnswerText": "No", - "questionNum": 1, - } + questionText: "Test duplicate question 1?", + selectedAnswerText: "No", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "key": "testkey1", - "questions": [ + glassLocation: "Windshield", + glassName: "Single", + key: "testkey1", + questions: [ { - "questionSequence": 1, - "questionText": "Test duplicate question 1?", - "answers": [ + questionSequence: 1, + questionText: "Test duplicate question 1?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "456", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "456", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, - ] + ], }, { - "glassLocation": "Driver", - "glassName": "Front", - "key": "testkey2", - "questions": [ + glassLocation: "Driver", + glassName: "Front", + key: "testkey2", + questions: [ { - "questionSequence": 1, - "questionText": "Test duplicate question 1?", - "answers": [ + questionSequence: 1, + questionText: "Test duplicate question 1?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "234", - "answerText": "No", - "nextQuestionSequence": null - } - ] - } - ] - } + answerResult: "234", + answerText: "No", + nextQuestionSequence: null, + }, + ], + }, + ], + }, ]; // Act - wrapper.vm.handleAnswerUpdates(answerNo, '', wrapper.vm); + wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm); const glassPieceWithDuplicate = wrapper.vm.questionsData[1]; // Assert expect(glassPieceWithDuplicate.key).not.toBe("testkey2"); }); - + test("then that question should be supressed", () => { // Arrange const answerNo = { - "answerResult": "456", - "answeredQuestions": [ + answerResult: "456", + answeredQuestions: [ { - "questionText": "Test duplicate question 1?", - "selectedAnswerText": "No", - "questionNum": 1, - } + questionText: "Test duplicate question 1?", + selectedAnswerText: "No", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "questions": [ + glassLocation: "Windshield", + glassName: "Single", + questions: [ { - "questionSequence": 1, - "questionText": "Test duplicate question 1?", - "answers": [ + questionSequence: 1, + questionText: "Test duplicate question 1?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "456", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "456", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, - ] + ], }, { - "glassLocation": "Driver", - "glassName": "Front", - "questions": [ + glassLocation: "Driver", + glassName: "Front", + questions: [ { - "questionSequence": 1, - "questionText": "Test duplicate question 1?", - "answers": [ + questionSequence: 1, + questionText: "Test duplicate question 1?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "234", - "answerText": "No", - "nextQuestionSequence": null - } - ] - } - ] - } + answerResult: "234", + answerText: "No", + nextQuestionSequence: null, + }, + ], + }, + ], + }, ]; // Act - wrapper.vm.handleAnswerUpdates(answerNo, '', wrapper.vm); + wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm); const duplicateQuestion = wrapper.vm.questionsData[1].questions[0]; // Assert expect(duplicateQuestion.suppressThisQuestion).toBeTruthy(); }); - + describe("and the duplicate has a nextQuestionSequence value", () => { - test("then the question set as nextQuestionSequence should not be suppressed", () => { // Arrange const answerNo = { - "answerResult": "456", - "answeredQuestions": [ + answerResult: "456", + answeredQuestions: [ { - "questionText": "Test duplicate question 1?", - "selectedAnswerText": "No", - "questionNum": 1, - } + questionText: "Test duplicate question 1?", + selectedAnswerText: "No", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); - + wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "questions": [ + glassLocation: "Windshield", + glassName: "Single", + questions: [ { - "questionSequence": 1, - "questionText": "Test duplicate question 1?", - "answers": [ + questionSequence: 1, + questionText: "Test duplicate question 1?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "456", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "456", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, - ] + ], }, { - "glassLocation": "Driver", - "glassName": "Front", - "questions": [ + glassLocation: "Driver", + glassName: "Front", + questions: [ { - "questionSequence": 1, - "questionText": "ZZZTest duplicate question 1?", - "answers": [ + questionSequence: 1, + questionText: "ZZZTest duplicate question 1?", + answers: [ { - "answerResult": "", - "answerText": "Yes", - "nextQuestionSequence": 2 + answerResult: "", + answerText: "Yes", + nextQuestionSequence: 2, }, { - "answerResult": "", - "answerText": "No", - "nextQuestionSequence": 3 - } - ] - }, - { - "questionSequence": 2, - "questionText": "Test question 2?", - "answers": [ - { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "", + answerText: "No", + nextQuestionSequence: 3, }, - { - "answerResult": "234", - "answerText": "No", - "nextQuestionSequence": null - } - ] - }, - { - "questionSequence": 3, - "questionText": "Test question 3?", - "answers": [ - { - "answerResult": "345", - "answerText": "Yes", - "nextQuestionSequence": null - }, - { - "answerResult": "456", - "answerText": "No", - "nextQuestionSequence": null - } ], - "suppressThisQuestion": true - } - ] - } + }, + { + questionSequence: 2, + questionText: "Test question 2?", + answers: [ + { + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, + }, + { + answerResult: "234", + answerText: "No", + nextQuestionSequence: null, + }, + ], + }, + { + questionSequence: 3, + questionText: "Test question 3?", + answers: [ + { + answerResult: "345", + answerText: "Yes", + nextQuestionSequence: null, + }, + { + answerResult: "456", + answerText: "No", + nextQuestionSequence: null, + }, + ], + suppressThisQuestion: true, + }, + ], + }, ]; - + // Act - wrapper.vm.handleAnswerUpdates(answerNo, '', wrapper.vm); + wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm); const nextQuestionAfterDuplicate = wrapper.vm.questionsData[1].questions[2]; - + // Assert expect(nextQuestionAfterDuplicate.suppressThisQuestion).not.toBeTruthy(); }); @@ -845,363 +847,376 @@ describe("vehicle-questions-mixin", () => { test("then the nextQuestionSequence should be updated and the original value saved", () => { // Arrange const answerNo = { - "answerResult": "456", - "answeredQuestions": [ + answerResult: "456", + answeredQuestions: [ { - "questionText": "Test question 3?", - "selectedAnswerText": "No", - "questionNum": 1, - } + questionText: "Test question 3?", + selectedAnswerText: "No", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); - + wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "questions": [ + glassLocation: "Windshield", + glassName: "Single", + questions: [ { - "questionSequence": 1, - "questionText": "Test question 3?", - "answers": [ + questionSequence: 1, + questionText: "Test question 3?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "456", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "456", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, - ] + ], }, { - "glassLocation": "Driver", - "glassName": "Front", - "questions": [ + glassLocation: "Driver", + glassName: "Front", + questions: [ { - "questionSequence": 1, - "questionText": "Test question 1?", - "answers": [ + questionSequence: 1, + questionText: "Test question 1?", + answers: [ { - "answerResult": "", - "answerText": "Yes", - "nextQuestionSequence": 2 + answerResult: "", + answerText: "Yes", + nextQuestionSequence: 2, }, { - "answerResult": "", - "answerText": "No", - "nextQuestionSequence": 3 - } - ] + answerResult: "", + answerText: "No", + nextQuestionSequence: 3, + }, + ], }, { - "questionSequence": 2, - "questionText": "Test question 2?", - "answers": [ + questionSequence: 2, + questionText: "Test question 2?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "234", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "234", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, { - "questionSequence": 3, - "questionText": "Test question 3?", - "answers": [ + questionSequence: 3, + questionText: "Test question 3?", + answers: [ { - "answerResult": "", - "answerText": "Yes", - "nextQuestionSequence": 4 + answerResult: "", + answerText: "Yes", + nextQuestionSequence: 4, }, { - "answerResult": "", - "answerText": "No", - "nextQuestionSequence": 5 - } - ] + answerResult: "", + answerText: "No", + nextQuestionSequence: 5, + }, + ], }, { - "questionSequence": 4, - "questionText": "Test question 4?", - "answers": [ + questionSequence: 4, + questionText: "Test question 4?", + answers: [ { - "answerResult": "567", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "567", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "678", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "678", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, { - "questionSequence": 5, - "questionText": "Test question 5?", - "answers": [ + questionSequence: 5, + questionText: "Test question 5?", + answers: [ { - "answerResult": "789", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "789", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "890", - "answerText": "No", - "nextQuestionSequence": null - } - ] - } - ] - } + answerResult: "890", + answerText: "No", + nextQuestionSequence: null, + }, + ], + }, + ], + }, ]; - + // Act - wrapper.vm.handleAnswerUpdates(answerNo, '', wrapper.vm); + wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm); const duplicatedQuestion = wrapper.vm.questionsData[1].questions[2]; - const duplicatedQuestionAnswer = duplicatedQuestion.answers.filter(a => { + const duplicatedQuestionAnswer = duplicatedQuestion.answers.filter((a) => { return a.selected; - }) - const answerToTest = wrapper.vm.questionsData[1].questions[0].answers.filter(a => { - return a.originalNextQuestionSequence; }); - + const answerToTest = wrapper.vm.questionsData[1].questions[0].answers.filter( + (a) => { + return a.originalNextQuestionSequence; + } + ); + // Assert - expect(answerToTest[0].originalNextQuestionSequence).toEqual(duplicatedQuestion.questionSequence); - expect(answerToTest[0].nextQuestionSequence).toEqual(duplicatedQuestionAnswer[0].nextQuestionSequence); + expect(answerToTest[0].originalNextQuestionSequence).toEqual( + duplicatedQuestion.questionSequence + ); + expect(answerToTest[0].nextQuestionSequence).toEqual( + duplicatedQuestionAnswer[0].nextQuestionSequence + ); }); describe("and the duplicate was the first question for that part", () => { - test("then any questions up to the nextQuestionSequence value should be marked as suppressed", () => { // Arrange const answerNo = { - "answerResult": "456", - "answeredQuestions": [ + answerResult: "456", + answeredQuestions: [ { - "questionText": "Test duplicate question 1?", - "selectedAnswerText": "No", - "questionNum": 1, - } + questionText: "Test duplicate question 1?", + selectedAnswerText: "No", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); - + wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "questions": [ + glassLocation: "Windshield", + glassName: "Single", + questions: [ { - "questionSequence": 1, - "questionText": "Test duplicate question 1?", - "answers": [ + questionSequence: 1, + questionText: "Test duplicate question 1?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "456", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "456", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, - ] + ], }, { - "glassLocation": "Driver", - "glassName": "Front", - "questions": [ + glassLocation: "Driver", + glassName: "Front", + questions: [ { - "questionSequence": 1, - "questionText": "Test duplicate question 1?", - "answers": [ + questionSequence: 1, + questionText: "Test duplicate question 1?", + answers: [ { - "answerResult": "", - "answerText": "Yes", - "nextQuestionSequence": 2 + answerResult: "", + answerText: "Yes", + nextQuestionSequence: 2, }, { - "answerResult": "", - "answerText": "No", - "nextQuestionSequence": 3 - } - ] + answerResult: "", + answerText: "No", + nextQuestionSequence: 3, + }, + ], }, { - "questionSequence": 2, - "questionText": "Test question 2?", - "answers": [ + questionSequence: 2, + questionText: "Test question 2?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "234", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "234", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, { - "questionSequence": 3, - "questionText": "Test question 3?", - "answers": [ + questionSequence: 3, + questionText: "Test question 3?", + answers: [ { - "answerResult": "345", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "345", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "456", - "answerText": "No", - "nextQuestionSequence": null - } - ] - } - ] - } + answerResult: "456", + answerText: "No", + nextQuestionSequence: null, + }, + ], + }, + ], + }, ]; - + // Act - wrapper.vm.handleAnswerUpdates(answerNo, '', wrapper.vm); - + wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm); + // Assert - expect(wrapper.vm.questionsData[1].questions[0].suppressThisQuestion).toBeTruthy(); - expect(wrapper.vm.questionsData[1].questions[1].suppressThisQuestion).toBeTruthy(); - expect(wrapper.vm.questionsData[1].questions[2].suppressThisQuestion).toBeFalsy(); + expect( + wrapper.vm.questionsData[1].questions[0].suppressThisQuestion + ).toBeTruthy(); + expect( + wrapper.vm.questionsData[1].questions[1].suppressThisQuestion + ).toBeTruthy(); + expect( + wrapper.vm.questionsData[1].questions[2].suppressThisQuestion + ).toBeFalsy(); }); - }); - }); describe("and the duplicate has an answerResult", () => { test("then any questions in the same glass piece that lead to the duplicate should be modified to just provide the duplicate's answerResult", async () => { // Arrange const answerNo = { - "answerResult": "456", - "answeredQuestions": [ + answerResult: "456", + answeredQuestions: [ { - "questionText": "Test question 3?", - "selectedAnswerText": "No", - "questionNum": 1, - } + questionText: "Test question 3?", + selectedAnswerText: "No", + questionNum: 1, + }, ], - "glassIndex": 0 + glassIndex: 0, }; const { wrapper } = setupMocks({}); - + wrapper.vm.questionsData = [ { - "glassLocation": "Windshield", - "glassName": "Single", - "questions": [ + glassLocation: "Windshield", + glassName: "Single", + questions: [ { - "questionSequence": 1, - "questionText": "Test question 3?", - "answers": [ + questionSequence: 1, + questionText: "Test question 3?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "456", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "456", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, - ] + ], }, { - "glassLocation": "Driver", - "glassName": "Front", - "questions": [ + glassLocation: "Driver", + glassName: "Front", + questions: [ { - "questionSequence": 1, - "questionText": "Test question 1?", - "answers": [ + questionSequence: 1, + questionText: "Test question 1?", + answers: [ { - "answerResult": "", - "answerText": "Yes", - "nextQuestionSequence": 2 + answerResult: "", + answerText: "Yes", + nextQuestionSequence: 2, }, { - "answerResult": "", - "answerText": "No", - "nextQuestionSequence": 3 - } - ] + answerResult: "", + answerText: "No", + nextQuestionSequence: 3, + }, + ], }, { - "questionSequence": 2, - "questionText": "Test question 2?", - "answers": [ + questionSequence: 2, + questionText: "Test question 2?", + answers: [ { - "answerResult": "123", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "123", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "234", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "234", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, { - "questionSequence": 3, - "questionText": "Test question 3?", - "answers": [ + questionSequence: 3, + questionText: "Test question 3?", + answers: [ { - "answerResult": "345", - "answerText": "Yes", - "nextQuestionSequence": null + answerResult: "345", + answerText: "Yes", + nextQuestionSequence: null, }, { - "answerResult": "456", - "answerText": "No", - "nextQuestionSequence": null - } - ] + answerResult: "456", + answerText: "No", + nextQuestionSequence: null, + }, + ], }, - ] - } + ], + }, ]; - + // Act - await wrapper.vm.handleAnswerUpdates(answerNo, '', wrapper.vm); - + await wrapper.vm.handleAnswerUpdates(answerNo, "", wrapper.vm); + const questionsToTest = wrapper.vm.questionsData[1].questions; const answerLeadingToDuplicate = questionsToTest[0].answers[1]; const duplicateQuestion = questionsToTest[2]; - const answerInDuplicateQuestion = duplicateQuestion.answers.filter(a => { + const answerInDuplicateQuestion = duplicateQuestion.answers.filter((a) => { return a.selected; - }) - + }); + // Assert - expect(answerLeadingToDuplicate.answerResult).toEqual(answerInDuplicateQuestion[0].answerResult); + expect(answerLeadingToDuplicate.answerResult).toEqual( + answerInDuplicateQuestion[0].answerResult + ); expect(answerLeadingToDuplicate.originalAnswerResult).toBeFalsy(); expect(answerLeadingToDuplicate.nextQuestionSequence).toEqual(null); - expect(answerLeadingToDuplicate.originalNextQuestionSequence).toEqual(duplicateQuestion.questionSequence); + expect(answerLeadingToDuplicate.originalNextQuestionSequence).toEqual( + duplicateQuestion.questionSequence + ); }); }); });