Changed Map to forEach and created unit test
This commit is contained in:
parent
6b1019eea6
commit
216848f7a3
2 changed files with 75 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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', () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue