finished up unit tests for license-plate-lookup
This commit is contained in:
parent
73edb7f457
commit
af50c7c31e
1 changed files with 114 additions and 136 deletions
|
|
@ -6,9 +6,7 @@ import { settleAllPromises } from "@/helpers/layout-helper.js";
|
|||
import { shallowMount } from "@vue/test-utils";
|
||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||
import { useMainStore } from "@/store";
|
||||
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),
|
||||
|
|
@ -17,16 +15,16 @@ jest.mock("@/helpers/damage-helper", () => ({
|
|||
|
||||
// Mock our module for promises.
|
||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||
settleAllPromises: jest.fn(),
|
||||
settleAllPromises: jest.fn(),
|
||||
}));
|
||||
|
||||
|
||||
// Mock fetchCmsContentForPage
|
||||
jest.mock("@/helpers/cms-content-helper", () => ({
|
||||
fetchCmsContentForPage: jest.fn(),
|
||||
fetchCmsContentForPage: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("license-plate-lookup.vue", () => {
|
||||
describe ("page level alerts", () => {
|
||||
describe("page level alerts", () => {
|
||||
test("If license plate matches a different vehicle, display MatchedDifferentVehicleAlert", async () => {
|
||||
// Arrange
|
||||
const mockRegistrationLicensePlate = {
|
||||
|
|
@ -34,11 +32,11 @@ describe("license-plate-lookup.vue", () => {
|
|||
};
|
||||
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
|
||||
useMainStore().order.vehicle.carId = "TESTCARID";
|
||||
|
||||
await wrapper.setData({
|
||||
licensePlate: mockRegistrationLicensePlate
|
||||
await wrapper.setData({
|
||||
licensePlate: mockRegistrationLicensePlate
|
||||
});
|
||||
|
||||
// Act
|
||||
|
|
@ -46,9 +44,10 @@ describe("license-plate-lookup.vue", () => {
|
|||
|
||||
// Assert
|
||||
expect(wrapper.findComponent({ ref: "alertMatchedDifferentVehicle" }).isVisible()).toBe(
|
||||
true
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
test("If no vehicles found, display VinNotFound alert", async () => {
|
||||
// Arrange
|
||||
const mockRegistrationLicensePlate = {
|
||||
|
|
@ -72,11 +71,11 @@ describe("license-plate-lookup.vue", () => {
|
|||
|
||||
// Assert
|
||||
expect(wrapper.findComponent({ ref: "alertVinNotFound" }).isVisible()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
describe ("navigation", () => {
|
||||
test("BackButtonAction triggers a router.navigate change", async () => {
|
||||
describe("navigation", () => {
|
||||
test("Clicking back button navigates back", async () => {
|
||||
//Arrange
|
||||
const { wrapper, apiPromise } = setupMocks({
|
||||
mountOptionsMockData: {
|
||||
|
|
@ -93,36 +92,10 @@ describe("license-plate-lookup.vue", () => {
|
|||
(c) => c(wrapper.vm)
|
||||
);
|
||||
await wrapper.vm.backButtonAction();
|
||||
|
||||
|
||||
//Assert
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||
});
|
||||
test("If a different vehicle is found than the one entered and the selected glass is not available for that vehicle, navigate back to vehicle-damage page", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
await wrapper.setData({
|
||||
isCarIdDifferent: true,
|
||||
isSelectedGlassAvailableForVehicle: false,
|
||||
});
|
||||
|
||||
useMainStore().order.vehicle.carId = "CARID";
|
||||
|
||||
let vehicleFound = {
|
||||
carId: "C0000",
|
||||
};
|
||||
|
||||
// Act
|
||||
await wrapper.vm.navigateForward(vehicleFound);
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||
navigationScenarios.SELECTED_VIN_WITH_MISMATCHED_GLASS,
|
||||
undefined,
|
||||
{},
|
||||
{ displayVehicleChangeAlert: true }
|
||||
);
|
||||
});
|
||||
|
||||
test("License plate found and matches entered vehicle => navigateForwardWithSingleCarMatch", async () => {
|
||||
// Arrange
|
||||
|
|
@ -140,59 +113,65 @@ describe("license-plate-lookup.vue", () => {
|
|||
|
||||
// Assert
|
||||
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("navigateForwardWithSingleCarMatch should be called if isCarIdDifferent is false or isSelectedGlassAvailableForVehicle is true when navigateForward is called", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
//Act
|
||||
await wrapper.setData({
|
||||
isCarIdDifferent: false,
|
||||
});
|
||||
wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => {
|
||||
return "";
|
||||
|
||||
test("if a different vehicle is found than the one entered and the selected glass is not available for that vehicle, navigate back to vehicle-damage page", async () => {
|
||||
// Arrange
|
||||
const mockRegistrationLicensePlate = {
|
||||
licensePlate: "TEST1234",
|
||||
};
|
||||
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
await wrapper.setData({
|
||||
licensePlate: mockRegistrationLicensePlate,
|
||||
isCarIdDifferent: true,
|
||||
isSelectedGlassAvailableForVehicle: false,
|
||||
});
|
||||
|
||||
useMainStore().order.vehicle.carId = "CARID";
|
||||
|
||||
let carsFound = [
|
||||
{
|
||||
vin: "TEST_VIN2",
|
||||
vehicle: {
|
||||
carId: "C0000",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Act
|
||||
await wrapper.vm.navigateForward(carsFound);
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||
navigationScenarios.SELECTED_VIN_WITH_MISMATCHED_GLASS,
|
||||
undefined,
|
||||
{},
|
||||
{ displayVehicleChangeAlert: true }
|
||||
);
|
||||
});
|
||||
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||
await wrapper.vm.navigateForward();
|
||||
|
||||
//Assert
|
||||
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
describe ("miscellaneous", () => {
|
||||
test("Button Text should revert to initial value when registrationZip textfield has new text", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
//Act
|
||||
await wrapper.setData({
|
||||
registrationZipCode: "55555",
|
||||
describe("miscellaneous", () => {
|
||||
test("Vehicle make set, arePagePrerequisitesValid should be true", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
useMainStore().order.vehicle.carId = "CR00000395";
|
||||
|
||||
// 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);
|
||||
});
|
||||
wrapper.vm.getCmsContent = jest.fn();
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
//Assert
|
||||
expect(wrapper.vm.$refs.siteFooter.updateButtonText).toHaveBeenCalled();
|
||||
});
|
||||
test("Vehicle make set, arePagePrerequisitesValid should be true", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
useMainStore().order.vehicle.carId = "CR00000395";
|
||||
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -206,69 +185,68 @@ function setupMocks({
|
|||
carId = "C0000",
|
||||
vinLookupResponseError = null,
|
||||
route = null,
|
||||
})
|
||||
{
|
||||
}) {
|
||||
useMainStore().validateZip = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
isValid: isZipValid,
|
||||
isServiceable: isZipServiceable,
|
||||
},
|
||||
})
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
isValid: isZipValid,
|
||||
isServiceable: isZipServiceable,
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
useMainStore().lookupVinByPlate = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: lookupVinByPlateResponse
|
||||
? lookupVinByPlateResponse: {
|
||||
vin: "TEST_VIN",
|
||||
vehicle: {
|
||||
carId: "CARID"
|
||||
},
|
||||
return Promise.resolve({
|
||||
data: lookupVinByPlateResponse
|
||||
? lookupVinByPlateResponse : {
|
||||
vin: "TEST_VIN",
|
||||
vehicle: {
|
||||
carId: "CARID"
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
partsOrQuestions: partsOrQuestions,
|
||||
},
|
||||
})
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
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,
|
||||
},
|
||||
vinLookupResponse: {
|
||||
vin: vin,
|
||||
vehicle: vehicle,
|
||||
error: vinLookupResponseError,
|
||||
},
|
||||
serviceZipValidationResponse: {
|
||||
isValid: isZipValid,
|
||||
isServiceable: isZipServiceable,
|
||||
},
|
||||
vinLookupResponse: {
|
||||
vin: vin,
|
||||
vehicle: vehicle,
|
||||
error: vinLookupResponseError,
|
||||
},
|
||||
};
|
||||
|
||||
settleAllPromises.mockImplementation(() => apiResponses);
|
||||
|
|
|
|||
Loading…
Reference in a new issue