253 lines
8.5 KiB
JavaScript
253 lines
8.5 KiB
JavaScript
// Components
|
|
import questionsPageLayout from "./questions-page-layout";
|
|
|
|
// Supporting Files
|
|
import { shallowMount } from "@vue/test-utils";
|
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
|
import baseMixin from "../../../mixins/base-mixin";
|
|
import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
|
|
|
|
// Mock our module for promises.
|
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
|
settleAllPromises: jest.fn(),
|
|
}));
|
|
|
|
// Mock fetchCmsContentForPage
|
|
jest.mock("@/helpers/cms-content-helper", () => ({
|
|
fetchCmsContentForPage: jest.fn(),
|
|
}));
|
|
|
|
jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({
|
|
navigateToHeritageFunnel: jest.fn(),
|
|
}));
|
|
|
|
describe("questionsPageLayout.vue", () => {
|
|
describe("method showThisQuestionChain...", () => {
|
|
test("Should return true if index prop and passed index match", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
await wrapper.setProps({ index: 0 });
|
|
|
|
const testGlassPiece = {
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
"Is your vehicle equipped with the optional Lane-Keeping System which tugs on the steering wheel and/or beeps to alert you if you drift too close to the edge of the lane?",
|
|
answers: [],
|
|
},
|
|
],
|
|
};
|
|
const testIndex = 0;
|
|
|
|
// Act
|
|
const result = wrapper.vm.showThisQuestionChain(testGlassPiece, testIndex);
|
|
|
|
//Assert
|
|
expect(result).toBe(true);
|
|
|
|
wrapper.unmount();
|
|
});
|
|
|
|
test("Should return true if answerResult exists", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
await wrapper.setProps({ index: 0 });
|
|
|
|
const testGlassPiece = {
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
"Is your vehicle equipped with the optional Lane-Keeping System which tugs on the steering wheel and/or beeps to alert you if you drift too close to the edge of the lane?",
|
|
answers: [],
|
|
},
|
|
],
|
|
answerData: {
|
|
answerResult: "test",
|
|
},
|
|
};
|
|
const testIndex = 1;
|
|
|
|
// Act
|
|
const result = wrapper.vm.showThisQuestionChain(testGlassPiece, testIndex);
|
|
|
|
//Assert
|
|
expect(result).toBe(true);
|
|
|
|
wrapper.unmount();
|
|
});
|
|
|
|
test("Should return false if indexes don't match and answerResult is missing", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
await wrapper.setProps({ index: 0 });
|
|
|
|
const testGlassPiece = {
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
"Is your vehicle equipped with the optional Lane-Keeping System which tugs on the steering wheel and/or beeps to alert you if you drift too close to the edge of the lane?",
|
|
answers: [],
|
|
},
|
|
],
|
|
};
|
|
const testIndex = 1;
|
|
|
|
// Act
|
|
const result = wrapper.vm.showThisQuestionChain(testGlassPiece, testIndex);
|
|
|
|
//Assert
|
|
expect(result).toBe(false);
|
|
|
|
wrapper.unmount();
|
|
});
|
|
|
|
test("Should return false if no questions", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
await wrapper.setProps({ index: 0 });
|
|
|
|
const testGlassPiece = {};
|
|
const testIndex = 0;
|
|
|
|
// Act
|
|
const result = wrapper.vm.showThisQuestionChain(testGlassPiece, testIndex);
|
|
|
|
//Assert
|
|
expect(result).toBe(false);
|
|
|
|
wrapper.unmount();
|
|
});
|
|
|
|
test("Should return false if suppressed", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
await wrapper.setProps({ index: 0 });
|
|
|
|
const testGlassPiece = {
|
|
isSuppressedPart: true,
|
|
questions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
"Is your vehicle equipped with the optional Lane-Keeping System which tugs on the steering wheel and/or beeps to alert you if you drift too close to the edge of the lane?",
|
|
answers: [],
|
|
},
|
|
],
|
|
answerData: {
|
|
answerResult: "test",
|
|
},
|
|
};
|
|
const testIndex = 0;
|
|
|
|
// Act
|
|
const result = wrapper.vm.showThisQuestionChain(testGlassPiece, testIndex);
|
|
|
|
//Assert
|
|
expect(result).toBe(false);
|
|
|
|
wrapper.unmount();
|
|
});
|
|
});
|
|
|
|
describe("method handleForwardButtonAction...", () => {
|
|
test("Should emit forwardButtonAction", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
await wrapper.setProps({});
|
|
|
|
// Act
|
|
wrapper.vm.handleForwardButtonAction();
|
|
|
|
//Assert
|
|
expect(wrapper.emitted()).toHaveProperty("forwardButtonAction");
|
|
|
|
wrapper.unmount();
|
|
});
|
|
});
|
|
|
|
describe("method handleBackButtonAction...", () => {
|
|
test("Should emit backButtonAction", async () => {
|
|
// Arrange
|
|
const { wrapper } = setupMocks({});
|
|
await wrapper.setProps({});
|
|
|
|
// Act
|
|
wrapper.vm.handleBackButtonAction();
|
|
|
|
//Assert
|
|
expect(wrapper.emitted()).toHaveProperty("back-click");
|
|
|
|
wrapper.unmount();
|
|
});
|
|
});
|
|
});
|
|
|
|
function setupMocks() {
|
|
const baseStoreGettersPageData = () => {
|
|
return {
|
|
partsOrQuestions: [
|
|
{
|
|
parts: null,
|
|
partQuestions: [
|
|
{
|
|
questionSequence: 1,
|
|
questionText:
|
|
"Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?",
|
|
answers: [
|
|
{
|
|
answerResult: "",
|
|
answerText: "Yes",
|
|
nextQuestionSequence: 2,
|
|
},
|
|
{
|
|
answerResult: "",
|
|
answerText: "No",
|
|
nextQuestionSequence: 3,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
answerKey: "Windshield-Single",
|
|
answerData: null,
|
|
},
|
|
],
|
|
};
|
|
};
|
|
const baseStoreGettersDamage = () => {
|
|
return {
|
|
partsQuestionAnswers: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
result: "FW04848",
|
|
answeredQuestions: [
|
|
{
|
|
questionText:
|
|
"Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?",
|
|
selectedAnswerText: "Yes",
|
|
questionNum: 1,
|
|
},
|
|
{
|
|
questionText:
|
|
"Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?",
|
|
selectedAnswerText: "Yes",
|
|
questionNum: 2,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
};
|
|
const mountOptions = getMountOptions({
|
|
mixins: [baseMixin, vehicleQuestionsMixin],
|
|
});
|
|
mountOptions["attachTo"] = document.body;
|
|
const wrapper = shallowMount(questionsPageLayout, mountOptions);
|
|
|
|
return { wrapper };
|
|
}
|