display correct coverage statement unit tests

This commit is contained in:
Kroell 2023-03-08 15:44:13 -05:00
parent 219a8964de
commit b3bb54a2ba
2 changed files with 126 additions and 110 deletions

View file

@ -5,10 +5,10 @@ import coverageStatement from "@/layouts/coverage-statement/coverage-statement.v
import { shallowMount } from "@vue/test-utils";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import { useMainStore } from "@/store";
import baseFormMixin from "@/mixins/base-form-mixin";
import baseMixin from "@/mixins/base-mixin";
import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
import { applicationConfig } from "@/constants/application-config";
//import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
import { settleAllPromises } from "@/helpers/layout-helper.js";
jest.mock("@/helpers/damage-helper", () => ({
@ -20,62 +20,105 @@ 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("method arePagePrerequisitesValid...", () => {
test("Should return true for valid page requisites if carId exists", () => {
test("Should return true for valid page requisites if vin exists", () => {
// Arrange
useMainStore().lineItems = {
glassParts:
[
{
partNumber: "DQ12204GTYNOEM",
requiresRecalibration: false,
}
]
};
useMainStore().vehicle = { carId: "TEST_CAR_ID" };
const { wrapper } = setupMocks({});
// Act
const result = wrapper.vm.arePagePrerequisitesValid();
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
//Assert
expect(result).toBe(true);
wrapper.unmount();
expect(arePagePrerequisitesValid).toBe(true);
});
test("Should return false for valid page requisites if carId is missing", () => {
test("Should return false for valid page requisites if vin is missing", () => {
// Arrange
useMainStore().lineItems = {
glassParts:
[
{
partNumber: "DQ12204GTYNOEM",
requiresRecalibration: false,
}
]
};
const { wrapper } = setupMocks({});
useMainStore().vehicle = { carId: null };
useMainStore().order.vehicle.vin = null;
// Act
const result = wrapper.vm.arePagePrerequisitesValid();
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
//Assert
expect(result).toBeFalsy();
wrapper.unmount();
expect(arePagePrerequisitesValid).toBe(false);
});
});
describe("navigation", () => {
// test("Vehicle has part questions, navigateBack triggers a router.navigate change with correct scenario", async () => {
// //Arrange
// const { wrapper } = setupMocks({
// mountOptionsMockData: {
// router: {
// navigate: jest.fn(),
// },
// route: {
// query: {
// issPage: "coverage-statement",
// },
// },
// },
// });
// //Act
// coverageStatement.beforeRouteEnter.call(
// wrapper.vm,
// { query: { issPage: "coverage-statement" } },
// undefined,
// (c) => c(wrapper.vm)
// );
// wrapper.vm.navigateBack();
// //Assert
// expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
// navigationScenarios.CLICKED_BACK_WITH_NO_VIN_NOR_QUESTIONS,
// wrapper.vm.$route
// );
// });
});
describe("display correct coverage statement", () => {
test("If damage is Repair, display NonADASRepair coverage statement", async () => {
// Arrange
const wrapper = shallowMount(coverageStatement, {
mixins: [mockMixin],
});
useMainStore().order.damage.isRepair = true;
// Assert
expect(wrapper.vm.unverifiedNonADASRepairBodyText).toEqual("NonADASRepairTestReturn");
})
test("If damage is NonADAS Replace, display NonADASReplace coverage statement", async () => {
// Arrange
const wrapper = shallowMount(coverageStatement, {
mixins: [mockMixin],
});
// Assert
expect(wrapper.vm.unverifiedNonADASNextStepsBodyText).toEqual("NonADASReplaceTestReturn");
})
test("If damage is ADAS Replace, display ADASReplace coverage statement", async () => {
// Arrange
const wrapper = shallowMount(coverageStatement, {
mixins: [mockMixin],
});
useMainStore().order.lineItems.requiresRecalibration = true;
// Assert
expect(wrapper.vm.unverifiedADASNextStepsBodyText).toEqual("ADASReplaceTestReturn");
})
})
});
const mockMixin = {
@ -84,6 +127,9 @@ const mockMixin = {
if (contentName === "UnverifiedADASNextStepsWidget") {
return "ADASReplaceTestReturn"
}
else if (contentName === "UnverifiedNonADASRepairWidget") {
return "NonADASRepairTestReturn"
}
else if (contentName === "UnverifiedNonADASNextStepsWidget") {
return "NonADASReplaceTestReturn"
}
@ -93,22 +139,30 @@ const mockMixin = {
};
function setupMocks({
cmsBodyText = "Body text goes here",
//pageHeaderWidgetHeaderText,
// mountOptionsMockData = {
// router: {
// navigate: jest.fn()
// },
// route: {
// query: {
// issPage: "coverage-statement",
// }
// }
// }
pageHeaderWidgetHeaderText,
// cmsPageContent = "CMS content goes here",
// unverifiedNonADASRepairBodyText = "repair body text",
}) {
//Mock api responses
const apiResponses = {
cmsContent: {
SiteSubHeaderWidget: pageHeaderWidgetHeaderText,
FunnelHeaderWidget: {
LogoImage:
`${applicationConfig.ISS_DEV_CMS_DOMAIN}/images/default-source/default-album/logos/insuranceLogo.jpg`,
},
ColorQuestionWidget: "Please choose your rear window tint color",
FeatureQuestionWidget: "Ok no choose features",
AlertWidget: {
BodyText: "Please choose your tint color",
HeadlineText: "Just a few more steps to go",
},
unverifiedNonADASRepairBodyText: "Repair body text",
},
};
useMainStore().order = {
vehicle: {
carId: "TEST",
vin: "TESTVIN",
},
lineItems: {
glassParts: [
@ -129,67 +183,29 @@ function setupMocks({
isRepair: false,
}
};
const apiPromise = Promise.resolve(apiResponses);
settleAllPromises.mockImplementation(() => apiPromise);
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
const mountOptions = getMountOptions({
// ...mountOptionsMockData,
// mixins: [baseFormMixin, vehicleQuestionsMixin],
});
//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());
mountOptions.mixins = [baseMixin, vehicleQuestionsMixin];
const wrapper = shallowMount(coverageStatement, mountOptions);
//Mock CMS content
const cmsContent = {
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 };
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;
// //Mock CMS content
// const cmsContent = {
// PageContent: cmsPageContent,
// NonADASRepairBodyText: unverifiedNonADASRepairBodyText,
// };
return { wrapper };
}

View file

@ -84,16 +84,16 @@ export default {
}
},
continueWithSchedulingBodyText() {
return this.getCmsContent('continueWithSchedulingCopy', 'BodyText');
return this.getCmsContent("continueWithSchedulingCopy", "BodyText");
},
unverifiedADASNextStepsBodyText() {
return this.getCmsContent('UnverifiedADASNextStepsWidget', 'BodyText').replaceAll("{custom:damage}", this.damageText);
return this.getCmsContent("UnverifiedADASNextStepsWidget", "BodyText").replaceAll("{custom:damage}", this.damageText);
},
unverifiedNonADASNextStepsBodyText() {
return this.getCmsContent('UnverifiedNonADASNextStepsWidget', 'BodyText').replaceAll("{custom:damage}", this.damageText);
return this.getCmsContent("UnverifiedNonADASNextStepsWidget", "BodyText").replaceAll("{custom:damage}", this.damageText);
},
unverifiedNonADASRepairBodyText() {
return this.getCmsContent('UnverifiedNonADASRepairWidget', 'BodyText');
return this.getCmsContent("UnverifiedNonADASRepairWidget", "BodyText");
},
damageText() {
var damageString = getDamageString();
@ -120,7 +120,7 @@ export default {
},
methods: {
arePagePrerequisitesValid() {
if (useMainStore().order.vehicle.carId) {
if (useMainStore().order.vehicle.vin) {
return true;
}
return false;