Fixing tests

This commit is contained in:
Michaela Brydon 2024-07-01 12:29:50 -04:00
parent 5d07842a6a
commit 6433b6e951
2 changed files with 55 additions and 20 deletions

View file

@ -244,7 +244,7 @@ describe('capabilityQuestions.vue', () => {
});
describe('forwardButtonAction', () => {
test('Should clear out answerData', () => {
test('Should clear out answerData', async () => {
// Arrange
const { wrapper } = setupMocks({});
@ -269,7 +269,7 @@ describe('capabilityQuestions.vue', () => {
}));
// Act
wrapper.vm.forwardButtonAction();
await wrapper.vm.forwardButtonAction();
// Assert
expect(wrapper.vm.questionsData[0].answerData).toEqual({});
@ -277,7 +277,6 @@ describe('capabilityQuestions.vue', () => {
wrapper.unmount();
});
// TODO add test spying on getPartFromCapQuestionAnswer
test('Should save to pinia store', async () => {
// Arrange
const { wrapper } = setupMocks({});
@ -306,15 +305,49 @@ describe('capabilityQuestions.vue', () => {
const saveCapabilityQuestionAnswersSpy = jest.spyOn(useMainStore(), 'saveCapabilityQuestionAnswers');
// Act
wrapper.vm.forwardButtonAction();
await nextTick();
await wrapper.vm.forwardButtonAction();
// Assert
expect(saveCapabilityQuestionAnswersSpy).toHaveBeenCalled();
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 () => {
// Arrange
const { wrapper } = setupMocks({});

View file

@ -11,10 +11,10 @@ export default {
return partsOrQuestions?.some((pq) => pq.parts?.length > 1);
},
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) {
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
@ -23,18 +23,20 @@ export default {
glassParts.forEach((glass) => {
if (Array.isArray(glass.parts) && glass.parts.length === 1) {
const singlePart = glass.parts[0];
reducedGlassParts.push({
partNumber: singlePart.partNumber,
description: singlePart.description,
color: singlePart.color,
partType: singlePart.partType,
canSafeliteRecalibrate: singlePart.canSafeliteRecalibrate,
requiresRecalibration: singlePart.requiresRecalibration,
requiresCapabilityQuestions: singlePart.requiresCapabilityQuestions,
recalibrationType: singlePart.recalibrationType,
childParts: singlePart.childParts,
price: singlePart.price
});
if (singlePart){
reducedGlassParts.push({
partNumber: singlePart.partNumber,
description: singlePart.description,
color: singlePart.color,
partType: singlePart.partType,
canSafeliteRecalibrate: singlePart.canSafeliteRecalibrate,
requiresRecalibration: singlePart.requiresRecalibration,
requiresCapabilityQuestions: singlePart.requiresCapabilityQuestions,
recalibrationType: singlePart.recalibrationType,
childParts: singlePart.childParts,
price: singlePart.price
});
}
}
});
return reducedGlassParts;