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', () => {