completed unit tests for molding-questions

This commit is contained in:
Kroell 2023-02-09 16:49:29 -05:00
parent e9bcab5402
commit 9a536d2886

View file

@ -93,7 +93,7 @@ const baseStoreGettersDamage = () => {
}; };
}; };
useMainStore().pageData = baseStoreGettersDamage; useMainStore().pageData = baseStoreGettersPageData;
useMainStore().damage = baseStoreGettersDamage; useMainStore().damage = baseStoreGettersDamage;
describe("moldingQuestions.vue", () => { describe("moldingQuestions.vue", () => {
@ -114,7 +114,7 @@ describe("moldingQuestions.vue", () => {
test("Should return false for valid page requisites if partsOrQuestions in pageData is missing", () => { test("Should return false for valid page requisites if partsOrQuestions in pageData is missing", () => {
// Arrange // Arrange
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
store.getters.pageData = jest.fn(() => { useMainStore().pageData = jest.fn(() => {
return undefined; return undefined;
}); });
@ -129,14 +129,13 @@ describe("moldingQuestions.vue", () => {
test("Should be at least one item in partsOrQuestions", () => { test("Should be at least one item in partsOrQuestions", () => {
// Arrange // Arrange
store.getters = { useMainStore().pageData = jest.fn(() => {
pageData: jest.fn(() => { return {
return { partsOrQuestions: [],
partsOrQuestions: [], };
}; });
}), useMainStore().damage = baseStoreGettersDamage;
damage: baseStoreGettersDamage,
};
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
// Act // Act
@ -150,10 +149,13 @@ describe("moldingQuestions.vue", () => {
}); });
describe("watch on selectedAnswers should be set up...", () => { describe("watch on selectedAnswers should be set up...", () => {
test("Should trigger handleCompletedQuestionChainAnswers if watched data changes", async () => { test("Should trigger handleAnswerUpdates if watched data changes", async () => {
// Arrange // Arrange
useMainStore().pageData = baseStoreGettersPageData;
useMainStore().damage = baseStoreGettersDamage;
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
const spy = jest.spyOn(wrapper.vm, "handleCompletedQuestionChainAnswers"); const spy = jest.spyOn(wrapper.vm, "handleAnswerUpdates");
// Act // Act
wrapper.setData({ wrapper.setData({
@ -190,135 +192,190 @@ describe("moldingQuestions.vue", () => {
}); });
}); });
// describe("forwardButtonAction", () => { describe("forwardButtonAction", () => {
// test("Should clear out answerData", () => { test("Should clear out answerData", () => {
// // Arrange // Arrange
// const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
// wrapper.vm.questionsData = [ wrapper.vm.questionsData = [
// { {
// glassLocation: "Windshield", glassLocation: "Windshield",
// glassName: "Single", glassName: "Single",
// answerData: { answerData: {
// answerResult: "FW04848", answerResult: "FW04848",
// answeredQuestions: [], answeredQuestions: [],
// }, },
// }, },
// ]; ];
// wrapper.vm.dispatchStoreAction = jest.fn(() => { wrapper.vm.dispatchStoreAction = jest.fn(() => {
// return { return {
// data: { data: {
// glassPieceParts: [], partsOrQuestions: [],
// }, },
// }; };
// }); });
// // Act // Act
// wrapper.vm.forwardButtonAction(); wrapper.vm.forwardButtonAction();
// //Assert //Assert
// expect(wrapper.vm.questionsData[0].answerData).toEqual({}); expect(wrapper.vm.questionsData[0].answerData).toEqual({});
// wrapper.unmount(); wrapper.unmount();
// }); });
// test("Should save to Vuex store", async () => { test("Should save to pinia store", async () => {
// // Arrange // Arrange
// const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
// wrapper.vm.questionsData = [ wrapper.vm.questionsData = [
// { {
// glassLocation: "Windshield", glassLocation: "Windshield",
// glassName: "Single", glassName: "Single",
// answerData: { answerData: {
// answerResult: "FW04848", answerResult: "FW04848",
// answeredQuestions: [], answeredQuestions: [],
// }, },
// }, },
// ]; ];
// wrapper.vm.dispatchStoreAction = jest.fn(() => { useMainStore().getPartsOrQuestions = jest.fn(() => {
// return { return {
// data: { data: {
// glassPieceParts: [], partsOrQuestions: [],
// }, },
// }; };
// }); });
// const spy = jest.spyOn(wrapper.vm, "dispatchStoreAction");
// // Act // Act
// wrapper.vm.forwardButtonAction(); wrapper.vm.forwardButtonAction();
// await nextTick(); await nextTick();
// //Assert //Assert
// expect(spy).toHaveBeenNthCalledWith( expect(wrapper.vm.saveMoldingQuestionAnswers).toHaveBeenCalled;
// 1, wrapper.unmount();
// "saveMoldingQuestionAnswers", });
// [
// {
// answeredQuestions: [],
// glassLocation: "Windshield",
// glassName: "Single",
// isSuppressedPart: undefined,
// partNum: "FW04848",
// },
// ],
// false
// );
// wrapper.unmount(); test("Should call GET_PARTS_OR_QUESTIONS API", async () => {
// }); // Arrange
const { wrapper } = setupMocks({});
// test("Should trigger navigateForward", async () => { wrapper.vm.questionsData = [
// // Arrange {
// const { wrapper } = setupMocks({}); glassLocation: "Windshield",
glassName: "Single",
answerData: {
answerResult: "FW04848",
answeredQuestions: [],
},
},
];
useMainStore().getPartsOrQuestions = jest.fn(() => {
return {
data: {
partsOrQuestions: [],
},
};
});
// wrapper.vm.questionsData = [ // Act
// { wrapper.vm.forwardButtonAction();
// glassLocation: "Windshield",
// glassName: "Single",
// answerData: {
// answerResult: "FW04848",
// answeredQuestions: [],
// },
// },
// ];
// wrapper.vm.dispatchStoreAction = jest.fn(() => {
// return {
// data: {
// glassPieceParts: [],
// },
// };
// });
// wrapper.vm.navigateForward = jest.fn();
// // Act await nextTick();
// await wrapper.vm.forwardButtonAction();
// //Assert //Assert
// expect(wrapper.vm.navigateForward).toHaveBeenCalled(); expect(wrapper.vm.getPartsOrQuestions).toHaveBeenCalled;
// wrapper.unmount(); wrapper.unmount();
// }); });
// });
test("Should trigger navigateForward", async () => {
// Arrange
const { wrapper } = setupMocks({});
wrapper.vm.questionsData = [
{
glassLocation: "Windshield",
glassName: "Single",
answerData: {
answerResult: "FW04848",
answeredQuestions: [],
},
},
];
useMainStore().getPartsOrQuestions = jest.fn(() => {
return {
data: {
partsOrQuestions: [],
},
};
});
wrapper.vm.navigateForward = jest.fn();
// Act
await wrapper.vm.forwardButtonAction();
//Assert
expect(wrapper.vm.navigateForward).toHaveBeenCalled();
wrapper.unmount();
});
}); });
});
function setupMocks({ function setupMocks({
mountOptionsMockData = { mountOptionsMockData = {
router: { router: {
navigate: jest.fn(), navigate: jest.fn(),
}, },
store: { actionList: [
getters: store.getters, {
commit: store.commit, actionName: "saveMoldingQuestionAnswers",
}, data: {},
},
{
actionName: "getPartsOrQuestions",
data: {},
},
],
route: { route: {
query: { query: {
issPage: "molding-questions", issPage: "molding-questions",
}, },
}, },
data() {
return {
computedSwitcher: [
{
glassLocation: "Windshield",
glassName: "Single",
answerData: {
answerResult: "FW04848",
answeredQuestions: [],
},
},
],
};
},
questionsData: {
get() {
return this.computedSwitcher;
},
set(val) {
this.computedSwitcher = val;
},
},
}, },
}) { }) {
useMainStore().getPartsOrQuestions = jest.fn(() => {
return {
data: {
partsOrQuestions: [],
}
};
});
const mountOptions = getMountOptions({ const mountOptions = getMountOptions({
...mountOptionsMockData, ...mountOptionsMockData,
mixins: [baseMixin, vehicleQuestionsMixin], mixins: [baseMixin, vehicleQuestionsMixin],