1130 lines
No EOL
32 KiB
JavaScript
1130 lines
No EOL
32 KiB
JavaScript
import globalMethods from "@/global-methods";
|
|
import { mutations, state, actions, getters } from "@/store";
|
|
import { storeMutations } from "@/constants/store-mutations";
|
|
import { storeActions } from "@/constants/store-actions";
|
|
// Mock global method
|
|
globalMethods.callHttpClient = jest.fn();
|
|
|
|
|
|
describe("Mutations", () => {
|
|
|
|
it("Updates vehicle year in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateYear(storeState, "2019");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.year).toEqual("2019");
|
|
});
|
|
|
|
it("Updates vehicle make in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateMake(storeState, "Acura");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.make).toEqual("Acura");
|
|
});
|
|
|
|
it("Updates vehicle model in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateModel(storeState, "ILX");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.model).toEqual("ILX");
|
|
});
|
|
|
|
it("Updates vehicle style in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateStyle(storeState, "4 DOOR SEDAN");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.style).toEqual("4 DOOR SEDAN");
|
|
});
|
|
|
|
it("Updates vehicle carId in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateCarId(storeState, "C0000001");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.carId).toEqual("C0000001");
|
|
});
|
|
|
|
it("Updates vehicle vehicle category in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateVehicleCategory(storeState, "CAR");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.category).toEqual("CAR");
|
|
});
|
|
|
|
it("Remove item to eventBus in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const event = { category: "CategoryOne", subCategory: "SubCategoryOne" }
|
|
|
|
// Act / Assert
|
|
mutations.addEventToBus(storeState, event);
|
|
expect(storeState.applicationUser.eventBus).toEqual([event]);
|
|
|
|
// Act / Assert
|
|
mutations.removeEventFromBus(storeState, event);
|
|
expect(storeState.applicationUser.eventBus).toEqual([]);
|
|
|
|
});
|
|
|
|
it("Adds item to eventBus in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.addEventToBus(storeState, { EventOne: "ValueOne" });
|
|
|
|
// Assert
|
|
expect(storeState.applicationUser.eventBus).toEqual([{ EventOne: "ValueOne" }]);
|
|
});
|
|
|
|
it("resetVehicleState, should set fields to null", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
mutations.updateYear(storeState, "2019");
|
|
mutations.updateMake(storeState, "Acura");
|
|
mutations.updateModel(storeState, "ILX");
|
|
mutations.updateStyle(storeState, "4 DOOR SEDAN");
|
|
mutations.updateCarId(storeState, "C0000001");
|
|
mutations.updateVehicleCategory(storeState, "CAR");
|
|
|
|
// Expect
|
|
expect(storeState.order.vehicle.year).toEqual("2019");
|
|
expect(storeState.order.vehicle.make).toEqual("Acura");
|
|
expect(storeState.order.vehicle.model).toEqual("ILX");
|
|
expect(storeState.order.vehicle.style).toEqual("4 DOOR SEDAN");
|
|
expect(storeState.order.vehicle.carId).toEqual("C0000001");
|
|
expect(storeState.order.vehicle.category).toEqual("CAR");
|
|
|
|
// Act
|
|
mutations.resetVehicleState(storeState);
|
|
|
|
// Expect
|
|
expect(storeState.order.vehicle.year).toEqual(null);
|
|
expect(storeState.order.vehicle.make).toEqual(null);
|
|
expect(storeState.order.vehicle.model).toEqual(null);
|
|
expect(storeState.order.vehicle.style).toEqual(null);
|
|
expect(storeState.order.vehicle.carId).toEqual(null);
|
|
expect(storeState.order.vehicle.category).toEqual(null);
|
|
|
|
});
|
|
|
|
it("resetDamageState, should set fields to null", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
storeState.order.damage = {
|
|
isRepair: true,
|
|
numberOfChips: 2,
|
|
glassToReplace: [{ location: 'Rear', name: 'Stationary' }]
|
|
}
|
|
|
|
// Expect
|
|
expect(storeState.order.damage.isRepair).toEqual(true);
|
|
expect(storeState.order.damage.numberOfChips).toEqual(2);
|
|
expect(storeState.order.damage.glassToReplace).toStrictEqual([{ location: 'Rear', name: 'Stationary' }]);
|
|
|
|
// Act
|
|
mutations.resetDamageState(storeState);
|
|
|
|
// Expect
|
|
expect(storeState.order.damage.isRepair).toEqual(null);
|
|
expect(storeState.order.damage.numberOfChips).toEqual(null);
|
|
expect(storeState.order.damage.glassToReplace).toEqual(null);
|
|
});
|
|
|
|
it("Updates number of chips in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateNumberOfChips(storeState, "1");
|
|
|
|
// Assert
|
|
expect(storeState.order.damage.numberOfChips).toEqual("1");
|
|
});
|
|
|
|
it("Updates glass to replace in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateGlassToReplace(storeState, ["Windshield"]);
|
|
|
|
// Assert
|
|
expect(storeState.order.damage.glassToReplace).toEqual(["Windshield"]);
|
|
});
|
|
|
|
it("Updates Parts in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateGlassParts(storeState, { 'Windshield-Single': 'PARTNUM101' });
|
|
|
|
// Assert
|
|
expect(storeState.order.lineItems.glassParts).toEqual({ 'Windshield-Single': 'PARTNUM101' });
|
|
});
|
|
|
|
it("Updates page data in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updatePageData(storeState, { page: 'vehicle-year', data: {} });
|
|
|
|
// Assert
|
|
expect(storeState.applicationUser.pageData['vehicle-year']).toEqual({});
|
|
});
|
|
|
|
it("updateStateWithOrderInformation, should set order information in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateStateWithOrderInformation(storeState, {
|
|
referralNumber: 123,
|
|
referralDate: new Date().toUTCString(),
|
|
referralCorrelationId: "xxx-xxx-xxx",
|
|
vehicle: {
|
|
year: "2019",
|
|
make: "Acura",
|
|
model: "ILX",
|
|
style: "4 DOOR SEDAN",
|
|
carId: "C0000001",
|
|
category: "CAR",
|
|
registration: {}
|
|
},
|
|
damage: {
|
|
glassToReplace: ["Windshield"],
|
|
isRepair: false,
|
|
numberOfChips: 0,
|
|
},
|
|
parts: [],
|
|
accountNumber: "123456789",
|
|
insuranceInfo: {},
|
|
serviceLocation: {},
|
|
customer: {}
|
|
});
|
|
|
|
// Assert
|
|
expect(storeState.order.referralNumber).toEqual(123);
|
|
expect(storeState.order.referralCorrelationId).toEqual("xxx-xxx-xxx");
|
|
expect(storeState.order.vehicle.year).toEqual("2019");
|
|
expect(storeState.order.vehicle.make).toEqual("Acura");
|
|
expect(storeState.order.vehicle.model).toEqual("ILX");
|
|
});
|
|
|
|
it("updateInsuranceVerifiedStatus, should set isVerified flag", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateInsuranceVerifiedStatus(storeState, true);
|
|
|
|
// Assert
|
|
expect(storeState.order.payment.insuranceCoverage.isVerified).toEqual(true);
|
|
});
|
|
|
|
});
|
|
|
|
describe("Actions", () => {
|
|
it("getVehicleYears action, should return years array", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: [2023, 2022, 2021] });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.getVehicleYears(context)
|
|
|
|
expect(response.data).toEqual([2023, 2022, 2021]);
|
|
});
|
|
|
|
it("lookupVehicleByYmms action, should return car data", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { carId: "C00000001" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.lookupVehicleByYmms(context, "2019", "Acura", "ILX", "4 DOOR SEDAN")
|
|
|
|
expect(response.data).toEqual({ carId: "C00000001" });
|
|
});
|
|
|
|
it("lookupVehicleByVin action, should return car data", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { carId: "C00000001" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.lookupVehicleByVin(context, "12345678901234567")
|
|
|
|
expect(response.data).toEqual({ carId: "C00000001" });
|
|
});
|
|
|
|
it("lookupVinByPlate action, should return car data", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { carId: "C00000001" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.lookupVinByPlate(context, "12345678901234567")
|
|
|
|
expect(response.data).toEqual({ carId: "C00000001" });
|
|
});
|
|
|
|
it("getVehicleMakes action, should return makes list", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["Acura", "Honda"] });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.getVehicleMakes(context, "2019")
|
|
|
|
expect(response.data).toEqual(["Acura", "Honda"]);
|
|
});
|
|
|
|
it("getVehicleModels action, should return models list", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["ILX", "RDX"] });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.getVehicleModels(context, "2019", "Acura")
|
|
|
|
expect(response.data).toEqual(["ILX", "RDX"]);
|
|
});
|
|
|
|
it("getVehicleStyles action, should return models list", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { style: "4 DOOR SEDAN" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.getVehicleStyles(context, "2019", "Acura", "ILX")
|
|
|
|
expect(response.data).toEqual({ style: "4 DOOR SEDAN" });
|
|
});
|
|
|
|
it("setVehicle action, should get vehicle data and set carId and vehicle category", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { carId: "C00000000", category: "CAR" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.setVehicle(context, "C00000000")
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_CAR_ID, "C00000000");
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_CATEGORY, "CAR");
|
|
expect(response.data).toEqual({ carId: "C00000000", category: "CAR" });
|
|
});
|
|
|
|
it("getDamageOptions action", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["Windshield", "DriversFrontDoor"] });
|
|
});
|
|
|
|
const response = await actions.getDamageOptions(context, "C00000000")
|
|
|
|
// Assert
|
|
expect(response.data).toEqual(["Windshield", "DriversFrontDoor"]);
|
|
});
|
|
|
|
it("validateZip action", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: "43201" });
|
|
});
|
|
|
|
const response = await actions.validateZip(context, "C00000000")
|
|
|
|
// Assert
|
|
expect(response.data).toEqual("43201");
|
|
});
|
|
|
|
it("resetVehicleAndDependencies action", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
await actions.resetVehicleAndDependencies(context)
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_VEHICLE_STATE);
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_DAMAGE_STATE);
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_REGISTRATION_STATE);
|
|
|
|
});
|
|
|
|
it("resetDamageAndDependencies action", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
await actions.resetDamageAndDependencies(context)
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_DAMAGE_STATE);
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_GLASS_PARTS_STATE);
|
|
|
|
});
|
|
|
|
it("resetRegistrationAndDependencies action", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
await actions.resetRegistrationAndDependencies(context)
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_REGISTRATION_STATE);
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_GLASS_PARTS_STATE);
|
|
|
|
});
|
|
|
|
it("resetPartsAndDependencies action", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
await actions.resetPartsAndDependencies(context)
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_GLASS_PARTS_STATE);
|
|
|
|
});
|
|
|
|
it("resetState action", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
await actions.resetState(context)
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_STATE);
|
|
|
|
});
|
|
|
|
it("getRouteInfo action, returns route info", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { Widget: "Data" } });
|
|
});
|
|
|
|
// Act
|
|
const response = await actions.getRouteInfo(context, "vehicle-year")
|
|
|
|
|
|
expect(response.data).toEqual({ Widget: "Data" });
|
|
|
|
});
|
|
|
|
it("getHomepageName action, returns homepage name", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { Name: "vehicle-year" } });
|
|
});
|
|
|
|
// Act
|
|
const response = await actions.getHomepageName(context)
|
|
|
|
|
|
expect(response.data).toEqual({ Name: "vehicle-year" });
|
|
|
|
});
|
|
|
|
it("getPageData action, returns page data", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { Results: [{ Widget: "Data" }] } });
|
|
});
|
|
|
|
// Act
|
|
const response = await actions.getPageData(context, "vehicle-year")
|
|
|
|
|
|
expect(response.data).toEqual({ Results: [{ Widget: "Data" }] });
|
|
|
|
});
|
|
|
|
it("getEvoxImage action, returns image url", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { imageUrl: "https://test.com" } });
|
|
});
|
|
|
|
// Act
|
|
const response = await actions.getEvoxImage(context, { relativeUrl: "https://relativeurl.com" });
|
|
|
|
|
|
expect(response.data).toEqual({ imageUrl: "https://test.com" });
|
|
});
|
|
|
|
it("saveOrder action, returns order information", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.getters = {
|
|
vehicle: {
|
|
registration: {}
|
|
},
|
|
damage: {},
|
|
};
|
|
context.state = {
|
|
order: {
|
|
serviceLocation: {},
|
|
customer: {}
|
|
}
|
|
};
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { referralNumber: 123 } });
|
|
});
|
|
|
|
// Act
|
|
const response = await actions.saveOrder(context);
|
|
|
|
// Assert
|
|
expect(response.data).toEqual({ referralNumber: 123 });
|
|
});
|
|
|
|
|
|
it("loadOrder action, returns order information, calls mutation", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { referralNumber: 123 } });
|
|
});
|
|
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
const response = await actions.loadOrder(context, { referralNumber: "123", referralDate: new Date().toUTCString(), referralCorrelationId: "xxx-xxx-xxx" });
|
|
|
|
// Assert
|
|
expect(response.data).toEqual({ referralNumber: 123 });
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_STATE_WITH_ORDER_INFORMATION, { "referralNumber": 123 });
|
|
});
|
|
|
|
it("setReferralInformation, should call commit three times", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
actions.setReferralInformation(context, { referralNumber: "123", referralDate: new Date().toUTCString(), referralCorrelationId: "xxx-xxx-xxx" });
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_NUMBER, "123");
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_DATE, new Date().toUTCString());
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, "xxx-xxx-xxx");
|
|
});
|
|
|
|
it("logPageView action, should return nothing", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
var pageEvent = {
|
|
action: "",
|
|
event: "ENTRY",
|
|
}
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({});
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.logPageView(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", pageEvent: pageEvent, shouldUseSessionId: false });
|
|
expect(response).toEqual({});
|
|
});
|
|
|
|
it("logCustomEvent action, should return nothing", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
var customEvent = {
|
|
category: "tstCat",
|
|
action: "click",
|
|
label: "damage",
|
|
value: "psych"
|
|
};
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({});
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.logCustomEvent(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", customEvent: customEvent, shouldUseSessionId: false });
|
|
expect(response).toEqual({});
|
|
});
|
|
|
|
it("initializeSession action, should return nothing", async () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({});
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.initializeSession(context, { userId: "userId", sessionId: "", userAgent: "", referrer: "", shouldUseSessionId: false });
|
|
expect(response).toEqual({});
|
|
});
|
|
|
|
it("saveVin, should call mutation when CarId is different and selectedGlass is not available for vehicle", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
vin: "YYYYY"
|
|
}
|
|
}
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveVin(context, { isCarIdDifferent: true, isSelectedGlassAvailableForVehicle: false, vehicleInfo: { carId: 'C010101', vin: "XXXXX" } });
|
|
|
|
// Assert
|
|
expect(dispatch).toBeCalledWith(storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, { carId: 'C010101', vin: "XXXXX" });
|
|
|
|
});
|
|
|
|
it("saveEmail, should call mutation", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
actions.saveEmail(context, 'test@safelite.com');
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_CUSTOMER_EMAIL_ADDRESS, 'test@safelite.com');
|
|
});
|
|
|
|
it("saveServiceLocation, should call mutation", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
actions.saveServiceLocation(context, { zipCode: "80020" });
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_SERVICE_LOCATION, { zipCode: "80020" });
|
|
});
|
|
|
|
it("saveGlassParts, should call mutation", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
actions.saveGlassParts(context, { glassParts: {} });
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, { glassParts: {} });
|
|
});
|
|
|
|
it("clearVin, should call mutation", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
actions.clearVin(context);
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_VIN, null);
|
|
});
|
|
|
|
it("saveVinLookup, should call mutation if vin is different", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
|
|
// Act
|
|
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(3, storeActions.SAVE_EMAIL, payload.customerEmail);
|
|
expect(dispatch).toHaveBeenNthCalledWith(4, storeActions.SAVE_SERVICE_LOCATION, payload.serviceLocationInfo);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, payload.vehicleInfo);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REGISTRATION, payload.registrationInfo);
|
|
});
|
|
|
|
it("saveRegistrationLicensePlateLookup, should call mutation if LP is different", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
registration: {
|
|
licensePlate: "ABC123"
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
const payload = { isCarIdDifferent: true, isSelectedGlassAvailableForVehicle: false, vehicleInfo: { carId: 'C010101', vin: "XXXXX" }, registrationInfo: { zipCode: "80020", licensePlate: "ALQX35" }, serviceLocationInfo: { state: "CO" }, customerEmail: "test@safelite.com" };
|
|
|
|
actions.saveRegistrationLicensePlateLookup(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(3, storeActions.SAVE_EMAIL, payload.customerEmail);
|
|
expect(dispatch).toHaveBeenNthCalledWith(4, storeActions.SAVE_SERVICE_LOCATION, payload.serviceLocationInfo);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, payload.vehicleInfo);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REGISTRATION, payload.registrationInfo);
|
|
});
|
|
|
|
it("saveRegistrationAddressLookup, should call mutation when address is different", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
registration: {
|
|
address: "123 Main St"
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
const payload = { isCarIdDifferent: true, isSelectedGlassAvailableForVehicle: false, vehicleInfo: { carId: 'C010101', vin: "XXXXX" }, registrationInfo: { zipCode: "80020", address: "123 Marys Ave" }, serviceLocationInfo: { state: "CO" }, customerEmail: "test@safelite.com" };
|
|
|
|
actions.saveRegistrationAddressLookup(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(3, storeActions.SAVE_EMAIL, payload.customerEmail);
|
|
expect(dispatch).toHaveBeenNthCalledWith(4, storeActions.SAVE_SERVICE_LOCATION, payload.serviceLocationInfo);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, payload.vehicleInfo);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REGISTRATION, payload.registrationInfo);
|
|
});
|
|
|
|
it("saveVehicleYear, should wipe out vehicle info if year changes", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
year: "2015"
|
|
}
|
|
}
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveVehicleYear(context, "2016");
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(1, storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES);
|
|
expect(dispatch).toHaveBeenNthCalledWith(2, storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_MAKE, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_MODEL, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_STYLE, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_CAR_ID, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_CATEGORY, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_VIN, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_URL, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_VIF_NUMBER, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_COLOR, null);
|
|
});
|
|
|
|
it("saveVehicleMake, should wipe out vehicle info if make changes", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
make: "Honda"
|
|
}
|
|
}
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveVehicleMake(context, "Toyota");
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(1, storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES);
|
|
expect(dispatch).toHaveBeenNthCalledWith(2, storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_MODEL, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_STYLE, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_CAR_ID, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_CATEGORY, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_VIN, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_URL, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_VIF_NUMBER, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_COLOR, null);
|
|
|
|
});
|
|
|
|
it("saveVehicle model, should wipe out vehicle info if model changes", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
model: "Civic"
|
|
}
|
|
}
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveVehicleModel(context, "Accord");
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(1, storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES);
|
|
expect(dispatch).toHaveBeenNthCalledWith(2, storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_STYLE, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_CAR_ID, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_CATEGORY, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_VIN, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_URL, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_VIF_NUMBER, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_COLOR, null);
|
|
});
|
|
|
|
it("saveVehicleStyle, should wipe out vehicle info if style changes", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
style: "Sedan"
|
|
}
|
|
}
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveVehicleStyle(context, "SUV");
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(1, storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES);
|
|
expect(dispatch).toHaveBeenNthCalledWith(2, storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_CAR_ID, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_CATEGORY, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_VIN, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_URL, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_VIF_NUMBER, null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_IMAGE_COLOR, null);
|
|
});
|
|
|
|
it("saveVehicleDamage, should wipe out damage if different", () => {
|
|
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
damage: {
|
|
glassToReplace: [{glassName: 'Single', glassLocation: 'Windshield'}]
|
|
}
|
|
}
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
const payload = { isWindshieldRepair: false, selectedGlassToReplace: [{glassName: 'Rear', glassLocation: 'quarter'}], selectedWindshieldChipCount: 0};
|
|
actions.saveVehicleDamage(context, payload);
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(1, storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_IS_REPAIR, payload.isWindshieldRepair);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_NUMBER_OF_CHIPS, payload.isWindshieldRepair ? parseInt(payload.selectedWindshieldChipCount) : null);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_GLASS_TO_REPLACE, payload.selectedGlassToReplace);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
describe("Getters", () => {
|
|
it("Vehicle getter, should return vehicle data", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateYear(storeState, "2019");
|
|
mutations.updateMake(storeState, "Acura");
|
|
mutations.updateModel(storeState, "ILX");
|
|
|
|
// Assert
|
|
expect(getters.vehicle(storeState).year).toEqual("2019");
|
|
expect(getters.vehicle(storeState).make).toEqual("Acura");
|
|
expect(getters.vehicle(storeState).model).toEqual("ILX");
|
|
|
|
});
|
|
|
|
it("Get event bus item by event category and eventSubCategory", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const event = { category: "CategoryOne", subCategory: "SubCategoryOne", eventValue: "EventValueOne" };
|
|
|
|
// Act
|
|
mutations.addEventToBus(storeState, event);
|
|
|
|
// Assert
|
|
//expect(storeState.applicationUser.eventBus).toEqual([event]);
|
|
expect(getters.eventBusItem(storeState)(event.category, event.subCategory)).toEqual(event.eventValue);
|
|
|
|
});
|
|
|
|
it("Get event bus", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
storeState.applicationUser.eventBus = [];
|
|
|
|
const event = { category: "CategoryOne", subCategory: "SubCategoryOne", eventValue: "EventValueOne" };
|
|
|
|
// Act
|
|
mutations.addEventToBus(storeState, event);
|
|
|
|
// Assert
|
|
expect(getters.eventBus(storeState)).toEqual([event]);
|
|
|
|
});
|
|
|
|
it("Damage getter, should return damage data", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateGlassToReplace(storeState, ["Rear"]);
|
|
|
|
// Assert
|
|
expect(getters.damage(storeState).glassToReplace).toEqual(["Rear"]);
|
|
|
|
});
|
|
|
|
it("lineItems getter, should return lineItem data", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateGlassParts(storeState, { "Rear-Stationary": 'PART101' });
|
|
|
|
// Assert
|
|
expect(getters.lineItems(storeState).glassParts).toEqual({ "Rear-Stationary": 'PART101' });
|
|
|
|
});
|
|
|
|
|
|
it("PageData getter, should return page data for specific page", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updatePageData(storeState, { page: 'vehicle-year', data: {} });
|
|
|
|
// Assert
|
|
expect(getters.pageData(storeState)('vehicle-year')).toEqual({});
|
|
|
|
});
|
|
|
|
it("Payment getter, should return payment data", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
//Act
|
|
mutations.updateInsuranceVerifiedStatus(storeState, true);
|
|
|
|
//Assert
|
|
expect(getters.payment(storeState).insuranceCoverage.isVerified).toEqual(true);
|
|
});
|
|
|
|
}); |