328 lines
7.8 KiB
JavaScript
328 lines
7.8 KiB
JavaScript
import store from "./index";
|
|
import globalMethods from "@/global-methods";
|
|
|
|
describe("Actions", () => {
|
|
it("Should return list of years retrieved", async () => {
|
|
// Arrange
|
|
let years = [];
|
|
|
|
// Act
|
|
globalMethods.callHttpClient = jest.fn();
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: [2023, 2022, 2021] });
|
|
});
|
|
await store.dispatch("getVehicleYears").then((response) => {
|
|
years = response.data;
|
|
});
|
|
|
|
// Assert
|
|
expect(years[0]).toBe(2023);
|
|
});
|
|
|
|
it("Should return list of makes retrieved", async () => {
|
|
// Arrange
|
|
let makes = [];
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["Baic", "Honda", "Ford"] });
|
|
});
|
|
await store.dispatch("getVehicleMakes", { year: 2023 }).then((response) => {
|
|
makes = response.data;
|
|
});
|
|
|
|
// Assert
|
|
expect(makes[0]).toBe("Baic");
|
|
});
|
|
|
|
it("Should return list of models retrieved", async () => {
|
|
// Arrange
|
|
let models = [];
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["BJ40 (MEX)", "Civic", "Accord"] });
|
|
});
|
|
await store
|
|
.dispatch("getVehicleModels", { year: 2023, make: "Baic" })
|
|
.then((response) => {
|
|
models = response.data;
|
|
});
|
|
|
|
// Assert
|
|
expect(models[0]).toBe("BJ40 (MEX)");
|
|
});
|
|
|
|
it("Should return list of styles retrieved", async () => {
|
|
// Arrange
|
|
let styles = [];
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["4 DOOR UTILITY", "2 DOOR"] });
|
|
});
|
|
await store
|
|
.dispatch("getVehicleStyles", {
|
|
year: 2023,
|
|
make: "Baic",
|
|
model: "BJ40 (MEX)",
|
|
})
|
|
.then((response) => {
|
|
styles = response.data;
|
|
});
|
|
|
|
// Assert
|
|
expect(styles[0]).toBe("4 DOOR UTILITY");
|
|
});
|
|
|
|
it("Should return list of damage options retrieved", async () => {
|
|
// Arrange
|
|
let damageOptions = [];
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["Front Window", "Rear Window"] });
|
|
});
|
|
await store
|
|
.dispatch("getDamageOptions", {
|
|
carId: "CR00070154",
|
|
})
|
|
.then((response) => {
|
|
damageOptions = response.data;
|
|
});
|
|
|
|
// Assert
|
|
expect(damageOptions[0]).toBe("Front Window");
|
|
});
|
|
|
|
it("Should return data from url retrieved", async () => {
|
|
// Arrange
|
|
let routeInfo = [];
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({
|
|
data: {
|
|
Result: "Route Info Data",
|
|
},
|
|
});
|
|
});
|
|
await store
|
|
.dispatch("getRouteInfo", { pageName: "vehicle-year" })
|
|
.then((response) => {
|
|
routeInfo = response.data.Result;
|
|
});
|
|
|
|
// Assert
|
|
expect(routeInfo).toBe("Route Info Data");
|
|
});
|
|
|
|
it("Should return page data from url retrieved", async () => {
|
|
// Arrange
|
|
let pageData = [];
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({
|
|
data: {
|
|
Result: "Page Info Data",
|
|
},
|
|
});
|
|
});
|
|
await store
|
|
.dispatch("getPageData", { pageName: "vehicle-year" })
|
|
.then((response) => {
|
|
pageData = response.data.Result;
|
|
});
|
|
|
|
// Assert
|
|
expect(pageData).toBe("Page Info Data");
|
|
});
|
|
|
|
it("Should return data from url retrieved", async () => {
|
|
// Arrange
|
|
let returnData = [];
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({
|
|
data: {
|
|
Result: "2018 Honda Civic",
|
|
},
|
|
});
|
|
});
|
|
await store
|
|
.dispatch("lookupVehicleByYmms", {
|
|
year: "2018",
|
|
make: "Honda",
|
|
model: "Civic",
|
|
style: "2 Door",
|
|
})
|
|
.then((response) => {
|
|
returnData = response.data.Result;
|
|
});
|
|
|
|
// Assert
|
|
expect(returnData).toBe("2018 Honda Civic");
|
|
});
|
|
|
|
it("Should return vehicle data from url retrieved", async () => {
|
|
// Arrange
|
|
let returnData = [];
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({
|
|
data: {
|
|
Result: "2021 Honda Civic",
|
|
},
|
|
});
|
|
});
|
|
await store
|
|
.dispatch("lookupVehicleByVin", { vin: "12345678" })
|
|
.then((response) => {
|
|
returnData = response.data.Result;
|
|
});
|
|
|
|
// Assert
|
|
expect(returnData).toBe("2021 Honda Civic");
|
|
});
|
|
|
|
it("Should return vehicle image data from url retrieved", async () => {
|
|
// Arrange
|
|
let returnData = [];
|
|
|
|
// Act
|
|
globalMethods.callMockHttpClient = jest.fn();
|
|
globalMethods.callMockHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({
|
|
data: {
|
|
Result: "2008_honda_civic.jpg",
|
|
},
|
|
});
|
|
});
|
|
await store
|
|
.dispatch("getEvoxImage", { relativeUrl: "evox_image.com" })
|
|
.then((response) => {
|
|
returnData = response.data.Result;
|
|
});
|
|
|
|
// Assert
|
|
expect(returnData).toBe("2008_honda_civic.jpg");
|
|
});
|
|
});
|
|
|
|
describe("Mutations", () => {
|
|
it("Should update the year property in the store", () => {
|
|
// Act
|
|
store.commit("updateYear", 2020);
|
|
|
|
// Assert
|
|
expect(store.state.order.vehicle.year).toBe(2020);
|
|
});
|
|
|
|
it("Should update the make property in the store", () => {
|
|
// Act
|
|
store.commit("updateMake", "Honda");
|
|
|
|
// Assert
|
|
expect(store.state.order.vehicle.make).toBe("Honda");
|
|
});
|
|
|
|
it("Should update the model property in the store", () => {
|
|
// Act
|
|
store.commit("updateModel", "Civic");
|
|
|
|
// Assert
|
|
expect(store.state.order.vehicle.model).toBe("Civic");
|
|
});
|
|
|
|
it("Should update the style property in the store", () => {
|
|
// Act
|
|
store.commit("updateStyle", "2 Door");
|
|
|
|
// Assert
|
|
expect(store.state.order.vehicle.style).toBe("2 Door");
|
|
});
|
|
|
|
it("Should update the carID and category propertys in the store", () => {
|
|
// Arrange
|
|
const carData = {
|
|
carId: "123abc",
|
|
category: "car",
|
|
};
|
|
// Act
|
|
store.commit("updateVehicle", carData);
|
|
|
|
// Assert
|
|
expect(store.state.order.vehicle.carId).toBe("123abc");
|
|
expect(store.state.order.vehicle.category).toBe("car");
|
|
});
|
|
|
|
it("Should add event onto bus and update state", () => {
|
|
// Arrange
|
|
const event = {
|
|
category: "TestCategoryOne",
|
|
subCategory: "TestSubCategoryOne",
|
|
eventValue: "TestEventValueOne",
|
|
};
|
|
|
|
// Act
|
|
store.commit("addEventToBus", event);
|
|
|
|
//Assert
|
|
expect(store.state.applicationUser.eventBus[0].category).toBe(
|
|
"TestCategoryOne"
|
|
);
|
|
expect(store.state.applicationUser.eventBus[0].subCategory).toBe(
|
|
"TestSubCategoryOne"
|
|
);
|
|
expect(store.state.applicationUser.eventBus[0].eventValue).toBe(
|
|
"TestEventValueOne"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("Getters", () => {
|
|
it("Should validate vehicle getter", () => {
|
|
// Arrange
|
|
const vehicle = store.getters.vehicle;
|
|
|
|
// Assert
|
|
expect(typeof vehicle).toBe("object");
|
|
});
|
|
|
|
it("Should get item from bus via getter", () => {
|
|
// Arrange
|
|
const event = {
|
|
category: "TestCategoryOne",
|
|
subCategory: "TestSubCategoryOne",
|
|
eventValue: "TestEventValueOne",
|
|
};
|
|
|
|
// Act
|
|
store.commit("addEventToBus", event);
|
|
|
|
// Assert
|
|
const returnedEventValue = store.getters.eventBusItem(
|
|
event.category,
|
|
event.subCategory
|
|
);
|
|
expect(returnedEventValue).toBe("TestEventValueOne");
|
|
});
|
|
|
|
it("Should get eventbus from getter, should have length > 0", () => {
|
|
// Arrange
|
|
const event = {
|
|
category: "TestCategoryOne",
|
|
subCategory: "TestSubCategoryOne",
|
|
eventValue: "TestEventValueOne",
|
|
};
|
|
|
|
// Act
|
|
store.commit("addEventToBus", event);
|
|
|
|
//Assert
|
|
expect(store.getters.eventBus.length).toBeGreaterThan(0);
|
|
});
|
|
});
|