EOD commit - unit testing for coverage statement
This commit is contained in:
parent
7310d43c1a
commit
219a8964de
2 changed files with 160 additions and 80 deletions
|
|
@ -1,115 +1,195 @@
|
|||
// Components
|
||||
import coverageStatement from "@/layouts/coverage-statement/coverage-statement.vue";
|
||||
|
||||
// Supporting Files
|
||||
// Supporting files
|
||||
import { shallowMount } from "@vue/test-utils";
|
||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||
import { useMainStore } from "@/store";
|
||||
import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
|
||||
import baseFormMixin from "@/mixins/base-form-mixin";
|
||||
import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
|
||||
import { applicationConfig } from "@/constants/application-config";
|
||||
//import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||
import { settleAllPromises } from "@/helpers/layout-helper.js";
|
||||
|
||||
jest.mock("@/helpers/damage-helper", () => ({
|
||||
getDamageString: jest.fn(),
|
||||
}));
|
||||
|
||||
// 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(),
|
||||
}));
|
||||
// // Mock fetchCmsContentForPage
|
||||
// jest.mock("@/helpers/cms-content-helper", () => ({
|
||||
// fetchCmsContentForPage: jest.fn(),
|
||||
// }));
|
||||
|
||||
describe("coverage-statement.vue", () => {
|
||||
describe("display correct coverage statement", () => {
|
||||
test("If damage is Repair, display NonADASRepairNextSteps statement", async () => {
|
||||
describe("coverage-statement.vue...", () => {
|
||||
describe("method arePagePrerequisitesValid...", () => {
|
||||
test("Should return true for valid page requisites if carId exists", () => {
|
||||
// Arrange
|
||||
useMainStore().pageData = jest.fn();
|
||||
useMainStore().lineItems = { glassParts: null};
|
||||
useMainStore().order.damage.isRepair = true;
|
||||
|
||||
const { wrapper, cmsContent } = setupMocks({});
|
||||
|
||||
useMainStore().lineItems = {
|
||||
glassParts:
|
||||
[
|
||||
{
|
||||
partNumber: "DQ12204GTYNOEM",
|
||||
requiresRecalibration: false,
|
||||
}
|
||||
]
|
||||
};
|
||||
useMainStore().vehicle = { carId: "TEST_CAR_ID" };
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
|
||||
//Act
|
||||
coverageStatement.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { issPage: "coverage-statement" } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
// Act
|
||||
const result = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
// Assert
|
||||
expect(wrapper).toBeVisible();
|
||||
})
|
||||
})
|
||||
})
|
||||
//Assert
|
||||
expect(result).toBe(true);
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test("Should return false for valid page requisites if carId is missing", () => {
|
||||
// Arrange
|
||||
useMainStore().lineItems = {
|
||||
glassParts:
|
||||
[
|
||||
{
|
||||
partNumber: "DQ12204GTYNOEM",
|
||||
requiresRecalibration: false,
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
useMainStore().vehicle = { carId: null };
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
//Assert
|
||||
expect(result).toBeFalsy();
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const mockMixin = {
|
||||
methods: {
|
||||
getCmsContent: jest.fn((contentName) => {
|
||||
if (contentName === "UnverifiedADASNextStepsWidget") {
|
||||
return "ADASReplaceTestReturn"
|
||||
}
|
||||
else if (contentName === "UnverifiedNonADASNextStepsWidget") {
|
||||
return "NonADASReplaceTestReturn"
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
}
|
||||
};
|
||||
|
||||
function setupMocks({
|
||||
cmsWidgetName = "CMS widget name goes here",
|
||||
mountOptionsMockData = {
|
||||
router: {
|
||||
navigate: jest.fn(),
|
||||
},
|
||||
actionList: [
|
||||
{
|
||||
actionName: "getPartsOrQuestions",
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
route: {
|
||||
query: {
|
||||
issPage: "coverage-statement",
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
computedSwitcher: [
|
||||
{
|
||||
glassLocation: "Windshield",
|
||||
glassName: "Single",
|
||||
answerData: {
|
||||
answerResult: "FW04848",
|
||||
answeredQuestions: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
questionsData: {
|
||||
get() {
|
||||
return this.computedSwitcher;
|
||||
},
|
||||
set(val) {
|
||||
this.computedSwitcher = val;
|
||||
},
|
||||
},
|
||||
},
|
||||
cmsBodyText = "Body text goes here",
|
||||
//pageHeaderWidgetHeaderText,
|
||||
// mountOptionsMockData = {
|
||||
// router: {
|
||||
// navigate: jest.fn()
|
||||
// },
|
||||
// route: {
|
||||
// query: {
|
||||
// issPage: "coverage-statement",
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}) {
|
||||
|
||||
useMainStore().getPartsOrQuestions = jest.fn(() => {
|
||||
return {
|
||||
data: {
|
||||
partsOrQuestions: [],
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
useMainStore().order = {
|
||||
vehicle: {
|
||||
carId: "TEST",
|
||||
},
|
||||
lineItems: {
|
||||
glassParts: [
|
||||
{
|
||||
canSafeliteRecalibrate: false,
|
||||
childParts: null,
|
||||
color: "Green Tint",
|
||||
description: "solar, driver side, encap",
|
||||
partNumber: "DQ12204GTYNOEM",
|
||||
partType: "DRIVER REAR QUARTER GLASS",
|
||||
recalibrationType: null,
|
||||
requiresCapabilityQuestions: false,
|
||||
requiresRecalibration: false,
|
||||
}
|
||||
]
|
||||
},
|
||||
damage: {
|
||||
isRepair: false,
|
||||
}
|
||||
};
|
||||
const mountOptions = getMountOptions({
|
||||
...mountOptionsMockData,
|
||||
mixins: [baseFormMixin, vehicleQuestionsMixin],
|
||||
// ...mountOptionsMockData,
|
||||
// mixins: [baseFormMixin, vehicleQuestionsMixin],
|
||||
});
|
||||
mountOptions["attachTo"] = document.body;
|
||||
//mountOptions["attachTo"] = document.body;
|
||||
|
||||
// const apiResponses = {
|
||||
// cmsContent: {
|
||||
// SiteHeaderWidget: {
|
||||
// LogoImage:
|
||||
// `${applicationConfig.ISS_DEV_CMS_DOMAIN}/images/default-source/default-album/logos/insuranceLogo.jpg`,
|
||||
// },
|
||||
// SiteSubHeaderWidget: pageHeaderWidgetHeaderText,
|
||||
// verifyingCoverageStatement: "We're verifying your coverage",
|
||||
// continueWithSchedulingCopy: "Go ahead and continue with scheduling while we verify your coverage. We'll let you know what deductible amount, if any, applies.",
|
||||
// whatHappensNextCopy: "What happens next:",
|
||||
// UnverifiedADASNextStepsWidget: {
|
||||
// BodyText: "ADASReplace body text goes here",
|
||||
// },
|
||||
// UnverifiedNonADASNextStepsWidget: {
|
||||
// BodyText: "NonADASReplace body text goes here",
|
||||
// },
|
||||
// UnverifiedNonADASRepairWidget: {
|
||||
// BodyText: "NonADASRepair body text goes here",
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
|
||||
|
||||
// const apiResponses = {
|
||||
// cmsContent: {},
|
||||
// };
|
||||
|
||||
|
||||
mountOptions.mixins = [mockMixin];
|
||||
//settleAllPromises.mockImplementation(() => apiResponses);
|
||||
//fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
|
||||
|
||||
const wrapper = shallowMount(coverageStatement, mountOptions);
|
||||
|
||||
//Mock CMS content
|
||||
const cmsContent = {
|
||||
Name: cmsWidgetName,
|
||||
BodyText: cmsBodyText,
|
||||
// UnverifiedADASNextStepsWidget: {
|
||||
// BodyText: "ADASReplace body text goes here",
|
||||
// },
|
||||
// UnverifiedNonADASNextStepsWidget: {
|
||||
// BodyText: "NonADASReplace body text goes here",
|
||||
// },
|
||||
// UnverifiedNonADASRepairWidget: {
|
||||
// BodyText: "NonADASRepair body text goes here",
|
||||
// },
|
||||
};
|
||||
|
||||
//wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => "");
|
||||
//wrapper.vm.setCmsContent = jest.fn();
|
||||
|
||||
return { wrapper, cmsContent };
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
cmsWidgetName="whatHappensNextCopy"
|
||||
class="mt-4 mb-2 fw-bold"
|
||||
/>
|
||||
<div v-html="bodyText"></div>
|
||||
<div v-html="bodyText" ref="coverageStatementBodyText"></div>
|
||||
<recalModal cmsWidgetName="RecalModal" />
|
||||
<siteFooter
|
||||
cmsWidgetName="SiteFooterWidget"
|
||||
|
|
|
|||
Loading…
Reference in a new issue