Fixing tests
This commit is contained in:
parent
5d07842a6a
commit
6433b6e951
2 changed files with 55 additions and 20 deletions
|
|
@ -244,7 +244,7 @@ describe('capabilityQuestions.vue', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('forwardButtonAction', () => {
|
describe('forwardButtonAction', () => {
|
||||||
test('Should clear out answerData', () => {
|
test('Should clear out answerData', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
|
@ -269,7 +269,7 @@ describe('capabilityQuestions.vue', () => {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.forwardButtonAction();
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.questionsData[0].answerData).toEqual({});
|
expect(wrapper.vm.questionsData[0].answerData).toEqual({});
|
||||||
|
|
@ -277,7 +277,6 @@ describe('capabilityQuestions.vue', () => {
|
||||||
wrapper.unmount();
|
wrapper.unmount();
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO add test spying on getPartFromCapQuestionAnswer
|
|
||||||
test('Should save to pinia store', async () => {
|
test('Should save to pinia store', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
|
|
@ -306,15 +305,49 @@ describe('capabilityQuestions.vue', () => {
|
||||||
const saveCapabilityQuestionAnswersSpy = jest.spyOn(useMainStore(), 'saveCapabilityQuestionAnswers');
|
const saveCapabilityQuestionAnswersSpy = jest.spyOn(useMainStore(), 'saveCapabilityQuestionAnswers');
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
wrapper.vm.forwardButtonAction();
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(saveCapabilityQuestionAnswersSpy).toHaveBeenCalled();
|
expect(saveCapabilityQuestionAnswersSpy).toHaveBeenCalled();
|
||||||
wrapper.unmount();
|
wrapper.unmount();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Should call getPartFromCapabilityQuestionAnswer', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
wrapper.vm.questionsData = [
|
||||||
|
{
|
||||||
|
glassLocation: 'Windshield',
|
||||||
|
glassName: 'Single',
|
||||||
|
answerData: {
|
||||||
|
answerResult: 'FW04848',
|
||||||
|
answeredQuestions: []
|
||||||
|
},
|
||||||
|
questions: [],
|
||||||
|
parts: [
|
||||||
|
{
|
||||||
|
childPartQuestions: []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
useMainStore().getPartsOrQuestions = jest.fn(() => ({
|
||||||
|
data: {
|
||||||
|
partsOrQuestions: []
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
const getPartFromCapabilityQuestionAnswerSpy = jest.spyOn(useMainStore(), 'getPartFromCapabilityQuestionAnswer');
|
||||||
|
getPartFromCapabilityQuestionAnswerSpy.mockClear();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(getPartFromCapabilityQuestionAnswerSpy).toHaveBeenCalledTimes(1);
|
||||||
|
wrapper.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
test('Should trigger navigateForward', async () => {
|
test('Should trigger navigateForward', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ export default {
|
||||||
return partsOrQuestions?.some((pq) => pq.parts?.length > 1);
|
return partsOrQuestions?.some((pq) => pq.parts?.length > 1);
|
||||||
},
|
},
|
||||||
hasChildPartQuestions(partsOrQuestions) {
|
hasChildPartQuestions(partsOrQuestions) {
|
||||||
return partsOrQuestions?.some((pq) => pq.parts?.some((part) => part.childPartQuestions?.length > 0));
|
return partsOrQuestions?.some((pq) => pq.parts?.some((part) => part?.childPartQuestions?.length > 0));
|
||||||
},
|
},
|
||||||
hasCapabilityQuestions(partsOrQuestions) {
|
hasCapabilityQuestions(partsOrQuestions) {
|
||||||
return partsOrQuestions?.some((pq) => pq.parts?.some((part) => part.requiresCapabilityQuestions === true));
|
return partsOrQuestions?.some((pq) => pq.parts?.some((part) => part?.requiresCapabilityQuestions === true));
|
||||||
},
|
},
|
||||||
|
|
||||||
// method to only include keys listed for lineItems.glassParts in
|
// method to only include keys listed for lineItems.glassParts in
|
||||||
|
|
@ -23,18 +23,20 @@ export default {
|
||||||
glassParts.forEach((glass) => {
|
glassParts.forEach((glass) => {
|
||||||
if (Array.isArray(glass.parts) && glass.parts.length === 1) {
|
if (Array.isArray(glass.parts) && glass.parts.length === 1) {
|
||||||
const singlePart = glass.parts[0];
|
const singlePart = glass.parts[0];
|
||||||
reducedGlassParts.push({
|
if (singlePart){
|
||||||
partNumber: singlePart.partNumber,
|
reducedGlassParts.push({
|
||||||
description: singlePart.description,
|
partNumber: singlePart.partNumber,
|
||||||
color: singlePart.color,
|
description: singlePart.description,
|
||||||
partType: singlePart.partType,
|
color: singlePart.color,
|
||||||
canSafeliteRecalibrate: singlePart.canSafeliteRecalibrate,
|
partType: singlePart.partType,
|
||||||
requiresRecalibration: singlePart.requiresRecalibration,
|
canSafeliteRecalibrate: singlePart.canSafeliteRecalibrate,
|
||||||
requiresCapabilityQuestions: singlePart.requiresCapabilityQuestions,
|
requiresRecalibration: singlePart.requiresRecalibration,
|
||||||
recalibrationType: singlePart.recalibrationType,
|
requiresCapabilityQuestions: singlePart.requiresCapabilityQuestions,
|
||||||
childParts: singlePart.childParts,
|
recalibrationType: singlePart.recalibrationType,
|
||||||
price: singlePart.price
|
childParts: singlePart.childParts,
|
||||||
});
|
price: singlePart.price
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return reducedGlassParts;
|
return reducedGlassParts;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue