update unit test coverage

This commit is contained in:
Adam Caouette 2022-10-05 23:29:33 -04:00
parent 6e06c32c50
commit 41a27cc427

View file

@ -155,6 +155,126 @@ describe("vehicle-questions-mixin", () => {
});
});
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 = [[fmgPageValues.PART_QUESTIONS, fmgPageValues.VEHICLE_PARTS, true],
[fmgPageValues.VEHICLE_PARTS, fmgPageValues.VEHICLE_PARTS, false],
@ -195,6 +315,94 @@ describe("vehicle-questions-mixin", () => {
})
});
describe("setupInitialData", () => {
describe("should always", () => {
test("return glass with new key attribute", async () => {
// Arrange
const { wrapper } = setupMocks({});
const glass = {
"glassName": "Single",
"glassLocation": "Windshield",
};
const i = 0;
// Act
const returnedGlass = await wrapper.vm.setupInitialData(glass, i);
// Assert
expect(returnedGlass).toMatchObject({"key": "Windshield-Single"});
});
});
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("navigateForward", () => {
describe("should go to parts-questions", () => {
test("single glass location has part question => go to parts-questions", async () => {
@ -1160,6 +1368,18 @@ describe("vehicle-questions-mixin", () => {
expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_WITH_NO_QUESTIONS, {"query": {"fmgPage": fmgPageValues.QUOTE}})
})
test("current page is quote and there are capability questions => go to capability questions", () => {
// Arrange
const { wrapper } = setupMocks({ fmgPage: fmgPageValues.QUOTE });
wrapper.vm.hasCapabilityQuestions = jest.fn().mockReturnValue(true);
// Act
wrapper.vm.backButtonAction();
// Assert
expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK_WITH_CAPABILITY_QUESTIONS, {"query": {"fmgPage": fmgPageValues.QUOTE}})
})
test("current page is quote and there are part questions and molding questions => go to molding questions", () => {
// Arrange
const { wrapper } = setupMocks({ fmgPage: fmgPageValues.QUOTE });
@ -1209,7 +1429,15 @@ function setupMocks({ fmgPage = fmgPageValues.VIN_LOOKUP }) {
const baseMixin = setupMocksForJsFiles({
actionList: [{
actionName: storeActions.GET_CAPABILITY_QUESTIONS,
data: [],
data: [
{
answers: [
{
answerResult1: "testing"
}
]
}
],
}]
});