2127 lines
90 KiB
JavaScript
2127 lines
90 KiB
JavaScript
import vehicleQuestionsMixin from '@/mixins/vehicle-questions-mixin';
|
|
import { shallowMount } from '@vue/test-utils';
|
|
import { setupMocksForJsFiles, getMountOptions } from '@/helpers/unit-test-helper.js';
|
|
import { issPageValues } from '@/router/router-constants/issPage-values';
|
|
import { navigationScenarios } from '@/router/router-constants/navigation-scenarios';
|
|
import { useMainStore } from '@/store';
|
|
|
|
describe('vehicle-questions-mixin', () => {
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
describe('hasPartQuestions', () => {
|
|
test('has no part questions => return false', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasPartQuestions = wrapper.vm.hasPartQuestions([
|
|
{
|
|
partQuestions: []
|
|
}
|
|
]);
|
|
|
|
// Assert
|
|
expect(hasPartQuestions).toBe(false);
|
|
});
|
|
|
|
test('has undefined part questions => return false', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasPartQuestions = wrapper.vm.hasPartQuestions([]);
|
|
|
|
// Assert
|
|
expect(hasPartQuestions).toBe(false);
|
|
});
|
|
|
|
test('has part questions => return true', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasPartQuestions = wrapper.vm.hasPartQuestions([
|
|
{
|
|
partQuestions: [
|
|
{
|
|
testProperty: 'some value'
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
// Assert
|
|
expect(hasPartQuestions).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('hasGlassLocationWithMultipleParts', () => {
|
|
test('has one part for one glass location => return false', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasGlassLocationWithMultipleParts = wrapper.vm.hasGlassLocationWithMultipleParts([
|
|
{
|
|
glassName: 'Something',
|
|
glassLocation: 'somewhere',
|
|
parts: [
|
|
{
|
|
partNumber: '1234567'
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
// Assert
|
|
expect(hasGlassLocationWithMultipleParts).toBe(false);
|
|
});
|
|
|
|
test('has one part for every glass location => return false', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasGlassLocationWithMultipleParts = wrapper.vm.hasGlassLocationWithMultipleParts([
|
|
{
|
|
glassName: 'Something',
|
|
glassLocation: 'somewhere',
|
|
parts: [
|
|
{
|
|
partNumber: '1234567'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassName: 'Another glass',
|
|
glassLocation: 'somewhere else',
|
|
parts: [
|
|
{
|
|
partNumber: '1234568'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassName: 'Special glass',
|
|
glassLocation: 'Another where',
|
|
parts: [
|
|
{
|
|
partNumber: '1234569'
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
// Assert
|
|
expect(hasGlassLocationWithMultipleParts).toBe(false);
|
|
});
|
|
|
|
test('has multiple parts for one glass location => return true', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasGlassLocationWithMultipleParts = wrapper.vm.hasGlassLocationWithMultipleParts([
|
|
{
|
|
glassName: 'Something',
|
|
glassLocation: 'somewhere',
|
|
parts: [
|
|
{
|
|
partNumber: '1234567'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassName: 'Another glass',
|
|
glassLocation: 'somewhere else',
|
|
parts: [
|
|
{
|
|
partNumber: '1234568'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassName: 'Special glass',
|
|
glassLocation: 'Another where',
|
|
parts: [
|
|
{
|
|
partNumber: '1234569'
|
|
},
|
|
{
|
|
partNumber: '1234560'
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
// Assert
|
|
expect(hasGlassLocationWithMultipleParts).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('hasChildPartQuestions', () => {
|
|
test('has no child part questions => return false', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasChildPartQuestions = wrapper.vm.hasChildPartQuestions([
|
|
{
|
|
parts: [
|
|
{
|
|
childPartQuestions: []
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
// Assert
|
|
expect(hasChildPartQuestions).toBe(false);
|
|
});
|
|
|
|
test('has undefined child part questions => return false', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasChildPartQuestions = wrapper.vm.hasChildPartQuestions([]);
|
|
|
|
// Assert
|
|
expect(hasChildPartQuestions).toBe(false);
|
|
});
|
|
|
|
test('has child part questions => return true', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasChildPartQuestions = wrapper.vm.hasChildPartQuestions([
|
|
{
|
|
parts: [
|
|
{
|
|
childPartQuestions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
'Does the rubber seal around your windshield have a chrome strip running through it?',
|
|
answers: [
|
|
{
|
|
answerResult: 'WKT D1106 C',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: 'WKT D1106 B',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
// Assert
|
|
expect(hasChildPartQuestions).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('hasCapabilityQuestions', () => {
|
|
test('has no capability questions => return false', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasCapabilityQuestions = wrapper.vm.hasCapabilityQuestions([
|
|
{
|
|
parts: [
|
|
{
|
|
requiresCapabilityQuestions: false
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
// Assert
|
|
expect(hasCapabilityQuestions).toBe(false);
|
|
});
|
|
|
|
test('has undefined capability questions => return false', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasCapabilityQuestions = wrapper.vm.hasCapabilityQuestions([]);
|
|
|
|
// Assert
|
|
expect(hasCapabilityQuestions).toBe(false);
|
|
});
|
|
|
|
test('has capability questions => return true', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const hasCapabilityQuestions = wrapper.vm.hasCapabilityQuestions([
|
|
{
|
|
parts: [
|
|
{
|
|
requiresCapabilityQuestions: true
|
|
}
|
|
]
|
|
}
|
|
]);
|
|
|
|
// Assert
|
|
expect(hasCapabilityQuestions).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('currentPageComesBeforePage', () => {
|
|
const testCases = [
|
|
[issPageValues.PART_QUESTIONS, issPageValues.VEHICLE_PARTS, true],
|
|
[issPageValues.VEHICLE_PARTS, issPageValues.VEHICLE_PARTS, false],
|
|
[issPageValues.VEHICLE_PARTS, issPageValues.REVEAL, false],
|
|
[issPageValues.VEHICLE_PARTS, issPageValues.PART_QUESTIONS, false],
|
|
[issPageValues.PART_QUESTIONS, issPageValues.CAPABILITY_QUESTIONS, true],
|
|
[issPageValues.MOLDING_QUESTIONS, issPageValues.CAPABILITY_QUESTIONS, true]
|
|
];
|
|
test.each(testCases)('%s comes before %s is %s',
|
|
(currentPage, nextPage, expectedResult) => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const result = wrapper.vm.currentPageComesBeforePage(currentPage, nextPage);
|
|
|
|
// Assert
|
|
expect(result).toEqual(expectedResult);
|
|
});
|
|
});
|
|
|
|
describe('currentPageComesAfterPage', () => {
|
|
const testCases = [
|
|
[issPageValues.PART_QUESTIONS, issPageValues.VEHICLE_PARTS, false],
|
|
[issPageValues.VEHICLE_PARTS, issPageValues.VEHICLE_PARTS, false],
|
|
[issPageValues.VEHICLE_PARTS, issPageValues.SERVICE_LOCATION, true],
|
|
[issPageValues.VEHICLE_PARTS, issPageValues.PART_QUESTIONS, true],
|
|
[issPageValues.PART_QUESTIONS, issPageValues.CAPABILITY_QUESTIONS, false],
|
|
[issPageValues.MOLDING_QUESTIONS, issPageValues.CAPABILITY_QUESTIONS, false]
|
|
];
|
|
test.each(testCases)('%s comes after %s is %s', (currentPage, nextPage, expectedResult) => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const result = wrapper.vm.currentPageComesAfterPage(currentPage, nextPage);
|
|
|
|
// Assert
|
|
expect(result).toEqual(expectedResult);
|
|
});
|
|
});
|
|
|
|
describe('setupInitialData', () => {
|
|
describe('if no alreadyAnsweredQuestions', () => {
|
|
test('should return glass with answerData of null', async () => {
|
|
// Arrange
|
|
const glass = {
|
|
glassName: 'Single',
|
|
glassLocation: 'Windshield'
|
|
};
|
|
const i = 0;
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const returnedGlass = await wrapper.vm.setupInitialData(glass, i);
|
|
|
|
// Assert
|
|
expect(returnedGlass).toMatchObject({ answerData: null });
|
|
});
|
|
});
|
|
|
|
describe('if alreadyAnsweredQuestions', () => {
|
|
test('should return glass with answerResult within answerData', async () => {
|
|
// Arrange
|
|
const glass = {
|
|
glassName: 'Single',
|
|
glassLocation: 'Windshield',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
'Does the rubber seal around your windshield have a chrome strip running through it?',
|
|
answers: [
|
|
{
|
|
answerResult: 'WKT D1106 C',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: 'WKT D1106 B',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
};
|
|
const i = 0;
|
|
const alreadyAnsweredQuestions = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
partNum: 'WKT D1106 C',
|
|
answeredQuestions: [
|
|
{
|
|
questionText:
|
|
'Does the rubber seal around your windshield have a chrome strip running through it?',
|
|
selectedAnswerText: 'Yes',
|
|
questionNum: 1
|
|
}
|
|
]
|
|
}
|
|
];
|
|
const { wrapper } = setupMocks({});
|
|
|
|
// Act
|
|
const returnedGlass = await wrapper.vm.setupInitialData(glass,
|
|
i,
|
|
alreadyAnsweredQuestions);
|
|
|
|
// Assert
|
|
expect(returnedGlass.answerData).toMatchObject({ answerResult: 'WKT D1106 C' });
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('handleAnswerUpdates', () => {
|
|
describe('selectedAnswers', () => {
|
|
test('should be cleared to be empty', () => {
|
|
// Arrange
|
|
const answer = {
|
|
answerResult: 'DD11132',
|
|
answeredQuestions: [
|
|
{
|
|
questionText: 'Test duplicate question 1?',
|
|
selectedAnswerText: 'Yes',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.selectedAnswers = { test: 'mockSelectedAnswers' };
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
questions: [],
|
|
answerData: 'testAnswerData1'
|
|
}
|
|
];
|
|
|
|
// Act
|
|
wrapper.vm.handleAnswerUpdates(answer, '', wrapper.vm);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.selectedAnswers).toMatchObject({});
|
|
});
|
|
});
|
|
|
|
describe('questions in glass parts that are after the answered glass', () => {
|
|
test('should have answerData cleared', () => {
|
|
// Arrange
|
|
const answer = {
|
|
answerResult: 'DD11132',
|
|
answeredQuestions: [
|
|
{
|
|
questionText: 'Test duplicate question 1?',
|
|
selectedAnswerText: 'Yes',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
questions: [],
|
|
answerData: 'testAnswerData1'
|
|
},
|
|
{
|
|
glassLocation: 'Driver',
|
|
glassName: 'Front',
|
|
questions: [],
|
|
answerData: 'testAnswerData2'
|
|
}
|
|
];
|
|
|
|
// Act
|
|
wrapper.vm.handleAnswerUpdates(answer, '', wrapper.vm);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.questionsData[1].answerData).toEqual(null);
|
|
});
|
|
test('should have isSuppressedPart cleared', () => {
|
|
// Arrange
|
|
const answer = {
|
|
answerResult: 'DD11132',
|
|
answeredQuestions: [
|
|
{
|
|
questionText: 'Test duplicate question 1?',
|
|
selectedAnswerText: 'Yes',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
questions: [],
|
|
answerData: 'testAnswerData1'
|
|
},
|
|
{
|
|
glassLocation: 'Driver',
|
|
glassName: 'Front',
|
|
questions: [],
|
|
answerData: 'testAnswerData2',
|
|
isSuppressedPart: true
|
|
}
|
|
];
|
|
|
|
// Act
|
|
wrapper.vm.handleAnswerUpdates(answer, '', wrapper.vm);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.questionsData[1].isSuppressedPart).toEqual(null);
|
|
});
|
|
test('should set answerSelected for each glass part question to null ', () => {
|
|
// Arrange
|
|
const answer = {
|
|
answerResult: 'DD11132',
|
|
answeredQuestions: [
|
|
{
|
|
questionText: 'Test duplicate question 1?',
|
|
selectedAnswerText: 'Yes',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
questions: [],
|
|
answerData: 'testAnswerData1'
|
|
},
|
|
{
|
|
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: [
|
|
{
|
|
answerResult: '',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: 2
|
|
},
|
|
{
|
|
answerResult: '',
|
|
answerText: 'No',
|
|
nextQuestionSequence: 3
|
|
}
|
|
],
|
|
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: [
|
|
{
|
|
answerResult: 'FW04848',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: 'FW04846',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
],
|
|
answerSelected: '789'
|
|
}
|
|
],
|
|
answerData: 'testAnswerData2'
|
|
}
|
|
];
|
|
|
|
// Act
|
|
wrapper.vm.handleAnswerUpdates(answer, '', wrapper.vm);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.questionsData[1].questions[0].answerSelected).toEqual(null);
|
|
expect(wrapper.vm.questionsData[1].questions[1].answerSelected).toEqual(null);
|
|
});
|
|
});
|
|
|
|
describe('if there is a duplicate question', () => {
|
|
test("then the glass piece's key should be updated", () => {
|
|
// Arrange
|
|
const answerNo = {
|
|
answerResult: '456',
|
|
answeredQuestions: [
|
|
{
|
|
questionText: 'Test duplicate question 1?',
|
|
selectedAnswerText: 'No',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
key: 'testkey1',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test duplicate question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '123',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '456',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassLocation: 'Driver',
|
|
glassName: 'Front',
|
|
key: 'testkey2',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test duplicate question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '123',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '234',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
// Act
|
|
wrapper.vm.handleAnswerUpdates(answerNo, '', wrapper.vm);
|
|
const glassWithDuplicate = wrapper.vm.questionsData[1];
|
|
|
|
// Assert
|
|
expect(glassWithDuplicate.key).not.toBe('testkey2');
|
|
});
|
|
|
|
test('then that question should be supressed', () => {
|
|
// Arrange
|
|
const answerNo = {
|
|
answerResult: '456',
|
|
answeredQuestions: [
|
|
{
|
|
questionText: 'Test duplicate question 1?',
|
|
selectedAnswerText: 'No',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test duplicate question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '123',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '456',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassLocation: 'Driver',
|
|
glassName: 'Front',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test duplicate question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '123',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '234',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
// Act
|
|
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: [
|
|
{
|
|
questionText: 'Test duplicate question 1?',
|
|
selectedAnswerText: 'No',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test duplicate question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '123',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '456',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassLocation: 'Driver',
|
|
glassName: 'Front',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'ZZZTest duplicate question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: 2
|
|
},
|
|
{
|
|
answerResult: '',
|
|
answerText: 'No',
|
|
nextQuestionSequence: 3
|
|
}
|
|
]
|
|
},
|
|
{
|
|
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);
|
|
const nextQuestionAfterDuplicate = wrapper.vm.questionsData[1].questions[2];
|
|
|
|
// Assert
|
|
expect(nextQuestionAfterDuplicate.suppressThisQuestion).not.toBeTruthy();
|
|
});
|
|
|
|
test('then the nextQuestionSequence should be updated and the original value saved', () => {
|
|
// Arrange
|
|
const answerNo = {
|
|
answerResult: '456',
|
|
answeredQuestions: [
|
|
{
|
|
questionText: 'Test question 3?',
|
|
selectedAnswerText: 'No',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test question 3?',
|
|
answers: [
|
|
{
|
|
answerResult: '123',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '456',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassLocation: 'Driver',
|
|
glassName: 'Front',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: 2
|
|
},
|
|
{
|
|
answerResult: '',
|
|
answerText: 'No',
|
|
nextQuestionSequence: 3
|
|
}
|
|
]
|
|
},
|
|
{
|
|
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: '',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: 4
|
|
},
|
|
{
|
|
answerResult: '',
|
|
answerText: 'No',
|
|
nextQuestionSequence: 5
|
|
}
|
|
]
|
|
},
|
|
{
|
|
questionSequence: 4,
|
|
questionText: 'Test question 4?',
|
|
answers: [
|
|
{
|
|
answerResult: '567',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '678',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
},
|
|
{
|
|
questionSequence: 5,
|
|
questionText: 'Test question 5?',
|
|
answers: [
|
|
{
|
|
answerResult: '789',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '890',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
// Act
|
|
wrapper.vm.handleAnswerUpdates(answerNo, '', wrapper.vm);
|
|
const duplicatedQuestion = wrapper.vm.questionsData[1].questions[2];
|
|
const duplicatedQuestionAnswer = duplicatedQuestion.answers.filter((a) => a.selected);
|
|
const answerToTest = wrapper.vm.questionsData[1].questions[0].answers.filter((a) => a.originalNextQuestionSequence);
|
|
|
|
// Assert
|
|
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: [
|
|
{
|
|
questionText: 'Test duplicate question 1?',
|
|
selectedAnswerText: 'No',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test duplicate question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '123',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '456',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassLocation: 'Driver',
|
|
glassName: 'Front',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test duplicate question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: 2
|
|
},
|
|
{
|
|
answerResult: '',
|
|
answerText: 'No',
|
|
nextQuestionSequence: 3
|
|
}
|
|
]
|
|
},
|
|
{
|
|
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
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
// Act
|
|
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();
|
|
});
|
|
});
|
|
});
|
|
|
|
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: [
|
|
{
|
|
questionText: 'Test question 3?',
|
|
selectedAnswerText: 'No',
|
|
questionNum: 1
|
|
}
|
|
],
|
|
index: 0
|
|
};
|
|
const { wrapper } = setupMocks({});
|
|
|
|
wrapper.vm.questionsData = [
|
|
{
|
|
glassLocation: 'Windshield',
|
|
glassName: 'Single',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test question 3?',
|
|
answers: [
|
|
{
|
|
answerResult: '123',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: '456',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassLocation: 'Driver',
|
|
glassName: 'Front',
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText: 'Test question 1?',
|
|
answers: [
|
|
{
|
|
answerResult: '',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: 2
|
|
},
|
|
{
|
|
answerResult: '',
|
|
answerText: 'No',
|
|
nextQuestionSequence: 3
|
|
}
|
|
]
|
|
},
|
|
{
|
|
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
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
// Act
|
|
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) => a.selected);
|
|
|
|
// Assert
|
|
expect(answerLeadingToDuplicate.answerResult).toEqual(answerInDuplicateQuestion[0].answerResult);
|
|
expect(answerLeadingToDuplicate.originalAnswerResult).toBeFalsy();
|
|
expect(answerLeadingToDuplicate.nextQuestionSequence).toEqual(null);
|
|
expect(answerLeadingToDuplicate.originalNextQuestionSequence).toEqual(duplicateQuestion.questionSequence);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('navigateForward', () => {
|
|
describe('should go to parts-questions', () => {
|
|
test('single glass location has part question => go to parts-questions', async () => {
|
|
// Arrange
|
|
const partsOrQuestions = [
|
|
{
|
|
glassName: 'Single',
|
|
glassLocation: 'Windshield',
|
|
parts: null,
|
|
partQuestions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
"Is there a line running across the bottom, driver's side then up the center of the Windshield?",
|
|
answers: [
|
|
{
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01144'
|
|
},
|
|
{
|
|
answerText: 'No',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01143'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
const { wrapper } = setupMocks({
|
|
partsOrQuestions
|
|
});
|
|
|
|
// Act
|
|
await wrapper.vm.navigateForward(partsOrQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_PART_QUESTIONS,
|
|
wrapper.vm.$route,
|
|
{},
|
|
{},
|
|
{ partsOrQuestions });
|
|
});
|
|
|
|
test('multiple glass locations have part questions => go to parts-questions', async () => {
|
|
// Arrange
|
|
const partsOrQuestions = [
|
|
{
|
|
glassName: 'Single',
|
|
glassLocation: 'Windshield',
|
|
parts: null,
|
|
partQuestions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
"Is there a line running across the bottom, driver's side then up the center of the Windshield?",
|
|
answers: [
|
|
{
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01144'
|
|
},
|
|
{
|
|
answerText: 'No',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01143'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassName: 'Front',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DD08158GTYN',
|
|
description: 'driver side, front',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Quarter',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DQ08162GTYN',
|
|
description: 'driver side, 1 hole',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'SideDoor',
|
|
glassLocation: 'Driver',
|
|
parts: null,
|
|
partQuestions: [
|
|
{
|
|
questionSequence: 2,
|
|
questionText: 'Is this a super awesome question?',
|
|
answers: [
|
|
{
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01144000'
|
|
},
|
|
{
|
|
answerText: 'Super yes',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01143001'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassName: 'Stationary',
|
|
glassLocation: 'Rear',
|
|
parts: [
|
|
{
|
|
partNumber: 'DB08165GTNN',
|
|
description: 'heated glass, stationary',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
}
|
|
];
|
|
|
|
const { wrapper } = setupMocks({
|
|
partsOrQuestions
|
|
});
|
|
|
|
// Act
|
|
await wrapper.vm.navigateForward(partsOrQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_PART_QUESTIONS,
|
|
wrapper.vm.$route,
|
|
{},
|
|
{},
|
|
{ partsOrQuestions });
|
|
});
|
|
|
|
test('multiple glass locations selected, one has part question => go to parts-questions', async () => {
|
|
// Arrange
|
|
const partsOrQuestions = [
|
|
{
|
|
glassName: 'Single',
|
|
glassLocation: 'Windshield',
|
|
parts: null,
|
|
partQuestions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
"Is there a line running across the bottom, driver's side then up the center of the Windshield?",
|
|
answers: [
|
|
{
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01144'
|
|
},
|
|
{
|
|
answerText: 'No',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01143'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassName: 'Front',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DD08158GTYN',
|
|
description: 'driver side, front',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Quarter',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DQ08162GTYN',
|
|
description: 'driver side, 1 hole',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'SideDoor',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DD08160GTYN',
|
|
description: 'driver side, body side, 1 hole',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Stationary',
|
|
glassLocation: 'Rear',
|
|
parts: [
|
|
{
|
|
partNumber: 'DB08165GTNN',
|
|
description: 'heated glass, stationary',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
}
|
|
];
|
|
|
|
const { wrapper } = setupMocks({
|
|
partsOrQuestions
|
|
});
|
|
|
|
// Act
|
|
await wrapper.vm.navigateForward(partsOrQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_PART_QUESTIONS,
|
|
wrapper.vm.$route,
|
|
{},
|
|
{},
|
|
{ partsOrQuestions });
|
|
});
|
|
|
|
test('a selected glass location has part questions and multiple parts => go to parts-questions', async () => {
|
|
// Arrange
|
|
const partsOrQuestions = [
|
|
{
|
|
glassName: 'Single',
|
|
glassLocation: 'Windshield',
|
|
parts: null,
|
|
partQuestions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
"Is there a line running across the bottom, driver's side then up the center of the Windshield?",
|
|
answers: [
|
|
{
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01144'
|
|
},
|
|
{
|
|
answerText: 'No',
|
|
nextQuestionSequence: null,
|
|
answerResult: 'DW01143'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
glassName: 'Front',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DD08158GTYN',
|
|
description: 'driver side, front',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Quarter',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DQ08162GTYN',
|
|
description: 'driver side, 1 hole',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DQ08162YPYN',
|
|
description: 'driver side, 1 hole',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'SideDoor',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DD08160GTYN',
|
|
description: 'driver side, body side, 1 hole',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DD08160YPYN',
|
|
description: 'driver side, body side, 1 hole',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Stationary',
|
|
glassLocation: 'Rear',
|
|
parts: [
|
|
{
|
|
partNumber: 'DB08165GTNN',
|
|
description: 'heated glass, stationary',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DB08165YPNN',
|
|
description: 'heated glass, stationary',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DB08166GTNN',
|
|
description: 'stationary',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DB08167GTNN',
|
|
description: 'heated glass, movable, 8 hole',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DB08167YPNN',
|
|
description: 'heated glass, movable, 8 hole',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
}
|
|
];
|
|
|
|
const { wrapper } = setupMocks({
|
|
partsOrQuestions
|
|
});
|
|
|
|
// Act
|
|
await wrapper.vm.navigateForward(partsOrQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_PART_QUESTIONS,
|
|
wrapper.vm.$route,
|
|
{},
|
|
{},
|
|
{ partsOrQuestions });
|
|
});
|
|
});
|
|
|
|
describe('should go to vehicle-parts', () => {
|
|
test('single glass location has multiple parts => go to vehicle-parts', async () => {
|
|
// Arrange
|
|
const partsOrQuestions = [
|
|
{
|
|
glassName: 'Stationary',
|
|
glassLocation: 'Rear',
|
|
parts: [
|
|
{
|
|
partNumber: 'FB25724GTYN',
|
|
description: 'heated glass, solar, antenna',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'FB25759GTYN',
|
|
description: 'heated glass, solar, antenna, w/diversity antenna',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
}
|
|
];
|
|
|
|
const { wrapper } = setupMocks({
|
|
partsOrQuestions
|
|
});
|
|
|
|
// Act
|
|
await wrapper.vm.navigateForward(partsOrQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_MULTIPLE_PARTS_TO_CHOOSE,
|
|
wrapper.vm.$route,
|
|
{},
|
|
{},
|
|
{ partsOrQuestions });
|
|
});
|
|
|
|
test('multiple glass locations selected, one of them has multiple parts => go to vehicle parts', async () => {
|
|
// Arrange
|
|
const partsOrQuestions = [
|
|
{
|
|
glassName: 'Single',
|
|
glassLocation: 'Windshield',
|
|
parts: [
|
|
{
|
|
partNumber: 'FW03647GTNN',
|
|
description: 'solar, 3rd visor band',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: [
|
|
{
|
|
partNumber: 'MWF03647',
|
|
partType: 'MOULDING',
|
|
description: 'Upper '
|
|
}
|
|
]
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Back',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'FD25747GTYN',
|
|
description: 'solar, driver side, rear, ex models and above',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Front',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'FD25719GTYN',
|
|
description: 'solar, driver side, front, ex models and above',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Vent',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'FV25749GTNN',
|
|
description: 'solar, driver side, rear',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Stationary',
|
|
glassLocation: 'Rear',
|
|
parts: [
|
|
{
|
|
partNumber: 'FB25724GTYN',
|
|
description: 'heated glass, solar, antenna',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'FB25759GTYN',
|
|
description: 'heated glass, solar, antenna, w/diversity antenna',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
}
|
|
];
|
|
|
|
const { wrapper } = setupMocks({
|
|
partsOrQuestions
|
|
});
|
|
|
|
// Act
|
|
await wrapper.vm.navigateForward(partsOrQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_MULTIPLE_PARTS_TO_CHOOSE,
|
|
wrapper.vm.$route,
|
|
{},
|
|
{},
|
|
{ partsOrQuestions });
|
|
});
|
|
|
|
test('multiple glass locations selected, multiple have multiple parts => go to vehicle-parts', async () => {
|
|
// Arrange
|
|
const partsOrQuestions = [
|
|
{
|
|
glassName: 'Single',
|
|
glassLocation: 'Windshield',
|
|
parts: [
|
|
{
|
|
partNumber: 'DW02101GTYN',
|
|
description: 'solar',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Back',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DD12202GTYN',
|
|
description: 'solar, driver side, rear',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DD12202YPYN',
|
|
description: 'solar, driver side, rear',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Front',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DD12198GTYN',
|
|
description: 'solar, driver side, front',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DD12200GTYN',
|
|
description: 'solar, driver side, front, laminated, soundproofing',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Quarter',
|
|
glassLocation: 'Driver',
|
|
parts: [
|
|
{
|
|
partNumber: 'DQ12204GTYNOEM',
|
|
description: 'solar, driver side, encap',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DQ12204YPYNOEM',
|
|
description: 'solar, driver side, encap',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DQ12205GTYNOEM',
|
|
description: 'solar, antenna, driver side, encap',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DQ12205YPYNOEM',
|
|
description: 'solar, antenna, driver side, encap',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DQ12207GTYN',
|
|
description: 'solar, driver side, encap, chrome molding',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DQ12207YPYNOEM',
|
|
description: 'solar, driver side, encap, chrome molding',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DQ12208GTYNOEM',
|
|
description: 'solar, antenna, driver side, encap, chrome molding',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DQ12208YPYNOEM',
|
|
description: 'solar, antenna, driver side, encap, chrome molding',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
},
|
|
{
|
|
glassName: 'Stationary',
|
|
glassLocation: 'Rear',
|
|
parts: [
|
|
{
|
|
partNumber: 'DB12209GTYN',
|
|
description: 'heated glass, solar, 1 hole',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
},
|
|
{
|
|
partNumber: 'DB12209YPYN',
|
|
description: 'heated glass, solar, 1 hole',
|
|
color: 'Gray Tint Privacy',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null
|
|
}
|
|
],
|
|
partQuestions: null
|
|
}
|
|
];
|
|
|
|
const { wrapper } = setupMocks({
|
|
partsOrQuestions
|
|
});
|
|
|
|
// Act
|
|
await wrapper.vm.navigateForward(partsOrQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_MULTIPLE_PARTS_TO_CHOOSE,
|
|
wrapper.vm.$route,
|
|
{},
|
|
{},
|
|
{ partsOrQuestions });
|
|
});
|
|
});
|
|
|
|
describe('should go to molding-questions', () => {
|
|
test('single glass location has child part questions => go to molding-questions', async () => {
|
|
// Arrange
|
|
const partsOrQuestions = [
|
|
{
|
|
glassName: 'Stationary',
|
|
glassLocation: 'Rear',
|
|
parts: [
|
|
{
|
|
partNumber: 'FB25724GTYN',
|
|
description: 'heated glass, solar, antenna',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null,
|
|
childPartQuestions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
'Does the rubber seal around your windshield have a chrome strip running through it?',
|
|
answers: [
|
|
{
|
|
answerResult: 'WKT D1106 C',
|
|
answerText: 'Yes',
|
|
nextQuestionSequence: null
|
|
},
|
|
{
|
|
answerResult: 'WKT D1106 B',
|
|
answerText: 'No',
|
|
nextQuestionSequence: null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
partQuestions: null
|
|
}
|
|
];
|
|
|
|
const { wrapper } = setupMocks({
|
|
partsOrQuestions
|
|
});
|
|
|
|
// Act
|
|
await wrapper.vm.navigateForward(partsOrQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_MOLDING_QUESTIONS,
|
|
wrapper.vm.$route,
|
|
{},
|
|
{},
|
|
{ partsOrQuestions });
|
|
});
|
|
});
|
|
|
|
describe('should go to capability-questions', () => {
|
|
test('single glass location has no child part questions but requiresCapabilityQuestions is true => go to capability-questions', async () => {
|
|
// Arrange
|
|
const partsOrQuestions = [
|
|
{
|
|
glassName: 'Single',
|
|
glassLocation: 'Windshield',
|
|
parts: [
|
|
{
|
|
partNumber: 'FB25724GTYN',
|
|
description: 'heated glass, solar, antenna',
|
|
color: 'Green Tint',
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: true,
|
|
childParts: null,
|
|
childPartQuestions: null
|
|
}
|
|
],
|
|
capabilityQuestions: [],
|
|
partQuestions: null
|
|
}
|
|
];
|
|
|
|
const { wrapper } = setupMocks({
|
|
partsOrQuestions
|
|
});
|
|
|
|
// Act
|
|
await wrapper.vm.navigateForward(partsOrQuestions);
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_CAPABILITY_QUESTIONS,
|
|
wrapper.vm.$route,
|
|
{},
|
|
{},
|
|
{ partsOrQuestions });
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('navigateBack', () => {
|
|
test('current page is coverage-statement and damage is repair => go to vehicle-damage', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({ issPage: issPageValues.COVERAGE_STATEMENT });
|
|
useMainStore().order.damage.isRepair = true;
|
|
|
|
// Act
|
|
wrapper.vm.navigateBack();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_WITH_REPAIR,
|
|
{ query: { issPage: issPageValues.COVERAGE_STATEMENT } });
|
|
});
|
|
|
|
test('current page is molding questions and there are part questions, multiple parts to choose, and capability questions => go to vehicle-parts', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({ issPage: issPageValues.MOLDING_QUESTIONS });
|
|
wrapper.vm.hasPartQuestions = jest.fn().mockReturnValue(true);
|
|
wrapper.vm.hasGlassLocationWithMultipleParts = jest.fn().mockReturnValue(true);
|
|
wrapper.vm.hasChildPartQuestions = jest.fn().mockReturnValue(true);
|
|
wrapper.vm.hasCapabilityQuestions = jest.fn().mockReturnValue(true);
|
|
|
|
// Act
|
|
wrapper.vm.navigateBack();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_WITH_MULTIPLE_PARTS_TO_CHOOSE,
|
|
{ query: { issPage: issPageValues.MOLDING_QUESTIONS } });
|
|
});
|
|
|
|
test('current page is molding questions and there are part questions and capability questions => go to part-questions', () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({ issPage: issPageValues.MOLDING_QUESTIONS });
|
|
wrapper.vm.hasPartQuestions = jest.fn().mockReturnValue(true);
|
|
wrapper.vm.hasGlassLocationWithMultipleParts = jest.fn().mockReturnValue(false);
|
|
wrapper.vm.hasChildPartQuestions = jest.fn().mockReturnValue(true);
|
|
wrapper.vm.hasCapabilityQuestions = jest.fn().mockReturnValue(true);
|
|
|
|
// Act
|
|
wrapper.vm.navigateBack();
|
|
|
|
// Assert
|
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_WITH_PART_QUESTIONS,
|
|
{ query: { issPage: issPageValues.MOLDING_QUESTIONS } });
|
|
});
|
|
});
|
|
});
|
|
|
|
function setupMocks({ issPage = issPageValues.VIN_LOOKUP }) {
|
|
const baseMixin = setupMocksForJsFiles({
|
|
actionList: [
|
|
{
|
|
actionName: 'getCapabilityQuestions',
|
|
data: [
|
|
{
|
|
answers: [
|
|
{
|
|
answerResult1: 'testing'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
});
|
|
|
|
const mocks = getMountOptions({
|
|
router: {
|
|
navigate: jest.fn()
|
|
},
|
|
route: {
|
|
query: {
|
|
issPage
|
|
}
|
|
}
|
|
});
|
|
|
|
const mockVehicleQuestionComponent = {
|
|
template: '<div />',
|
|
mixins: [vehicleQuestionsMixin, baseMixin.baseMixin]
|
|
};
|
|
|
|
const store = useMainStore();
|
|
const actionResult = [];
|
|
store.getCapabilityQuestions.mockImplementation(() => Promise.resolve({ data: actionResult }));
|
|
|
|
const wrapper = shallowMount(mockVehicleQuestionComponent, mocks);
|
|
|
|
return { wrapper };
|
|
}
|