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()) {
|
else if (partQuestionsComponent.methods.arePagePrerequisitesValid()) {
|
||||||
return fmgPageValues.PART_QUESTIONS;
|
return fmgPageValues.PART_QUESTIONS;
|
||||||
}
|
}
|
||||||
else if (store.getters.vehicle.vin) {
|
else if (vinLookupComponent.methods.arePagePrerequisitesValid()) {
|
||||||
return fmgPageValues.VIN_LOOKUP;
|
return fmgPageValues.VIN_LOOKUP;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,11 @@ import { storeActions } from "@/constants/store-actions";
|
||||||
import { setupMocksForJsFiles, getMockOrderInfo } from "@/helpers/unit-test-helper.js";
|
import { setupMocksForJsFiles, getMockOrderInfo } from "@/helpers/unit-test-helper.js";
|
||||||
import { externalUrls } from "@/router/router-constants/externalUrl-values";
|
import { externalUrls } from "@/router/router-constants/externalUrl-values";
|
||||||
import { queryStrings } from "@/constants/query-strings";
|
import { queryStrings } from "@/constants/query-strings";
|
||||||
|
import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
|
||||||
|
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
|
import { lazy } from "yup";
|
||||||
|
|
||||||
// Mock Lazy Load
|
// Mock Lazy Load
|
||||||
jest.mock("@/router/dynamic-routing/component-loader.js", () => ({
|
jest.mock("@/router/dynamic-routing/component-loader.js", () => ({
|
||||||
|
|
@ -23,43 +25,9 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock out the lazy load calls for all components.
|
// Mock out the lazy load calls for all components.
|
||||||
lazyLoadComponent
|
mockLazyLoadComponentReturnValues({
|
||||||
.mockReturnValueOnce(() => {
|
[fmgPageValues.VEHICLE_MAKE]: false
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||||
|
|
@ -75,43 +43,11 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock out the lazy load calls for all components.
|
// Mock out the lazy load calls for all components.
|
||||||
lazyLoadComponent
|
mockLazyLoadComponentReturnValues({
|
||||||
.mockReturnValueOnce(() => {
|
[fmgPageValues.VEHICLE_MAKE]: true,
|
||||||
return {
|
[fmgPageValues.VEHICLE_MODEL]: true,
|
||||||
default: {
|
[fmgPageValues.VEHICLE_STYLE]: false,
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||||
|
|
@ -127,46 +63,13 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock out the lazy load calls for all components.
|
// Mock out the lazy load calls for all components.
|
||||||
lazyLoadComponent
|
mockLazyLoadComponentReturnValues({
|
||||||
.mockReturnValueOnce(() => {
|
[fmgPageValues.VEHICLE_MAKE]: true,
|
||||||
return {
|
[fmgPageValues.VEHICLE_MODEL]: true,
|
||||||
default: {
|
[fmgPageValues.VEHICLE_STYLE]: true,
|
||||||
methods: {
|
[fmgPageValues.VEHICLE_DAMAGE]: true,
|
||||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
[fmgPageValues.ESTIMATE]: false
|
||||||
}
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.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';
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||||
|
|
@ -175,54 +78,25 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
expect(result).toBe('vehicle-damage');
|
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
|
// Arrange
|
||||||
const toRoute = {
|
const toRoute = {
|
||||||
query: {}
|
query: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock out the lazy load calls for all components.
|
// Mock out the lazy load calls for all components.
|
||||||
lazyLoadComponent
|
mockLazyLoadComponentReturnValues({
|
||||||
.mockReturnValueOnce(() => {
|
[fmgPageValues.VEHICLE_MAKE]: true,
|
||||||
return {
|
[fmgPageValues.VEHICLE_MODEL]: true,
|
||||||
default: {
|
[fmgPageValues.VEHICLE_STYLE]: true,
|
||||||
methods: {
|
[fmgPageValues.VEHICLE_DAMAGE]: true,
|
||||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
[fmgPageValues.ESTIMATE]: true,
|
||||||
}
|
[fmgPageValues.CAPABILITY_QUESTIONS]: false,
|
||||||
}
|
[fmgPageValues.MOLDING_QUESTIONS]: false,
|
||||||
}
|
[fmgPageValues.VEHICLE_PARTS]: false,
|
||||||
})
|
[fmgPageValues.PART_QUESTIONS]: false,
|
||||||
.mockReturnValueOnce(() => {
|
[fmgPageValues.VIN_LOOKUP]: true,
|
||||||
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"
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||||
|
|
@ -231,54 +105,26 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
expect(result).toBe('vin-lookup');
|
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
|
// Arrange
|
||||||
const toRoute = {
|
const toRoute = {
|
||||||
query: {}
|
query: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock out the lazy load calls for all components.
|
// Mock out the lazy load calls for all components.
|
||||||
lazyLoadComponent
|
mockLazyLoadComponentReturnValues({
|
||||||
.mockReturnValueOnce(() => {
|
[fmgPageValues.VEHICLE_MAKE]: true,
|
||||||
return {
|
[fmgPageValues.VEHICLE_MODEL]: true,
|
||||||
default: {
|
[fmgPageValues.VEHICLE_STYLE]: true,
|
||||||
methods: {
|
[fmgPageValues.VEHICLE_DAMAGE]: true,
|
||||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
[fmgPageValues.ESTIMATE]: true,
|
||||||
}
|
[fmgPageValues.CAPABILITY_QUESTIONS]: false,
|
||||||
}
|
[fmgPageValues.MOLDING_QUESTIONS]: false,
|
||||||
}
|
[fmgPageValues.VEHICLE_PARTS]: false,
|
||||||
})
|
[fmgPageValues.PART_QUESTIONS]: false,
|
||||||
.mockReturnValueOnce(() => {
|
[fmgPageValues.VIN_LOOKUP]: false,
|
||||||
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 = null;
|
|
||||||
// Act
|
// Act
|
||||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||||
|
|
||||||
|
|
@ -401,4 +247,22 @@ describe("navigateToHeritageFunnel", () => {
|
||||||
expect(router.navigateToExternalUrl).toHaveBeenCalled();
|
expect(router.navigateToExternalUrl).toHaveBeenCalled();
|
||||||
saveOrderFunction.mockRestore();
|
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",
|
lastPageVisited: "test-page",
|
||||||
crmCustomerId: "xxx-xxx-xxx",
|
crmCustomerId: "xxx-xxx-xxx",
|
||||||
savedSessionId: "xxx-xxx-xxx"
|
savedSessionId: "xxx-xxx-xxx"
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
context.state = {
|
context.state = {
|
||||||
order: {
|
order: {
|
||||||
serviceLocation: {},
|
serviceLocation: {},
|
||||||
customer: {}
|
customer: {},
|
||||||
|
lineItems: {}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -793,13 +794,27 @@ describe("Actions", () => {
|
||||||
|
|
||||||
|
|
||||||
// Act
|
// 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);
|
actions.saveVinLookup(context, payload);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(1, storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES);
|
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_VEHICLE, payload.vehicleInfo);
|
||||||
expect(commit).toBeCalledWith(storeMutations.UPDATE_REGISTRATION, payload.registrationInfo);
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REGISTRATION, payload.registrationInfo);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue