CSR-466 Add tests
This commit is contained in:
parent
1bef672ec1
commit
d5efa00f05
7 changed files with 253 additions and 118 deletions
|
|
@ -20,9 +20,8 @@ module.exports = {
|
||||||
"!src/layouts/reveal/**/*.vue",
|
"!src/layouts/reveal/**/*.vue",
|
||||||
"!src/layouts/estimate/**/*.vue",
|
"!src/layouts/estimate/**/*.vue",
|
||||||
// TODO REMOVE THESE AFTER WRITING UNIT TESTS
|
// TODO REMOVE THESE AFTER WRITING UNIT TESTS
|
||||||
"!src/layouts/address-vehicles/address-vehicles.vue",
|
|
||||||
"!src/layouts/address-vehicles/address-vehicles-question/address-vehicles-question.vue",
|
"!src/layouts/address-vehicles/address-vehicles-question/address-vehicles-question.vue",
|
||||||
"!src/ux-components/alert\alert.vue",
|
"!src/ux-components/alert/alert.vue",
|
||||||
"!src/helpers/validation-rules.js",
|
"!src/helpers/validation-rules.js",
|
||||||
// END
|
// END
|
||||||
], // ! means exclude from coverage.
|
], // ! means exclude from coverage.
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
"build": "vue-cli-service build",
|
"build": "vue-cli-service build",
|
||||||
"test:unit": "vue-cli-service test:unit",
|
"test:unit": "vue-cli-service test:unit --coverage --ci",
|
||||||
"test:unit:lite": "vue-cli-service test:unit --ci",
|
"test:unit:lite": "vue-cli-service test:unit --ci",
|
||||||
"lint": "vue-cli-service lint"
|
"lint": "vue-cli-service lint"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,6 @@ describe("address-lookup.vue", () => {
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.updateVehicleInfo).toHaveBeenCalled();
|
expect(wrapper.vm.updateVehicleInfo).toHaveBeenCalled();
|
||||||
expect(navigateAfterSaveToHeritageFunnel).toHaveBeenCalled();
|
expect(navigateAfterSaveToHeritageFunnel).toHaveBeenCalled();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("if the car entered does not match any of the multiple vehicles found, navigate to address-vehicles page", async () => {
|
test("if the car entered does not match any of the multiple vehicles found, navigate to address-vehicles page", async () => {
|
||||||
|
|
@ -371,17 +370,17 @@ describe("address-lookup.vue", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const carsFound = [{
|
const carsFound = [{
|
||||||
vin: "TEST_VIN",
|
vin: "TEST_VIN",
|
||||||
vehicle: {
|
vehicle: {
|
||||||
carId: "CARID"
|
carId: "CARID"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vin: "TEST_VIN2",
|
vin: "TEST_VIN2",
|
||||||
vehicle: {
|
vehicle: {
|
||||||
carId: "CARID2"
|
carId: "CARID2"
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
|
||||||
await wrapper.setData({
|
await wrapper.setData({
|
||||||
customerQuestions: {
|
customerQuestions: {
|
||||||
|
|
@ -396,7 +395,6 @@ describe("address-lookup.vue", () => {
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.$router.navigateAfterSave).toHaveBeenCalledWith(navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, undefined, {}, {}, carsFound);
|
expect(wrapper.vm.$router.navigateAfterSave).toHaveBeenCalledWith(navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, undefined, {}, {}, carsFound);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("if the car entered matches one of the vehicles found but the zip is NOT serviceable, do not navigate forward", async () => {
|
test("if the car entered matches one of the vehicles found but the zip is NOT serviceable, do not navigate forward", async () => {
|
||||||
|
|
@ -520,13 +518,74 @@ describe("address-lookup.vue", () => {
|
||||||
await wrapper.vm.navigateForward(carEntered, carsFound);
|
await wrapper.vm.navigateForward(carEntered, carsFound);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.$router.navigateAfterSave).toHaveBeenCalledWith(navigationScenarios.CONTINUING_WITH_DIFFERENT_GLASS, undefined, {}, {"displayVehicleChangeAlert": true}, {});
|
expect(wrapper.vm.$router.navigateAfterSave).toHaveBeenCalledWith(navigationScenarios.CONTINUING_WITH_DIFFERENT_GLASS, undefined, {}, { "displayVehicleChangeAlert": true }, {});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("single car was found and matches entered vehicle => navigateForwardWithSingleCarMatch", async () => {
|
||||||
|
// Arrange
|
||||||
|
const carEntered = {
|
||||||
|
carId: "CARID2"
|
||||||
|
};
|
||||||
|
|
||||||
|
const carsFound = [
|
||||||
|
{
|
||||||
|
vin: "TEST_VIN_2",
|
||||||
|
vehicle: {
|
||||||
|
carId: "CARID2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const { wrapper } = setupMocks({}, {});
|
||||||
|
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
wrapper.vm.navigateForward(carEntered, carsFound);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("multiple cars were found and one matches entered vehicle => navigateForwardWithSingleCarMatch", async () => {
|
||||||
|
// Arrange
|
||||||
|
const carEntered = {
|
||||||
|
carId: "CARID2"
|
||||||
|
};
|
||||||
|
|
||||||
|
const carsFound = [
|
||||||
|
{
|
||||||
|
vin: "TEST_VIN_1",
|
||||||
|
vehicle: {
|
||||||
|
carId: "CARID1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vin: "TEST_VIN_2",
|
||||||
|
vehicle: {
|
||||||
|
carId: "CARID2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vin: "TEST_VIN_3",
|
||||||
|
vehicle: {
|
||||||
|
carId: "CARID3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const { wrapper } = setupMocks({}, {});
|
||||||
|
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
wrapper.vm.navigateForward(carEntered, carsFound);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("reseting dependent state", () => {
|
describe("resetting dependent state", () => {
|
||||||
test("when reseting dependent state, license plate is set to null and parts state and dependencies are reset", async () => {
|
test("when reseting dependent state, license plate is set to null and parts state and dependencies are reset", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const commitSpy = jest.spyOn(store, "commit");
|
const commitSpy = jest.spyOn(store, "commit");
|
||||||
|
|
@ -556,7 +615,7 @@ describe("address-lookup.vue", () => {
|
||||||
zipCode: "43215"
|
zipCode: "43215"
|
||||||
}
|
}
|
||||||
|
|
||||||
const { wrapper } = setupMocks(addressLookup,{
|
const { wrapper } = setupMocks(addressLookup, {
|
||||||
isZipServiceable: true
|
isZipServiceable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -572,7 +631,7 @@ describe("address-lookup.vue", () => {
|
||||||
await wrapper.vm.forwardButtonAction();
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// expect(wrapper.vm.dispatchStoreAction).toHaveBeenCalledWith(storeActions.UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION);
|
expect(wrapper.vm.dispatchStoreAction).toHaveBeenCalledWith(storeActions.UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -619,8 +678,8 @@ describe("address-lookup.vue", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { wrapper } = setupMocks(addressLookup, {
|
const { wrapper } = setupMocks(addressLookup, {
|
||||||
isZipServiceable: false
|
isZipServiceable: false
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(wrapper.vm.showServiceZipField).toBeFalsy();
|
expect(wrapper.vm.showServiceZipField).toBeFalsy();
|
||||||
|
|
@ -651,8 +710,8 @@ describe("address-lookup.vue", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { wrapper } = setupMocks(addressLookup, {
|
const { wrapper } = setupMocks(addressLookup, {
|
||||||
isZipServiceable: false
|
isZipServiceable: false
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
store.commit(storeMutations.UPDATE_CAR_ID, "CARID");
|
store.commit(storeMutations.UPDATE_CAR_ID, "CARID");
|
||||||
|
|
@ -778,6 +837,5 @@ function setupMocks(mountOptions, { isZipServiceable = true, lookupVinbyAddressR
|
||||||
wrapper.vm.$refs.loadingModal.showModal = jest.fn();
|
wrapper.vm.$refs.loadingModal.showModal = jest.fn();
|
||||||
|
|
||||||
return { wrapper };
|
return { wrapper };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,6 @@ export default {
|
||||||
// and one and only of them matches the car id entered
|
// and one and only of them matches the car id entered
|
||||||
const matchingCar = matchingCars[0];
|
const matchingCar = matchingCars[0];
|
||||||
this.updateVehicleInfo(matchingCar.vin, matchingCar.vehicle);
|
this.updateVehicleInfo(matchingCar.vin, matchingCar.vehicle);
|
||||||
|
|
||||||
this.navigateForwardWithSingleCarMatch();
|
this.navigateForwardWithSingleCarMatch();
|
||||||
} else {
|
} else {
|
||||||
// if there are no matches or there are multiple matches, navigate to "address-vehicles" page
|
// if there are no matches or there are multiple matches, navigate to "address-vehicles" page
|
||||||
|
|
@ -361,9 +360,7 @@ export default {
|
||||||
const serviceLocation = store.getters.order.serviceLocation;
|
const serviceLocation = store.getters.order.serviceLocation;
|
||||||
|
|
||||||
if (!serviceLocation.address && serviceLocation.zipCode && serviceLocation.zipCode == store.getters.vehicle.registration.zipCode) {
|
if (!serviceLocation.address && serviceLocation.zipCode && serviceLocation.zipCode == store.getters.vehicle.registration.zipCode) {
|
||||||
baseMixin.methods.dispatchStoreAction(
|
this.dispatchStoreAction(storeActions.UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION);
|
||||||
storeActions.UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -245,9 +245,7 @@ describe("addressVehicles.vue", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function setupMocks({
|
function setupMocks({}) {
|
||||||
cmsQuestionText = "CMS text goes here",
|
|
||||||
}) {
|
|
||||||
//Mock store
|
//Mock store
|
||||||
store.dispatch = jest.fn(() => {});
|
store.dispatch = jest.fn(() => {});
|
||||||
store.getters = {
|
store.getters = {
|
||||||
|
|
@ -296,7 +294,6 @@ function setupMocks({
|
||||||
router: {
|
router: {
|
||||||
navigate: jest.fn(),
|
navigate: jest.fn(),
|
||||||
},
|
},
|
||||||
mixins: [vinPagesMixin]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Mock props
|
//Mock props
|
||||||
|
|
@ -323,10 +320,5 @@ function setupMocks({
|
||||||
|
|
||||||
const wrapper = shallowMount(addressVehicles, mountOptions);
|
const wrapper = shallowMount(addressVehicles, mountOptions);
|
||||||
|
|
||||||
//Mock CMS content
|
|
||||||
const cmsContent = {
|
|
||||||
QuestionText: cmsQuestionText,
|
|
||||||
};
|
|
||||||
|
|
||||||
return { wrapper };
|
return { wrapper };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ describe("license-plate-lookup.vue", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("navigateForward", () => {
|
describe("navigateForward", () => {
|
||||||
test("NavigateAfterSave should be called if isCarIdDifferent is true and isSelectedGlassAvailableForVehicle is false when navigateForward is called", async () => {
|
test("navigateAfterSave should be called if isCarIdDifferent is true and isSelectedGlassAvailableForVehicle is false when navigateForward is called", async () => {
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
|
|
@ -260,6 +260,38 @@ describe("license-plate-lookup.vue", () => {
|
||||||
//Assert
|
//Assert
|
||||||
expect(navigateToHeritage.navigateAfterSaveToHeritageFunnel).toHaveBeenCalled();
|
expect(navigateToHeritage.navigateAfterSaveToHeritageFunnel).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("carId matches returned vehicle => navigateForwardWithSingleCarMatch", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
await wrapper.setData({
|
||||||
|
isCarIdDifferent: false
|
||||||
|
})
|
||||||
|
|
||||||
|
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.navigateForward();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("selected glass is available for returned vehicle => navigateForwardWithSingleCarMatch", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
await wrapper.setData({
|
||||||
|
isSelectedGlassAvailableForVehicle: true
|
||||||
|
})
|
||||||
|
|
||||||
|
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.navigateForward();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,38 @@
|
||||||
import { shallowMount } from "@vue/test-utils";
|
import { shallowMount } from "@vue/test-utils";
|
||||||
import vinLookup from "./vin-lookup.vue";
|
import vinLookup from "./vin-lookup.vue";
|
||||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
|
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios.js";
|
||||||
|
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
|
|
||||||
jest.mock("@/store", () => ({
|
jest.mock("@/store", () => ({
|
||||||
commit: jest.fn(),
|
commit: jest.fn(),
|
||||||
dispatch: jest.fn(),
|
dispatch: jest.fn(),
|
||||||
getters: {
|
getters: {
|
||||||
vehicle: {
|
vehicle: {
|
||||||
year: 2019,
|
year: 2019,
|
||||||
carId: 'initial carId'
|
carId: 'initial carId'
|
||||||
},
|
|
||||||
order: {
|
|
||||||
serviceLocation: {
|
|
||||||
zipCode: "45253"
|
|
||||||
},
|
},
|
||||||
customer: {
|
order: {
|
||||||
emailAddress: "builddigitaltest@safelite.com"
|
serviceLocation: {
|
||||||
|
zipCode: "45253"
|
||||||
|
},
|
||||||
|
customer: {
|
||||||
|
emailAddress: "builddigitaltest@safelite.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
payment: {
|
||||||
|
insuranceCoverage: {
|
||||||
|
isVerified: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
damage: {
|
||||||
|
glassToReplace: "windshield"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
payment: {
|
|
||||||
insuranceCoverage: {
|
|
||||||
isVerified: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
damage: {
|
|
||||||
glassToReplace: "windshield"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { getDamageString, getIsWindshieldOnly,isGlassAvailableForCarId } from "@/helpers/damage-helper";
|
import { getDamageString, getIsWindshieldOnly, isGlassAvailableForCarId } from "@/helpers/damage-helper";
|
||||||
|
|
||||||
jest.mock("@/helpers/damage-helper", () => ({
|
jest.mock("@/helpers/damage-helper", () => ({
|
||||||
isGlassAvailableForCarId: jest.fn(() => {
|
isGlassAvailableForCarId: jest.fn(() => {
|
||||||
|
|
@ -45,9 +46,9 @@ jest.mock("@/helpers/damage-helper", () => ({
|
||||||
describe("vin-lookup.vue", () => {
|
describe("vin-lookup.vue", () => {
|
||||||
it("Should update the funnel-footer forward button when VIN is changed", (done) => {
|
it("Should update the funnel-footer forward button when VIN is changed", (done) => {
|
||||||
//Arrange
|
//Arrange
|
||||||
const { wrapper } = setupMocks({ });
|
const { wrapper } = setupMocks({});
|
||||||
//Act
|
//Act
|
||||||
wrapper.setData({vin: "newValue"});
|
wrapper.setData({ vin: "newValue" });
|
||||||
//Assert
|
//Assert
|
||||||
wrapper.vm.$nextTick(() => {
|
wrapper.vm.$nextTick(() => {
|
||||||
expect(wrapper.vm.$refs.funnelFooter.updateButtonText).toBeCalled();
|
expect(wrapper.vm.$refs.funnelFooter.updateButtonText).toBeCalled();
|
||||||
|
|
@ -58,7 +59,7 @@ describe("vin-lookup.vue", () => {
|
||||||
|
|
||||||
it("Should call navigateForward() if the store carId matches the vin response carId and forward button is clicked", async () => {
|
it("Should call navigateForward() if the store carId matches the vin response carId and forward button is clicked", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({ });
|
const { wrapper } = setupMocks({});
|
||||||
wrapper.vm.navigateForward = jest.fn();
|
wrapper.vm.navigateForward = jest.fn();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -70,12 +71,12 @@ describe("vin-lookup.vue", () => {
|
||||||
|
|
||||||
it("Should not call navigateForward() if the store carId does not match the vin response carId and forward button is clicked", async () => {
|
it("Should not call navigateForward() if the store carId does not match the vin response carId and forward button is clicked", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({ });
|
const { wrapper } = setupMocks({});
|
||||||
const vehicleLookupApiResponse = {
|
const vehicleLookupApiResponse = {
|
||||||
data: {
|
data: {
|
||||||
carId: 'new carId' // does not match the store value
|
carId: 'new carId' // does not match the store value
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
||||||
|
|
||||||
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
||||||
|
|
@ -91,12 +92,12 @@ describe("vin-lookup.vue", () => {
|
||||||
|
|
||||||
it("Should call navigateForward() if the store carId does not match the vin response carId but does match previously enterted carId and forward button is clicked", async () => {
|
it("Should call navigateForward() if the store carId does not match the vin response carId but does match previously enterted carId and forward button is clicked", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({ });
|
const { wrapper } = setupMocks({});
|
||||||
const vehicleLookupApiResponse = {
|
const vehicleLookupApiResponse = {
|
||||||
data: {
|
data: {
|
||||||
carId: 'new carId' // does not match the store value
|
carId: 'new carId' // does not match the store value
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
||||||
|
|
||||||
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
||||||
|
|
@ -113,7 +114,7 @@ describe("vin-lookup.vue", () => {
|
||||||
|
|
||||||
it("Should not call navigateForward() if zip service returns a non-serviceable flag", async () => {
|
it("Should not call navigateForward() if zip service returns a non-serviceable flag", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({ });
|
const { wrapper } = setupMocks({});
|
||||||
const zipValidationApiResponse = {
|
const zipValidationApiResponse = {
|
||||||
data: {
|
data: {
|
||||||
isServiceable: false
|
isServiceable: false
|
||||||
|
|
@ -136,12 +137,12 @@ describe("vin-lookup.vue", () => {
|
||||||
|
|
||||||
it("Should not call navigateForward() when forward button is clicked but lookupVehicle errors out.", async () => {
|
it("Should not call navigateForward() when forward button is clicked but lookupVehicle errors out.", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({ });
|
const { wrapper } = setupMocks({});
|
||||||
const vehicleLookupApiResponse = {
|
const vehicleLookupApiResponse = {
|
||||||
data: {
|
data: {
|
||||||
carId: 'new carId' // does not match the store value
|
carId: 'new carId' // does not match the store value
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const vinPromise = Promise.reject(vehicleLookupApiResponse);
|
const vinPromise = Promise.reject(vehicleLookupApiResponse);
|
||||||
|
|
||||||
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
wrapper.vm.lookupVehicle = jest.fn().mockImplementation(() => vinPromise);
|
||||||
|
|
@ -155,19 +156,75 @@ describe("vin-lookup.vue", () => {
|
||||||
//Assert
|
//Assert
|
||||||
expect(wrapper.vm.navigateForward).not.toHaveBeenCalled();
|
expect(wrapper.vm.navigateForward).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("navigateForward", () => {
|
||||||
|
test("carId is different from returned vehicle and selected glass isn't available => continue with different glass", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({
|
||||||
|
customMountOptions: {
|
||||||
|
router: {
|
||||||
|
navigateAfterSave: jest.fn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||||
|
wrapper.setData({
|
||||||
|
isCarIdDifferent: true,
|
||||||
|
isSelectedGlassAvailableForVehicle: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.navigateForward();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.$router.navigateAfterSave).toBeCalledTimes(1);
|
||||||
|
expect(wrapper.vm.$router.navigateAfterSave).toHaveBeenCalledWith(navigationScenarios.CONTINUING_WITH_DIFFERENT_GLASS, wrapper.vm.$route, expect.anything(), expect.anything(), expect.anything());
|
||||||
|
})
|
||||||
|
|
||||||
|
test("carId matches => navigateForwardWithSingleCarMatch", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||||
|
wrapper.setData({
|
||||||
|
isCarIdDifferent: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.navigateForward();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toBeCalledTimes(1);
|
||||||
|
})
|
||||||
|
|
||||||
|
test("selected glass is available for returned vehicle => navigateForwardWithSingleCarMatch", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
|
||||||
|
wrapper.setData({
|
||||||
|
isSelectedGlassAvailableForVehicle: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.navigateForward();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toBeCalledTimes(1);
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function setupMocks({ customMountOptions }) {
|
function setupMocks({ customMountOptions }) {
|
||||||
const mountOptions = getMountOptions({});
|
const mountOptions = getMountOptions({
|
||||||
|
...customMountOptions
|
||||||
|
});
|
||||||
|
|
||||||
const finalMountOptions = Object.assign(mountOptions, customMountOptions);
|
|
||||||
// Modify/augment default mount options
|
// Modify/augment default mount options
|
||||||
finalMountOptions.global.mocks["$store"] = store;
|
mountOptions.global.mocks["$store"] = store;
|
||||||
finalMountOptions.global.mixins = [mockMixin];
|
mountOptions.global.mixins = [mockMixin];
|
||||||
finalMountOptions['attachTo'] = document.body; // append wrapper to document.body to test DOM methods
|
mountOptions['attachTo'] = document.body; // append wrapper to document.body to test DOM methods
|
||||||
|
|
||||||
const wrapper = shallowMount(vinLookup, finalMountOptions);
|
const wrapper = shallowMount(vinLookup, mountOptions);
|
||||||
mockOutPromises(wrapper);
|
mockOutPromises(wrapper);
|
||||||
mockOutStubFunctions(wrapper);
|
mockOutStubFunctions(wrapper);
|
||||||
return { wrapper };
|
return { wrapper };
|
||||||
|
|
@ -183,7 +240,7 @@ function mockOutPromises(wrapper) {
|
||||||
data: {
|
data: {
|
||||||
carId: 'initial carId'
|
carId: 'initial carId'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const zipPromise = Promise.resolve(zipValidationApiResponse);
|
const zipPromise = Promise.resolve(zipValidationApiResponse);
|
||||||
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
const vinPromise = Promise.resolve(vehicleLookupApiResponse);
|
||||||
|
|
@ -197,8 +254,8 @@ function mockOutStubFunctions(wrapper) {
|
||||||
wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn();
|
wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn();
|
||||||
}
|
}
|
||||||
|
|
||||||
const mockMixin = {
|
const mockMixin = {
|
||||||
methods: {
|
methods: {
|
||||||
getCmsContent: jest.fn(() => "placeholder CMS content"),
|
getCmsContent: jest.fn(() => "placeholder CMS content"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue