unit tests for navigation
This commit is contained in:
parent
934dccd37d
commit
54705cc61a
1 changed files with 125 additions and 95 deletions
|
|
@ -1,15 +1,19 @@
|
|||
// Components
|
||||
import licensePlateLookup from "@/layouts/license-plate-lookup/license-plate-lookup.vue";
|
||||
|
||||
// Supporting files
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
// Supporting Files
|
||||
import { settleAllPromises } from "@/helpers/layout-helper.js";
|
||||
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||
import baseMixin from "@/mixins/base-mixin.js";
|
||||
import { shallowMount } from "@vue/test-utils";
|
||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||
import { nextTick } from "vue";
|
||||
import { useMainStore } from "@/store";
|
||||
import { applicationConfig } from "@/constants/application-config";
|
||||
import { nextTick } from "vue";
|
||||
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
|
||||
import e from "express";
|
||||
|
||||
jest.mock("@/helpers/damage-helper", () => ({
|
||||
isGlassAvailableForCarId: jest.fn().mockImplementation(() => true),
|
||||
getDamageString: jest.fn(),
|
||||
}));
|
||||
|
||||
// Mock our module for promises.
|
||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||
|
|
@ -22,27 +26,49 @@ jest.mock("@/helpers/cms-content-helper", () => ({
|
|||
}));
|
||||
|
||||
describe("license-plate-lookup.vue", () => {
|
||||
test("Vehicle make set, arePagePrerequisitesValid should be true", () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
useMainStore().order.vehicle.carId = "CR00000395";
|
||||
describe ("page level alerts", () => {
|
||||
test("License plate matches a different vehicle, display MatchedDifferentVehicleAlert", async () => {
|
||||
// Arrange
|
||||
const mockRegistrationLicensePlate = {
|
||||
licensePlate: "UTN990",
|
||||
};
|
||||
|
||||
//Act
|
||||
licensePlateLookup.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { issPage: "license-plate-lookup" } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
useMainStore().order.vehicle.carId = "C00000";
|
||||
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
await wrapper.setData({
|
||||
licensePlate: mockRegistrationLicensePlate
|
||||
});
|
||||
|
||||
//Assert
|
||||
expect(arePagePrerequisitesValid).toBe(true);
|
||||
// Act
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.findComponent({ ref: "alertMatchedDifferentVehicle" }).isVisible()).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
});
|
||||
})
|
||||
describe ("navigation", () => {
|
||||
test("Vehicle make set, arePagePrerequisitesValid should be true", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
useMainStore().order.vehicle.carId = "CR00000395";
|
||||
|
||||
describe("navigation", () => {
|
||||
// Act
|
||||
licensePlateLookup.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { issPage: "license-plate-lookup" } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
// Assert
|
||||
expect(arePagePrerequisitesValid).toBe(true);
|
||||
});
|
||||
test("BackButtonAction triggers a router.navigate change", async () => {
|
||||
//Arrange
|
||||
const { wrapper, apiPromise } = setupMocks({
|
||||
|
|
@ -59,86 +85,90 @@ describe("navigation", () => {
|
|||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
wrapper.vm.backButtonAction();
|
||||
await nextTick();
|
||||
await wrapper.vm.backButtonAction();
|
||||
|
||||
//Assert
|
||||
return apiPromise.finally(() => {
|
||||
try {
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||
}
|
||||
catch (e) {
|
||||
throw e
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Create test for navigating forward when user clicks Continue
|
||||
// and information entered is correct (no alerts)
|
||||
|
||||
// TODO: Create test for license-plate-question component emitting value when user clicks Continue
|
||||
// and information entered is correct (no alerts)
|
||||
|
||||
// TODO: Create test for zip-question component emitting value when user clicks Continue
|
||||
// and information entered is correct (no alerts)
|
||||
|
||||
// *The above will be completed when navigation from page is complete (SSR-179)
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
function setupMocks({
|
||||
pageHeaderWidgetHeaderText = {},
|
||||
pageFooterWidgetCmsContent = {},
|
||||
mountOptionsMockData = {},
|
||||
//Values to set in the state store
|
||||
carId = null,
|
||||
registrationZipCode = null, //"55555",
|
||||
licensePlate = null, //"TESTPLATE",
|
||||
}) {
|
||||
//Mock api responses
|
||||
const apiResponses = {
|
||||
cmsContent: {
|
||||
SiteSubHeaderWidget: pageHeaderWidgetHeaderText,
|
||||
VehicleBannerWidget: {
|
||||
GenericVehicleImage:
|
||||
`${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,
|
||||
|
||||
isZipValid = true,
|
||||
isZipServiceable = true,
|
||||
lookupVinByPlateResponse,
|
||||
partsOrQuestions = [],
|
||||
vehicle = {},
|
||||
carId = "C0000",
|
||||
route = null,
|
||||
})
|
||||
{
|
||||
useMainStore().validateZip = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
isValid: isZipValid,
|
||||
isServiceable: isZipServiceable,
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
useMainStore().lookupVinByPlate = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: lookupVinByPlateResponse
|
||||
? lookupVinByPlateResponse
|
||||
: {
|
||||
licensePlate: "TEST1234",
|
||||
licenseState: "ZZ"
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
partsOrQuestions: partsOrQuestions,
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
const wrapper = shallowMount(
|
||||
licensePlateLookup,
|
||||
getMountOptions({
|
||||
route: route ? route : undefined,
|
||||
router: {
|
||||
navigate: jest.fn(),
|
||||
},
|
||||
mainStore: {
|
||||
order: {
|
||||
vehicle: {
|
||||
carId: carId,
|
||||
registration: {
|
||||
licensePlate: "TESTPLATE",
|
||||
zipCode: "12345",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
})
|
||||
);
|
||||
|
||||
const apiResponses = {
|
||||
serviceZipValidationResponse: {
|
||||
isValid: isZipValid,
|
||||
isServiceable: isZipServiceable,
|
||||
},
|
||||
};
|
||||
|
||||
mountOptionsMockData = {
|
||||
...mountOptionsMockData,
|
||||
router: {
|
||||
navigate: jest.fn(),
|
||||
},
|
||||
store: {
|
||||
getters: {
|
||||
vehicle: {
|
||||
registration: {
|
||||
licensePlate: licensePlate,
|
||||
zipCode: registrationZipCode,
|
||||
},
|
||||
carId: carId,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
vinLookupResponse: {
|
||||
vehicle: vehicle,
|
||||
},
|
||||
};
|
||||
|
||||
const apiPromise = Promise.resolve(apiResponses);
|
||||
|
||||
settleAllPromises.mockImplementation(() => apiPromise);
|
||||
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
|
||||
|
||||
const mountOptions = getMountOptions(mountOptionsMockData);
|
||||
settleAllPromises.mockImplementation(() => apiResponses);
|
||||
|
||||
const wrapper = shallowMount(licensePlateLookup, mountOptions);
|
||||
wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => "");
|
||||
wrapper.vm.setCmsContent = jest.fn();
|
||||
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
|
||||
wrapper.vm.$refs.siteFooter.removeLoader = jest.fn();
|
||||
|
||||
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;
|
||||
|
||||
return { wrapper, apiPromise };
|
||||
return { wrapper };
|
||||
}
|
||||
Loading…
Reference in a new issue