CSR-690 Fix tests
This commit is contained in:
parent
4980a7bc91
commit
11016372a3
3 changed files with 82 additions and 203 deletions
|
|
@ -95,7 +95,7 @@ async function getLatestPageForRedirection() {
|
|||
else if (partQuestionsComponent.methods.arePagePrerequisitesValid()) {
|
||||
return fmgPageValues.PART_QUESTIONS;
|
||||
}
|
||||
else if (store.getters.vehicle.vin) {
|
||||
else if (vinLookupComponent.methods.arePagePrerequisitesValid()) {
|
||||
return fmgPageValues.VIN_LOOKUP;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ import { storeActions } from "@/constants/store-actions";
|
|||
import { setupMocksForJsFiles, getMockOrderInfo } from "@/helpers/unit-test-helper.js";
|
||||
import { externalUrls } from "@/router/router-constants/externalUrl-values";
|
||||
import { queryStrings } from "@/constants/query-strings";
|
||||
import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
|
||||
|
||||
import store from "@/store";
|
||||
import router from "@/router";
|
||||
import { lazy } from "yup";
|
||||
|
||||
// Mock Lazy Load
|
||||
jest.mock("@/router/dynamic-routing/component-loader.js", () => ({
|
||||
|
|
@ -23,43 +25,9 @@ describe("getPageToRouteExistingOrderTo", () => {
|
|||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
lazyLoadComponent
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[fmgPageValues.VEHICLE_MAKE]: false
|
||||
})
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
|
@ -75,43 +43,11 @@ describe("getPageToRouteExistingOrderTo", () => {
|
|||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
lazyLoadComponent
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[fmgPageValues.VEHICLE_MAKE]: true,
|
||||
[fmgPageValues.VEHICLE_MODEL]: true,
|
||||
[fmgPageValues.VEHICLE_STYLE]: false,
|
||||
})
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
|
@ -127,46 +63,13 @@ describe("getPageToRouteExistingOrderTo", () => {
|
|||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
lazyLoadComponent
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
store.getters.damage.isRepair = undefined;
|
||||
store.getters.vehicle.carId = 'C00000';
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[fmgPageValues.VEHICLE_MAKE]: true,
|
||||
[fmgPageValues.VEHICLE_MODEL]: true,
|
||||
[fmgPageValues.VEHICLE_STYLE]: true,
|
||||
[fmgPageValues.VEHICLE_DAMAGE]: true,
|
||||
[fmgPageValues.ESTIMATE]: false
|
||||
})
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
|
@ -175,54 +78,25 @@ describe("getPageToRouteExistingOrderTo", () => {
|
|||
expect(result).toBe('vehicle-damage');
|
||||
});
|
||||
|
||||
test("getPageToRouteExistingOrderTo, should return vin-lookup", async () => {
|
||||
test("getPageToRouteExistingOrderTo, user has YMMS and no vehicle questions should return vin-lookup", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {}
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
lazyLoadComponent
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
store.getters.damage.isRepair = true;
|
||||
store.getters.vehicle.carId = 'C00000';
|
||||
store.getters.vehicle.vin = "1FADP3F26DL212886"
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[fmgPageValues.VEHICLE_MAKE]: true,
|
||||
[fmgPageValues.VEHICLE_MODEL]: true,
|
||||
[fmgPageValues.VEHICLE_STYLE]: true,
|
||||
[fmgPageValues.VEHICLE_DAMAGE]: true,
|
||||
[fmgPageValues.ESTIMATE]: true,
|
||||
[fmgPageValues.CAPABILITY_QUESTIONS]: false,
|
||||
[fmgPageValues.MOLDING_QUESTIONS]: false,
|
||||
[fmgPageValues.VEHICLE_PARTS]: false,
|
||||
[fmgPageValues.PART_QUESTIONS]: false,
|
||||
[fmgPageValues.VIN_LOOKUP]: true,
|
||||
})
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
|
@ -231,54 +105,26 @@ describe("getPageToRouteExistingOrderTo", () => {
|
|||
expect(result).toBe('vin-lookup');
|
||||
});
|
||||
|
||||
test("getPageToRouteExistingOrderTo, should return estimate", async () => {
|
||||
test("getPageToRouteExistingOrderTo, user has YMMS but no questions or carId should return estimate", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {}
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
lazyLoadComponent
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[fmgPageValues.VEHICLE_MAKE]: true,
|
||||
[fmgPageValues.VEHICLE_MODEL]: true,
|
||||
[fmgPageValues.VEHICLE_STYLE]: true,
|
||||
[fmgPageValues.VEHICLE_DAMAGE]: true,
|
||||
[fmgPageValues.ESTIMATE]: true,
|
||||
[fmgPageValues.CAPABILITY_QUESTIONS]: false,
|
||||
[fmgPageValues.MOLDING_QUESTIONS]: false,
|
||||
[fmgPageValues.VEHICLE_PARTS]: false,
|
||||
[fmgPageValues.PART_QUESTIONS]: false,
|
||||
[fmgPageValues.VIN_LOOKUP]: false,
|
||||
})
|
||||
|
||||
store.getters.damage.isRepair = true;
|
||||
store.getters.vehicle.carId = 'C00000';
|
||||
store.getters.vehicle.vin = null;
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
|
|
@ -401,4 +247,22 @@ describe("navigateToHeritageFunnel", () => {
|
|||
expect(router.navigateToExternalUrl).toHaveBeenCalled();
|
||||
saveOrderFunction.mockRestore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* `arePagePrerequisitesValidObject` is an object where the keys are fmgPageValue names and the values are booleans that indicate
|
||||
* whether arePagePrerequisitesValid is true or false
|
||||
*/
|
||||
function mockLazyLoadComponentReturnValues(arePagePrerequisitesValidObject = {}) {
|
||||
lazyLoadComponent.mockImplementation((pageName) => {
|
||||
return async () => {
|
||||
return Promise.resolve({
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(arePagePrerequisitesValidObject[pageName])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -575,12 +575,13 @@ describe("Actions", () => {
|
|||
lastPageVisited: "test-page",
|
||||
crmCustomerId: "xxx-xxx-xxx",
|
||||
savedSessionId: "xxx-xxx-xxx"
|
||||
}
|
||||
},
|
||||
};
|
||||
context.state = {
|
||||
order: {
|
||||
serviceLocation: {},
|
||||
customer: {}
|
||||
customer: {},
|
||||
lineItems: {}
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -793,13 +794,27 @@ describe("Actions", () => {
|
|||
|
||||
|
||||
// Act
|
||||
const payload = { isCarIdDifferent: true, isSelectedGlassAvailableForVehicle: false, vehicleInfo: { carId: 'C010101', vin: "XXXXX" }, registrationInfo: { zipCode: "80020" }, serviceLocationInfo: { state: "CO" }, customerEmail: "test@safleite.com" };
|
||||
const payload = {
|
||||
isCarIdDifferent: true,
|
||||
isSelectedGlassAvailableForVehicle: false,
|
||||
vehicleInfo: {
|
||||
carId: 'C010101', vin: "XXXXX"
|
||||
},
|
||||
registrationInfo: {
|
||||
zipCode: "80020"
|
||||
},
|
||||
serviceLocationInfo: {
|
||||
state: "CO"
|
||||
},
|
||||
customerEmail: "test@safleite.com"
|
||||
};
|
||||
|
||||
actions.saveVinLookup(context, payload);
|
||||
|
||||
// Assert
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(2, storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(2, storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(3, storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES);
|
||||
|
||||
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, payload.vehicleInfo);
|
||||
expect(commit).toBeCalledWith(storeMutations.UPDATE_REGISTRATION, payload.registrationInfo);
|
||||
|
|
|
|||
Loading…
Reference in a new issue