completed unit tests for molding-questions
This commit is contained in:
parent
e9bcab5402
commit
9a536d2886
1 changed files with 169 additions and 112 deletions
|
|
@ -93,7 +93,7 @@ const baseStoreGettersDamage = () => {
|
|||
};
|
||||
};
|
||||
|
||||
useMainStore().pageData = baseStoreGettersDamage;
|
||||
useMainStore().pageData = baseStoreGettersPageData;
|
||||
useMainStore().damage = baseStoreGettersDamage;
|
||||
|
||||
describe("moldingQuestions.vue", () => {
|
||||
|
|
@ -114,7 +114,7 @@ describe("moldingQuestions.vue", () => {
|
|||
test("Should return false for valid page requisites if partsOrQuestions in pageData is missing", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
store.getters.pageData = jest.fn(() => {
|
||||
useMainStore().pageData = jest.fn(() => {
|
||||
return undefined;
|
||||
});
|
||||
|
||||
|
|
@ -129,14 +129,13 @@ describe("moldingQuestions.vue", () => {
|
|||
|
||||
test("Should be at least one item in partsOrQuestions", () => {
|
||||
// Arrange
|
||||
store.getters = {
|
||||
pageData: jest.fn(() => {
|
||||
return {
|
||||
partsOrQuestions: [],
|
||||
};
|
||||
}),
|
||||
damage: baseStoreGettersDamage,
|
||||
};
|
||||
useMainStore().pageData = jest.fn(() => {
|
||||
return {
|
||||
partsOrQuestions: [],
|
||||
};
|
||||
});
|
||||
useMainStore().damage = baseStoreGettersDamage;
|
||||
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
|
|
@ -150,10 +149,13 @@ describe("moldingQuestions.vue", () => {
|
|||
});
|
||||
|
||||
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
|
||||
useMainStore().pageData = baseStoreGettersPageData;
|
||||
useMainStore().damage = baseStoreGettersDamage;
|
||||
|
||||
const { wrapper } = setupMocks({});
|
||||
const spy = jest.spyOn(wrapper.vm, "handleCompletedQuestionChainAnswers");
|
||||
const spy = jest.spyOn(wrapper.vm, "handleAnswerUpdates");
|
||||
|
||||
// Act
|
||||
wrapper.setData({
|
||||
|
|
@ -190,135 +192,190 @@ describe("moldingQuestions.vue", () => {
|
|||
});
|
||||
});
|
||||
|
||||
// describe("forwardButtonAction", () => {
|
||||
// test("Should clear out answerData", () => {
|
||||
// // Arrange
|
||||
// const { wrapper } = setupMocks({});
|
||||
describe("forwardButtonAction", () => {
|
||||
test("Should clear out answerData", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// wrapper.vm.questionsData = [
|
||||
// {
|
||||
// glassLocation: "Windshield",
|
||||
// glassName: "Single",
|
||||
// answerData: {
|
||||
// answerResult: "FW04848",
|
||||
// answeredQuestions: [],
|
||||
// },
|
||||
// },
|
||||
// ];
|
||||
// wrapper.vm.dispatchStoreAction = jest.fn(() => {
|
||||
// return {
|
||||
// data: {
|
||||
// glassPieceParts: [],
|
||||
// },
|
||||
// };
|
||||
// });
|
||||
wrapper.vm.questionsData = [
|
||||
{
|
||||
glassLocation: "Windshield",
|
||||
glassName: "Single",
|
||||
answerData: {
|
||||
answerResult: "FW04848",
|
||||
answeredQuestions: [],
|
||||
},
|
||||
},
|
||||
];
|
||||
wrapper.vm.dispatchStoreAction = jest.fn(() => {
|
||||
return {
|
||||
data: {
|
||||
partsOrQuestions: [],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
// // Act
|
||||
// wrapper.vm.forwardButtonAction();
|
||||
// Act
|
||||
wrapper.vm.forwardButtonAction();
|
||||
|
||||
// //Assert
|
||||
// expect(wrapper.vm.questionsData[0].answerData).toEqual({});
|
||||
//Assert
|
||||
expect(wrapper.vm.questionsData[0].answerData).toEqual({});
|
||||
|
||||
// wrapper.unmount();
|
||||
// });
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
// test("Should save to Vuex store", async () => {
|
||||
// // Arrange
|
||||
// const { wrapper } = setupMocks({});
|
||||
test("Should save to pinia store", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// wrapper.vm.questionsData = [
|
||||
// {
|
||||
// glassLocation: "Windshield",
|
||||
// glassName: "Single",
|
||||
// answerData: {
|
||||
// answerResult: "FW04848",
|
||||
// answeredQuestions: [],
|
||||
// },
|
||||
// },
|
||||
// ];
|
||||
// wrapper.vm.dispatchStoreAction = jest.fn(() => {
|
||||
// return {
|
||||
// data: {
|
||||
// glassPieceParts: [],
|
||||
// },
|
||||
// };
|
||||
// });
|
||||
// const spy = jest.spyOn(wrapper.vm, "dispatchStoreAction");
|
||||
wrapper.vm.questionsData = [
|
||||
{
|
||||
glassLocation: "Windshield",
|
||||
glassName: "Single",
|
||||
answerData: {
|
||||
answerResult: "FW04848",
|
||||
answeredQuestions: [],
|
||||
},
|
||||
},
|
||||
];
|
||||
useMainStore().getPartsOrQuestions = jest.fn(() => {
|
||||
return {
|
||||
data: {
|
||||
partsOrQuestions: [],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
// // Act
|
||||
// wrapper.vm.forwardButtonAction();
|
||||
// Act
|
||||
wrapper.vm.forwardButtonAction();
|
||||
|
||||
// await nextTick();
|
||||
await nextTick();
|
||||
|
||||
// //Assert
|
||||
// expect(spy).toHaveBeenNthCalledWith(
|
||||
// 1,
|
||||
// "saveMoldingQuestionAnswers",
|
||||
// [
|
||||
// {
|
||||
// answeredQuestions: [],
|
||||
// glassLocation: "Windshield",
|
||||
// glassName: "Single",
|
||||
// isSuppressedPart: undefined,
|
||||
// partNum: "FW04848",
|
||||
// },
|
||||
// ],
|
||||
// false
|
||||
// );
|
||||
//Assert
|
||||
expect(wrapper.vm.saveMoldingQuestionAnswers).toHaveBeenCalled;
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
// wrapper.unmount();
|
||||
// });
|
||||
test("Should call GET_PARTS_OR_QUESTIONS API", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// 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.questionsData = [
|
||||
// {
|
||||
// glassLocation: "Windshield",
|
||||
// glassName: "Single",
|
||||
// answerData: {
|
||||
// answerResult: "FW04848",
|
||||
// answeredQuestions: [],
|
||||
// },
|
||||
// },
|
||||
// ];
|
||||
// wrapper.vm.dispatchStoreAction = jest.fn(() => {
|
||||
// return {
|
||||
// data: {
|
||||
// glassPieceParts: [],
|
||||
// },
|
||||
// };
|
||||
// });
|
||||
// wrapper.vm.navigateForward = jest.fn();
|
||||
// Act
|
||||
wrapper.vm.forwardButtonAction();
|
||||
|
||||
// // Act
|
||||
// await wrapper.vm.forwardButtonAction();
|
||||
await nextTick();
|
||||
|
||||
// //Assert
|
||||
// expect(wrapper.vm.navigateForward).toHaveBeenCalled();
|
||||
//Assert
|
||||
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({
|
||||
mountOptionsMockData = {
|
||||
router: {
|
||||
navigate: jest.fn(),
|
||||
},
|
||||
store: {
|
||||
getters: store.getters,
|
||||
commit: store.commit,
|
||||
},
|
||||
actionList: [
|
||||
{
|
||||
actionName: "saveMoldingQuestionAnswers",
|
||||
data: {},
|
||||
},
|
||||
{
|
||||
actionName: "getPartsOrQuestions",
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
route: {
|
||||
query: {
|
||||
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({
|
||||
...mountOptionsMockData,
|
||||
mixins: [baseMixin, vehicleQuestionsMixin],
|
||||
|
|
|
|||
Loading…
Reference in a new issue