554 lines
No EOL
14 KiB
JavaScript
554 lines
No EOL
14 KiB
JavaScript
import globalMethods from "@/global-methods";
|
|
import { mutations, state, actions, getters } from "@/store";
|
|
import { storeMutations } from "@/constants/store-mutations";
|
|
|
|
// 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.updateParts(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({});
|
|
});
|
|
|
|
});
|
|
|
|
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("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("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_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_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_PARTS_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" });
|
|
});
|
|
|
|
});
|
|
|
|
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.updateParts(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({});
|
|
|
|
});
|
|
|
|
}); |