unit testing WIP
This commit is contained in:
parent
3b7dffd82a
commit
50b2310f12
1 changed files with 109 additions and 13 deletions
|
|
@ -8,6 +8,9 @@ import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||||
import baseMixin from "@/mixins/base-mixin.js";
|
import baseMixin from "@/mixins/base-mixin.js";
|
||||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
import { applicationConfig } from "@/constants/application-config";
|
import { applicationConfig } from "@/constants/application-config";
|
||||||
|
import { useMainStore } from "@/store";
|
||||||
|
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
|
||||||
|
|
||||||
// Mock our module for promises.
|
// Mock our module for promises.
|
||||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||||
settleAllPromises: jest.fn(),
|
settleAllPromises: jest.fn(),
|
||||||
|
|
@ -49,26 +52,121 @@ describe("welcome-page.vue", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("navigation", () => {
|
||||||
|
test("if policy and vehicles are found, navigate to policy-vehicle page", async () => {
|
||||||
|
// Arrange
|
||||||
|
const mockvehicles = [
|
||||||
|
{
|
||||||
|
vin: "TEST_VIN",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vin: "TEST_VIN2",
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
await wrapper.setData({
|
||||||
|
isCoverageEnabled : true,
|
||||||
|
vehiclesCount:2,
|
||||||
|
vehiclesFound:mockvehicles
|
||||||
|
});
|
||||||
|
|
||||||
|
useMainStore().order.policy.policyNumber = "p_0001";
|
||||||
|
useMainStore().order.policy.dateOfLoss = "2022-01-28";
|
||||||
|
useMainStore().order.accountNumber = "00000";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||||
|
navigationScenarios.CLICKED_FORWARD_WITH_POLICY_AND_VEHICLES,
|
||||||
|
undefined,
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
mockvehicles
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test("if policy is found, but no vehicles, navigate to vehicle-selection page", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
await wrapper.setData({
|
||||||
|
isCoverageEnabled: true,
|
||||||
|
vehiclesCount: 0,
|
||||||
|
vehiclesFound: null
|
||||||
|
});
|
||||||
|
|
||||||
|
useMainStore().order.policy.policyNumber = "p_0001";
|
||||||
|
useMainStore().order.policy.dateOfLoss = "2022-01-28";
|
||||||
|
useMainStore().order.accountNumber = "00000";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||||
|
navigationScenarios.CLICKED_FORWARD_WITH_POLICY_AND_NO_VEHICLES,
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test("if policy is not found, navigate to policy-holder-details page", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
await wrapper.setData({
|
||||||
|
isCoverageEnabled : true,
|
||||||
|
});
|
||||||
|
|
||||||
|
useMainStore().order.policy.policyNumber = null;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||||
|
navigationScenarios.CLICKED_FORWARD_WITH_NO_POLICY,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function setupMocks({
|
function setupMocks({
|
||||||
pageHeaderWidgetHeaderText = {},
|
pageHeaderWidgetHeaderText = {},
|
||||||
pageFooterWidgetCmsContent = {},
|
pageFooterWidgetCmsContent = {},
|
||||||
mountOptionsMockData = {},
|
mountOptionsMockData = {},
|
||||||
}) {
|
}) {
|
||||||
|
const policies = [{
|
||||||
|
vehicles:[
|
||||||
|
{
|
||||||
|
vin: "TEST_VIN",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vin: "TEST_VIN2",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}];
|
||||||
|
|
||||||
//Mock api responses
|
//Mock api responses
|
||||||
const apiResponses = {
|
const apiResponses = {
|
||||||
cmsContent: {
|
cmsContent: {
|
||||||
SiteSubHeaderWidget: pageHeaderWidgetHeaderText,
|
SiteSubHeaderWidget: pageHeaderWidgetHeaderText,
|
||||||
VehicleBannerWidget: {
|
VehicleBannerWidget: {
|
||||||
GenericVehicleImage:
|
GenericVehicleImage:
|
||||||
`${applicationConfig.ISS_DEV_CMS_DOMAIN}/images/default-source/default-album/blurred-image.jpg`,
|
`${applicationConfig.ISS_DEV_CMS_DOMAIN}/images/default-source/default-album/blurred-image.jpg`,
|
||||||
|
},
|
||||||
|
SiteHeaderWidget: {
|
||||||
|
LogoImage:
|
||||||
|
`${applicationConfig.ISS_DEV_CMS_DOMAIN}/images/default-source/default-album/logos/insuranceLogo.jpg`,
|
||||||
|
},
|
||||||
|
SiteFooterWidget: pageFooterWidgetCmsContent,
|
||||||
},
|
},
|
||||||
SiteHeaderWidget: {
|
policyLookupResponse:{
|
||||||
LogoImage:
|
policies: policies
|
||||||
`${applicationConfig.ISS_DEV_CMS_DOMAIN}/images/default-source/default-album/logos/insuranceLogo.jpg`,
|
}
|
||||||
},
|
|
||||||
SiteFooterWidget: pageFooterWidgetCmsContent,
|
|
||||||
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mountOptionsMockData = {
|
mountOptionsMockData = {
|
||||||
|
|
@ -76,8 +174,6 @@ function setupMocks({
|
||||||
router: {
|
router: {
|
||||||
navigate: jest.fn(),
|
navigate: jest.fn(),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const apiPromise = Promise.resolve(apiResponses);
|
const apiPromise = Promise.resolve(apiResponses);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue