Unit test coverage to 89%, redid store / store tests
This commit is contained in:
parent
5d9bfe0d0b
commit
66aa4190fb
4 changed files with 559 additions and 670 deletions
|
|
@ -18,7 +18,7 @@ module.exports = {
|
|||
testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
statements: 87,
|
||||
statements: 89,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ const storeMutations = {
|
|||
UPDATE_STYLE: "updateStyle",
|
||||
UPDATE_CAR_ID: "updateCarId",
|
||||
UPDATE_VEHICLE_CATEGORY: "updateVehicleCategory",
|
||||
UPDATE_VEHICLE: "updateVehicle",
|
||||
|
||||
// EVENT BUS MUTATIONS
|
||||
ADD_EVENT_TO_BUS: "addEventToBus",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,227 @@ import createPersistedState from "vuex-persistedstate";
|
|||
import globalMethods from "@/global-methods";
|
||||
|
||||
|
||||
|
||||
// Export State
|
||||
export const state = {
|
||||
order: {
|
||||
vehicle: {
|
||||
year: null,
|
||||
make: null,
|
||||
model: null,
|
||||
style: null,
|
||||
carId: null,
|
||||
category: null,
|
||||
damage: {
|
||||
isRepair: null,
|
||||
numberOfChips: null,
|
||||
glassToReplace: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
applicationUser: {
|
||||
eventBus: [],
|
||||
},
|
||||
}
|
||||
|
||||
// Export Mutations
|
||||
export const mutations = {
|
||||
// VEHICLE MUTATIONS
|
||||
updateYear(state, year) {
|
||||
state.order.vehicle.year = year;
|
||||
},
|
||||
updateMake(state, make) {
|
||||
state.order.vehicle.make = make;
|
||||
},
|
||||
updateModel(state, model) {
|
||||
state.order.vehicle.model = model;
|
||||
},
|
||||
updateStyle(state, style) {
|
||||
state.order.vehicle.style = style;
|
||||
},
|
||||
updateCarId(state, carId) {
|
||||
state.order.vehicle.carId = carId;
|
||||
},
|
||||
updateVehicleCategory(state, category) {
|
||||
state.order.vehicle.category = category;
|
||||
},
|
||||
|
||||
// EVENT BUS MUTATIONS
|
||||
addEventToBus(state, event) {
|
||||
state.applicationUser.eventBus.push(event);
|
||||
},
|
||||
removeEventFromBus(state, eventData) {
|
||||
const matchedEvent = state.applicationUser.eventBus.find(
|
||||
({ category, subCategory }) =>
|
||||
category === eventData.category &&
|
||||
subCategory === eventData.subCategory
|
||||
);
|
||||
const itemIndex = state.applicationUser.eventBus.indexOf(matchedEvent);
|
||||
|
||||
// If the item exists, remove it.
|
||||
if (itemIndex > -1) {
|
||||
state.applicationUser.eventBus.splice(itemIndex, 1);
|
||||
}
|
||||
},
|
||||
|
||||
// DEPENDENCY MUTATIONS
|
||||
resetVehicleAndDependencies(state) {
|
||||
state.order.vehicle.year = null;
|
||||
state.order.vehicle.make = null;
|
||||
state.order.vehicle.model = null;
|
||||
state.order.vehicle.style = null;
|
||||
state.order.vehicle.carId = null;
|
||||
state.order.vehicle.category = null;
|
||||
},
|
||||
resetDamageAndDependencies(state) {
|
||||
state.order.vehicle.damage.isRepair = null;
|
||||
state.order.vehicle.damage.numberOfChips = null;
|
||||
state.order.vehicle.damage.windshieldGlassToReplace = null;
|
||||
state.order.vehicle.damage.driverSideGlassToReplace = null;
|
||||
state.order.vehicle.damage.passengerSideGlassToReplace = null;
|
||||
state.order.vehicle.damage.rearGlassToReplace = null;
|
||||
|
||||
},
|
||||
resetRegistrationAndDependencies(state) {
|
||||
|
||||
},
|
||||
resetPartsAndDependencies(state) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Export Getters
|
||||
export const getters = {
|
||||
vehicle: (state) => state.order.vehicle,
|
||||
eventBusItem: (state) => (eventCategory, eventSubCategory) => {
|
||||
const matchedEvent = state.applicationUser.eventBus.find(
|
||||
({ category, subCategory }) =>
|
||||
category === eventCategory && subCategory === eventSubCategory
|
||||
);
|
||||
|
||||
return matchedEvent !== undefined ? matchedEvent.eventValue : undefined;
|
||||
},
|
||||
eventBus: (state) => state.applicationUser.eventBus,
|
||||
}
|
||||
|
||||
// Export Actions
|
||||
export const actions = {
|
||||
// Vehicle API Actions
|
||||
getVehicleYears(context) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleYears.method,
|
||||
endpoint: endpoints.GetVehicleYears.url,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
lookupVehicleByYmms(context, { year, make, model, style }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LookupVehicleByYmms.method,
|
||||
endpoint: `${endpoints.LookupVehicleByYmms.url}/${year}/${make}/${model}/${style}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
lookupVehicleByVin(context, { vin }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LookupVehicleByVin.method,
|
||||
endpoint: endpoints.LookupVehicleByVin.url,
|
||||
payload: {
|
||||
vin: vin, // EX "1J4GW58S4XC541166"
|
||||
},
|
||||
});
|
||||
},
|
||||
getVehicleMakes(context, { year }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleMakes.method,
|
||||
endpoint: `${endpoints.GetVehicleMakes.url}/${year}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
getVehicleModels(context, { year, make }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleModels.method,
|
||||
endpoint: `${endpoints.GetVehicleModels.url}/${year}/${make}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
getVehicleStyles(context, { year, make, model }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleStyles.method,
|
||||
endpoint: `${endpoints.GetVehicleStyles.url}/${year}/${make}/${model}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
setVehicle(context, { year, make, model, style }) {
|
||||
return globalMethods
|
||||
.callHttpClient({
|
||||
methods: endpoints.GetVehicle.method,
|
||||
endpoint: `${endpoints.GetVehicle.url}/${year}/${make}/${model}/${style}`,
|
||||
payload: {},
|
||||
})
|
||||
.then((response) => {
|
||||
context.commit(storeMutations.UPDATE_CAR_ID, response.data.carId);
|
||||
context.commit(storeMutations.UPDATE_VEHICLE_CATEGORY, response.data.category);
|
||||
return response;
|
||||
});
|
||||
},
|
||||
getDamageOptions(context, { carId }) {
|
||||
return globalMethods.callHttpClient({
|
||||
methods: endpoints.GetDamageOptions.method,
|
||||
endpoint: `${endpoints.GetDamageOptions.url}/${carId}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
|
||||
// DEPENDENCY ACTIONS
|
||||
resetVehicleAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_VEHICLE_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_DAMAGE_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_REGISTRATION_AND_DEPS);
|
||||
},
|
||||
resetDamageAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_DAMAGE_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_PARTS_AND_DEPS);
|
||||
},
|
||||
resetRegistrationAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_REGISTRATION_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_PARTS_AND_DEPS)
|
||||
},
|
||||
resetPartsAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_PARTS_AND_DEPS);
|
||||
},
|
||||
|
||||
// Content API Actions
|
||||
getRouteInfo(context, { pageName }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetRouteInfo.method,
|
||||
endpoint: endpoints.GetRouteInfo.url,
|
||||
payload: {
|
||||
pageName: pageName,
|
||||
},
|
||||
});
|
||||
},
|
||||
getHomepageName(context) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetHomepageInfo.method,
|
||||
endpoint: endpoints.GetHomepageInfo.url,
|
||||
});
|
||||
},
|
||||
getPageData(context, { pageName }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetPageData.method,
|
||||
endpoint: `${endpoints.GetPageData.url}/${pageName}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
getEvoxImage(context, { relativeUrl }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetPageData.method,
|
||||
endpoint: relativeUrl,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
export default createStore({
|
||||
plugins: [createPersistedState()],
|
||||
|
||||
|
|
@ -12,221 +233,8 @@ export default createStore({
|
|||
// * The CMS can reference the fields by name
|
||||
// * Return users may have a previous "version" of the model, and we don't want
|
||||
// them to have a breaking experience, because the model might have changed.
|
||||
state: {
|
||||
order: {
|
||||
vehicle: {
|
||||
year: null,
|
||||
make: null,
|
||||
model: null,
|
||||
style: null,
|
||||
carId: null,
|
||||
category: null,
|
||||
damage: {
|
||||
isRepair: null,
|
||||
numberOfChips: null,
|
||||
glassToReplace: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
applicationUser: {
|
||||
eventBus: [],
|
||||
},
|
||||
},
|
||||
// See IMPORTANT note at top of "state" declaration.
|
||||
|
||||
mutations: {
|
||||
// VEHICLE MUTATIONS
|
||||
updateYear(state, year) {
|
||||
state.order.vehicle.year = year;
|
||||
},
|
||||
updateMake(state, make) {
|
||||
state.order.vehicle.make = make;
|
||||
},
|
||||
updateModel(state, model) {
|
||||
state.order.vehicle.model = model;
|
||||
},
|
||||
updateStyle(state, style) {
|
||||
state.order.vehicle.style = style;
|
||||
},
|
||||
updateCarId(state, carId) {
|
||||
state.order.vehicle.carId = carId;
|
||||
},
|
||||
updateVehicleCategory(state, category) {
|
||||
state.order.vehicle.category = category;
|
||||
},
|
||||
updateVehicle(state, data) {
|
||||
state.order.vehicle.carId = data.carId;
|
||||
state.order.vehicle.category = data.category;
|
||||
},
|
||||
|
||||
// EVENT BUS MUTATIONS
|
||||
addEventToBus(state, event) {
|
||||
state.applicationUser.eventBus.push(event);
|
||||
},
|
||||
removeEventFromBus(state, eventData) {
|
||||
const matchedEvent = state.applicationUser.eventBus.find(
|
||||
({ category, subCategory }) =>
|
||||
category === eventData.category &&
|
||||
subCategory === eventData.subCategory
|
||||
);
|
||||
const itemIndex = state.applicationUser.eventBus.indexOf(matchedEvent);
|
||||
|
||||
// If the item exists, remove it.
|
||||
if (itemIndex > -1) {
|
||||
state.applicationUser.eventBus.splice(itemIndex, 1);
|
||||
}
|
||||
},
|
||||
|
||||
// DEPENDENCY MUTATIONS
|
||||
resetVehicleAndDependencies(state) {
|
||||
state.order.vehicle.year = null;
|
||||
state.order.vehicle.make = null;
|
||||
state.order.vehicle.model = null;
|
||||
state.order.vehicle.style = null;
|
||||
state.order.vehicle.carId = null;
|
||||
state.order.vehicle.category = null;
|
||||
},
|
||||
resetDamageAndDependencies(state) {
|
||||
state.order.vehicle.damage.isRepair = null;
|
||||
state.order.vehicle.damage.numberOfChips = null;
|
||||
state.order.vehicle.damage.windshieldGlassToReplace = null;
|
||||
state.order.vehicle.damage.driverSideGlassToReplace = null;
|
||||
state.order.vehicle.damage.passengerSideGlassToReplace = null;
|
||||
state.order.vehicle.damage.rearGlassToReplace = null;
|
||||
|
||||
},
|
||||
resetRegistrationAndDependencies(state) {
|
||||
|
||||
},
|
||||
resetPartsAndDependencies(state) {
|
||||
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
vehicle: (state) => state.order.vehicle,
|
||||
eventBusItem: (state) => (eventCategory, eventSubCategory) => {
|
||||
const matchedEvent = state.applicationUser.eventBus.find(
|
||||
({ category, subCategory }) =>
|
||||
category === eventCategory && subCategory === eventSubCategory
|
||||
);
|
||||
|
||||
return matchedEvent !== undefined ? matchedEvent.eventValue : undefined;
|
||||
},
|
||||
eventBus: (state) => state.applicationUser.eventBus,
|
||||
},
|
||||
actions: {
|
||||
// Vehicle API Actions
|
||||
getVehicleYears(context) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleYears.method,
|
||||
endpoint: endpoints.GetVehicleYears.url,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
lookupVehicleByYmms(context, { year, make, model, style }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LookupVehicleByYmms.method,
|
||||
endpoint: `${endpoints.LookupVehicleByYmms.url}/${year}/${make}/${model}/${style}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
lookupVehicleByVin(context, { vin }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LookupVehicleByVin.method,
|
||||
endpoint: endpoints.LookupVehicleByVin.url,
|
||||
payload: {
|
||||
vin: vin, // EX "1J4GW58S4XC541166"
|
||||
},
|
||||
});
|
||||
},
|
||||
getVehicleMakes(context, { year }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleMakes.method,
|
||||
endpoint: `${endpoints.GetVehicleMakes.url}/${year}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
getVehicleModels(context, { year, make }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleModels.method,
|
||||
endpoint: `${endpoints.GetVehicleModels.url}/${year}/${make}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
getVehicleStyles(context, { year, make, model }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleStyles.method,
|
||||
endpoint: `${endpoints.GetVehicleStyles.url}/${year}/${make}/${model}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
setVehicle(context, { year, make, model, style }) {
|
||||
return globalMethods
|
||||
.callHttpClient({
|
||||
methods: endpoints.GetVehicle.method,
|
||||
endpoint: `${endpoints.GetVehicle.url}/${year}/${make}/${model}/${style}`,
|
||||
payload: {},
|
||||
})
|
||||
.then((response) => {
|
||||
context.commit(storeMutations.UPDATE_VEHICLE, response.data);
|
||||
return response;
|
||||
});
|
||||
},
|
||||
getDamageOptions(context, { carId }) {
|
||||
return globalMethods.callHttpClient({
|
||||
methods: endpoints.GetDamageOptions.method,
|
||||
endpoint: `${endpoints.GetDamageOptions.url}/${carId}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
|
||||
// DEPENDENCY ACTIONS
|
||||
resetVehicleAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_VEHICLE_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_DAMAGE_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_REGISTRATION_AND_DEPS);
|
||||
},
|
||||
resetDamageAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_DAMAGE_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_PARTS_AND_DEPS);
|
||||
},
|
||||
resetRegistrationAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_REGISTRATION_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_PARTS_AND_DEPS)
|
||||
},
|
||||
resetPartsAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_PARTS_AND_DEPS);
|
||||
},
|
||||
|
||||
// Content API Actions
|
||||
getRouteInfo(context, { pageName }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetRouteInfo.method,
|
||||
endpoint: endpoints.GetRouteInfo.url,
|
||||
payload: {
|
||||
pageName: pageName,
|
||||
},
|
||||
});
|
||||
},
|
||||
getHomepageName(context) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetHomepageInfo.method,
|
||||
endpoint: endpoints.GetHomepageInfo.url,
|
||||
});
|
||||
},
|
||||
getPageData(context, { pageName }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetPageData.method,
|
||||
endpoint: `${endpoints.GetPageData.url}/${pageName}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
getEvoxImage(context, { relativeUrl }) {
|
||||
return globalMethods.callMockHttpClient({
|
||||
method: endpoints.GetPageData.method,
|
||||
endpoint: relativeUrl,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
},
|
||||
state,
|
||||
mutations,
|
||||
getters,
|
||||
actions,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,552 +1,434 @@
|
|||
import globalMethods from "@/global-methods";
|
||||
import store from "@/store";
|
||||
import { mutations, state, actions } from "@/store";
|
||||
import { storeMutations } from "@/constants/store-mutations";
|
||||
|
||||
// Mock Store
|
||||
jest.mock("@/store", () => ({
|
||||
commit: jest.fn(),
|
||||
dispatch: jest.fn(),
|
||||
// IMPORTANT: Be VERY careful when modifying these fields for at least a few reasons:
|
||||
// * The CMS can reference the fields by name
|
||||
// * Return users may have a previous "version" of the model, and we don't want
|
||||
// them to have a breaking experience, because the model might have changed.
|
||||
state: {
|
||||
order: {
|
||||
vehicle: {
|
||||
year: null,
|
||||
make: null,
|
||||
model: null,
|
||||
style: null,
|
||||
carId: null,
|
||||
category: null,
|
||||
damage: {
|
||||
isRepair: null,
|
||||
numberOfChips: null,
|
||||
glassToReplace: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
applicationUser: {
|
||||
eventBus: [],
|
||||
},
|
||||
},
|
||||
// See IMPORTANT note at top of "state" declaration.
|
||||
// Mock global method
|
||||
globalMethods.callHttpClient = jest.fn();
|
||||
|
||||
mutations: {
|
||||
// VEHICLE MUTATIONS
|
||||
updateYear: jest.fn(),
|
||||
updateMake: jest.fn(),
|
||||
updateModel(state, model) {
|
||||
state.order.vehicle.model = model;
|
||||
},
|
||||
updateStyle(state, style) {
|
||||
state.order.vehicle.style = style;
|
||||
},
|
||||
updateCarId(state, carId) {
|
||||
state.order.vehicle.carId = carId;
|
||||
},
|
||||
updateVehicleCategory(state, category) {
|
||||
state.order.vehicle.category = category;
|
||||
},
|
||||
updateVehicle(state, data) {
|
||||
state.order.vehicle.carId = data.carId;
|
||||
state.order.vehicle.category = data.category;
|
||||
},
|
||||
describe("Mutations", () => {
|
||||
|
||||
// EVENT BUS MUTATIONS
|
||||
addEventToBus(state, event) {
|
||||
state.applicationUser.eventBus.push(event);
|
||||
},
|
||||
removeEventFromBus(state, eventData) {
|
||||
const matchedEvent = state.applicationUser.eventBus.find(
|
||||
({ category, subCategory }) =>
|
||||
category === eventData.category &&
|
||||
subCategory === eventData.subCategory
|
||||
);
|
||||
const itemIndex = state.applicationUser.eventBus.indexOf(matchedEvent);
|
||||
it("Updates vehicle year in state", () => {
|
||||
// Arrange
|
||||
const storeState = state;
|
||||
|
||||
// If the item exists, remove it.
|
||||
if (itemIndex > -1) {
|
||||
state.applicationUser.eventBus.splice(itemIndex, 1);
|
||||
}
|
||||
},
|
||||
// Act
|
||||
mutations.updateYear(storeState, "2019");
|
||||
|
||||
// DEPENDENCY MUTATIONS
|
||||
resetVehicleAndDependencies(state) {
|
||||
state.order.vehicle.year = null;
|
||||
state.order.vehicle.make = null;
|
||||
state.order.vehicle.model = null;
|
||||
state.order.vehicle.style = null;
|
||||
state.order.vehicle.carId = null;
|
||||
state.order.vehicle.category = null;
|
||||
},
|
||||
resetDamageAndDependencies(state) {
|
||||
state.order.vehicle.damage.isRepair = null;
|
||||
state.order.vehicle.damage.numberOfChips = null;
|
||||
state.order.vehicle.damage.windshieldGlassToReplace = null;
|
||||
state.order.vehicle.damage.driverSideGlassToReplace = null;
|
||||
state.order.vehicle.damage.passengerSideGlassToReplace = null;
|
||||
state.order.vehicle.damage.rearGlassToReplace = null;
|
||||
// Assert
|
||||
expect(storeState.order.vehicle.year).toEqual("2019");
|
||||
});
|
||||
|
||||
},
|
||||
resetRegistrationAndDependencies(state) {
|
||||
it("Updates vehicle make in state", () => {
|
||||
// Arrange
|
||||
const storeState = state;
|
||||
|
||||
},
|
||||
resetPartsAndDependencies(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("resetVehicleAndDependencies, 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.resetVehicleAndDependencies(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("resetDamageAndDependencies, should set fields to null", () => {
|
||||
// Arrange
|
||||
const storeState = state;
|
||||
|
||||
storeState.order.vehicle.damage = {
|
||||
isRepair: true,
|
||||
numberOfChips: 2,
|
||||
windshieldGlassToReplace: "Front",
|
||||
driverSideGlassToReplace: "Rear",
|
||||
passengerSideGlassToReplace: "Rear",
|
||||
rearGlassToReplace: "Slider"
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
vehicle: (state) => state.order.vehicle,
|
||||
eventBusItem: (state) => (eventCategory, eventSubCategory) => {
|
||||
const matchedEvent = state.applicationUser.eventBus.find(
|
||||
({ category, subCategory }) =>
|
||||
category === eventCategory && subCategory === eventSubCategory
|
||||
);
|
||||
|
||||
return matchedEvent !== undefined ? matchedEvent.eventValue : undefined;
|
||||
},
|
||||
eventBus: (state) => state.applicationUser.eventBus,
|
||||
},
|
||||
actions: {
|
||||
// Vehicle API Actions
|
||||
getVehicleYears(context) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleYears.method,
|
||||
endpoint: endpoints.GetVehicleYears.url,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
lookupVehicleByYmms(context, { year, make, model, style }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LookupVehicleByYmms.method,
|
||||
endpoint: `${endpoints.LookupVehicleByYmms.url}/${year}/${make}/${model}/${style}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
lookupVehicleByVin(context, { vin }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LookupVehicleByVin.method,
|
||||
endpoint: endpoints.LookupVehicleByVin.url,
|
||||
payload: {
|
||||
vin: vin, // EX "1J4GW58S4XC541166"
|
||||
},
|
||||
});
|
||||
},
|
||||
getVehicleMakes(context, { year }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleMakes.method,
|
||||
endpoint: `${endpoints.GetVehicleMakes.url}/${year}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
getVehicleModels(context, { year, make }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleModels.method,
|
||||
endpoint: `${endpoints.GetVehicleModels.url}/${year}/${make}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
getVehicleStyles(context, { year, make, model }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetVehicleStyles.method,
|
||||
endpoint: `${endpoints.GetVehicleStyles.url}/${year}/${make}/${model}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
setVehicle(context, { year, make, model, style }) {
|
||||
return globalMethods
|
||||
.callHttpClient({
|
||||
methods: endpoints.GetVehicle.method,
|
||||
endpoint: `${endpoints.GetVehicle.url}/${year}/${make}/${model}/${style}`,
|
||||
payload: {},
|
||||
})
|
||||
.then((response) => {
|
||||
context.commit(storeMutations.UPDATE_VEHICLE, response.data);
|
||||
return response;
|
||||
});
|
||||
},
|
||||
getDamageOptions(context, { carId }) {
|
||||
return globalMethods.callHttpClient({
|
||||
methods: endpoints.GetDamageOptions.method,
|
||||
endpoint: `${endpoints.GetDamageOptions.url}/${carId}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
// Expect
|
||||
expect(storeState.order.vehicle.damage.isRepair).toEqual(true);
|
||||
expect(storeState.order.vehicle.damage.numberOfChips).toEqual(2);
|
||||
expect(storeState.order.vehicle.damage.windshieldGlassToReplace).toEqual("Front");
|
||||
expect(storeState.order.vehicle.damage.driverSideGlassToReplace).toEqual("Rear");
|
||||
expect(storeState.order.vehicle.damage.passengerSideGlassToReplace).toEqual("Rear");
|
||||
expect(storeState.order.vehicle.damage.rearGlassToReplace).toEqual("Slider");
|
||||
|
||||
// DEPENDENCY ACTIONS
|
||||
resetVehicleAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_VEHICLE_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_DAMAGE_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_REGISTRATION_AND_DEPS);
|
||||
},
|
||||
resetDamageAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_DAMAGE_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_PARTS_AND_DEPS);
|
||||
},
|
||||
resetRegistrationAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_REGISTRATION_AND_DEPS);
|
||||
context.commit(storeMutations.RESET_PARTS_AND_DEPS)
|
||||
},
|
||||
resetPartsAndDependencies(context) {
|
||||
context.commit(storeMutations.RESET_PARTS_AND_DEPS);
|
||||
},
|
||||
// Act
|
||||
mutations.resetDamageAndDependencies(storeState);
|
||||
|
||||
// Content API Actions
|
||||
getRouteInfo(context, { pageName }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetRouteInfo.method,
|
||||
endpoint: endpoints.GetRouteInfo.url,
|
||||
payload: {
|
||||
pageName: pageName,
|
||||
},
|
||||
});
|
||||
},
|
||||
getHomepageName(context) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetHomepageInfo.method,
|
||||
endpoint: endpoints.GetHomepageInfo.url,
|
||||
});
|
||||
},
|
||||
getPageData(context, { pageName }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetPageData.method,
|
||||
endpoint: `${endpoints.GetPageData.url}/${pageName}`,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
getEvoxImage(context, { relativeUrl }) {
|
||||
return globalMethods.callMockHttpClient({
|
||||
method: endpoints.GetPageData.method,
|
||||
endpoint: relativeUrl,
|
||||
payload: {},
|
||||
});
|
||||
},
|
||||
},
|
||||
}));
|
||||
// Expect
|
||||
expect(storeState.order.vehicle.damage.isRepair).toEqual(null);
|
||||
expect(storeState.order.vehicle.damage.numberOfChips).toEqual(null);
|
||||
expect(storeState.order.vehicle.damage.windshieldGlassToReplace).toEqual(null);
|
||||
expect(storeState.order.vehicle.damage.driverSideGlassToReplace).toEqual(null);
|
||||
expect(storeState.order.vehicle.damage.passengerSideGlassToReplace).toEqual(null);
|
||||
expect(storeState.order.vehicle.damage.rearGlassToReplace).toEqual(null);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("Actions", () => {
|
||||
it("Should return list of years retrieved", async () => {
|
||||
it("getVehicleYears action, should return years array", async () => {
|
||||
|
||||
// Arrange
|
||||
let years = [];
|
||||
console.log(getPageData);
|
||||
const context = state;
|
||||
|
||||
// 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);
|
||||
const response = await actions.getVehicleYears(context)
|
||||
|
||||
expect(response.data).toEqual([2023, 2022, 2021]);
|
||||
});
|
||||
|
||||
it("Should return list of makes retrieved", async () => {
|
||||
it("lookupVehicleByYmms action, should return car data", async () => {
|
||||
|
||||
// Arrange
|
||||
let makes = [];
|
||||
const context = state;
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ data: ["Baic", "Honda", "Ford"] });
|
||||
});
|
||||
await store.dispatch("getVehicleMakes", { year: 2023 }).then((response) => {
|
||||
makes = response.data;
|
||||
return Promise.resolve({ data: { carId: "C00000001" } });
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(makes[0]).toBe("Baic");
|
||||
const response = await actions.lookupVehicleByYmms(context, "2019", "Acura", "ILX", "4 DOOR SEDAN")
|
||||
|
||||
expect(response.data).toEqual({ carId: "C00000001" });
|
||||
});
|
||||
|
||||
it("Should return list of models retrieved", async () => {
|
||||
it("lookupVehicleByVin action, should return car data", async () => {
|
||||
|
||||
// Arrange
|
||||
let models = [];
|
||||
const context = state;
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ data: ["BJ40 (MEX)", "Civic", "Accord"] });
|
||||
return Promise.resolve({ data: { carId: "C00000001" } });
|
||||
});
|
||||
await store
|
||||
.dispatch("getVehicleModels", { year: 2023, make: "Baic" })
|
||||
.then((response) => {
|
||||
models = response.data;
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(models[0]).toBe("BJ40 (MEX)");
|
||||
const response = await actions.lookupVehicleByVin(context, "12345678901234567")
|
||||
|
||||
expect(response.data).toEqual({ carId: "C00000001" });
|
||||
});
|
||||
|
||||
it("Should return list of styles retrieved", async () => {
|
||||
it("getVehicleMakes action, should return makes list", async () => {
|
||||
|
||||
// Arrange
|
||||
let styles = [];
|
||||
const context = state;
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ data: ["4 DOOR UTILITY", "2 DOOR"] });
|
||||
return Promise.resolve({ data: ["Acura", "Honda"] });
|
||||
});
|
||||
await store
|
||||
.dispatch("getVehicleStyles", {
|
||||
year: 2023,
|
||||
make: "Baic",
|
||||
model: "BJ40 (MEX)",
|
||||
})
|
||||
.then((response) => {
|
||||
styles = response.data;
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(styles[0]).toBe("4 DOOR UTILITY");
|
||||
const response = await actions.getVehicleMakes(context, "2019")
|
||||
|
||||
expect(response.data).toEqual(["Acura", "Honda"]);
|
||||
});
|
||||
|
||||
it("Should return list of damage options retrieved", async () => {
|
||||
it("getVehicleModels action, should return models list", async () => {
|
||||
|
||||
// Arrange
|
||||
let damageOptions = [];
|
||||
const context = state;
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ data: ["Front Window", "Rear Window"] });
|
||||
return Promise.resolve({ data: ["ILX", "RDX"] });
|
||||
});
|
||||
await store
|
||||
.dispatch("getDamageOptions", {
|
||||
carId: "CR00070154",
|
||||
})
|
||||
.then((response) => {
|
||||
damageOptions = response.data;
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(damageOptions[0]).toBe("Front Window");
|
||||
const response = await actions.getVehicleModels(context, "2019", "Acura")
|
||||
|
||||
expect(response.data).toEqual(["ILX", "RDX"]);
|
||||
});
|
||||
|
||||
it("Should return data from url retrieved", async () => {
|
||||
it("getVehicleStyles action, should return models list", async () => {
|
||||
|
||||
// Arrange
|
||||
let routeInfo = [];
|
||||
const context = state;
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
Result: "Route Info Data",
|
||||
},
|
||||
});
|
||||
return Promise.resolve({ data: { style: "4 DOOR SEDAN" } });
|
||||
});
|
||||
await store
|
||||
.dispatch("getRouteInfo", { pageName: "vehicle-year" })
|
||||
.then((response) => {
|
||||
routeInfo = response.data.Result;
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(routeInfo).toBe("Route Info Data");
|
||||
const response = await actions.getVehicleStyles(context, "2019", "Acura", "ILX")
|
||||
|
||||
expect(response.data).toEqual({ style: "4 DOOR SEDAN" });
|
||||
});
|
||||
|
||||
it("Should return page data from url retrieved", async () => {
|
||||
it("setVehicle action, should get vehicle data and set carId and vehicle category", async () => {
|
||||
|
||||
// Arrange
|
||||
let pageData = [];
|
||||
const context = state;
|
||||
const commit = jest.fn();
|
||||
|
||||
context.commit = commit;
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
Result: "Page Info Data",
|
||||
},
|
||||
});
|
||||
return Promise.resolve({ data: { carId: "C00000000", category: "CAR" } });
|
||||
});
|
||||
await store
|
||||
.dispatch("getPageData", { pageName: "vehicle-year" })
|
||||
.then((response) => {
|
||||
pageData = response.data.Result;
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(pageData).toBe("Page Info Data");
|
||||
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("Should return data from url retrieved", async () => {
|
||||
it("getDamageOptions action", async () => {
|
||||
|
||||
// Arrange
|
||||
let returnData = [];
|
||||
const context = state;
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
Result: "2018 Honda Civic",
|
||||
},
|
||||
});
|
||||
return Promise.resolve({ data: ["Windshield", "DriversFrontDoor"] });
|
||||
});
|
||||
await store
|
||||
.dispatch("lookupVehicleByYmms", {
|
||||
year: "2018",
|
||||
make: "Honda",
|
||||
model: "Civic",
|
||||
style: "2 Door",
|
||||
})
|
||||
.then((response) => {
|
||||
returnData = response.data.Result;
|
||||
});
|
||||
|
||||
const response = await actions.getDamageOptions(context, "C00000000")
|
||||
|
||||
// Assert
|
||||
expect(returnData).toBe("2018 Honda Civic");
|
||||
expect(response.data).toEqual(["Windshield", "DriversFrontDoor"]);
|
||||
});
|
||||
|
||||
it("Should return vehicle data from url retrieved", async () => {
|
||||
it("resetVehicleAndDependencies action", async () => {
|
||||
|
||||
// Arrange
|
||||
let returnData = [];
|
||||
const context = state;
|
||||
const commit = jest.fn();
|
||||
|
||||
context.commit = commit;
|
||||
|
||||
// Act
|
||||
await actions.resetVehicleAndDependencies(context)
|
||||
|
||||
expect(commit).toBeCalledWith(storeMutations.RESET_VEHICLE_AND_DEPS);
|
||||
expect(commit).toBeCalledWith(storeMutations.RESET_DAMAGE_AND_DEPS);
|
||||
expect(commit).toBeCalledWith(storeMutations.RESET_REGISTRATION_AND_DEPS);
|
||||
|
||||
});
|
||||
|
||||
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_AND_DEPS);
|
||||
expect(commit).toBeCalledWith(storeMutations.RESET_PARTS_AND_DEPS);
|
||||
|
||||
});
|
||||
|
||||
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_AND_DEPS);
|
||||
expect(commit).toBeCalledWith(storeMutations.RESET_PARTS_AND_DEPS);
|
||||
|
||||
});
|
||||
|
||||
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_AND_DEPS);
|
||||
|
||||
});
|
||||
|
||||
it("getRouteInfo action, returns route info", async () => {
|
||||
|
||||
// Arrange
|
||||
const context = state;
|
||||
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
Result: "2021 Honda Civic",
|
||||
},
|
||||
});
|
||||
return Promise.resolve({ data: { Widget: "Data" } });
|
||||
});
|
||||
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",
|
||||
},
|
||||
});
|
||||
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" } });
|
||||
});
|
||||
await store
|
||||
.dispatch("getEvoxImage", { relativeUrl: "evox_image.com" })
|
||||
.then((response) => {
|
||||
returnData = response.data.Result;
|
||||
|
||||
// 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" } });
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(returnData).toBe("2008_honda_civic.jpg");
|
||||
});
|
||||
});
|
||||
// Act
|
||||
const response = await actions.getEvoxImage(context, { relativeUrl: "https://relativeurl.com" } );
|
||||
|
||||
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);
|
||||
expect(response.data).toEqual({ imageUrl: "https://test.com" });
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue