222 lines
No EOL
6.5 KiB
JavaScript
222 lines
No EOL
6.5 KiB
JavaScript
import { useMainStore } from '@/store';
|
|
import { createApp } from 'vue';
|
|
import { createPinia } from "pinia";
|
|
import globalMethods from "@/global-methods";
|
|
import App from '@/App.vue';
|
|
|
|
|
|
describe("Store", () => {
|
|
|
|
let store;
|
|
|
|
const vueApp = createApp(App);
|
|
const pinia = createPinia();
|
|
vueApp.use(pinia);
|
|
|
|
beforeEach(() => {
|
|
store = useMainStore();
|
|
store.applicationUser.eventBus = [];
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
|
|
it("Should Store Vehicle Year", () => {
|
|
let testYear = "2001";
|
|
store.updateVehicleYear(testYear);
|
|
expect(store.order.vehicle.year).toEqual(testYear);
|
|
});
|
|
|
|
it("Should add events to the bus", () => {
|
|
let event = {
|
|
category: "TestCategory",
|
|
subCategory: "TestSubCategory",
|
|
eventValue: {
|
|
isDismissible: true,
|
|
messageCopy: "You can get a quote by starting on this page.",
|
|
messageHeadline: "We're sorry, something went wrong.",
|
|
type: "testType",
|
|
},
|
|
};
|
|
|
|
store.addEventToBus(event);
|
|
|
|
expect(store.applicationUser.eventBus[0]).toEqual(event);
|
|
});
|
|
|
|
it("Should remove events from the bus", () => {
|
|
let event = {
|
|
category: "TestCategory",
|
|
subCategory: "TestSubCategory",
|
|
eventValue: {
|
|
isDismissible: true,
|
|
messageCopy: "You can get a quote by starting on this page.",
|
|
messageHeadline: "We're sorry, something went wrong.",
|
|
type: "testType",
|
|
},
|
|
};
|
|
|
|
store.addEventToBus(event);
|
|
|
|
expect(store.applicationUser.eventBus.length).toBe(1);
|
|
|
|
store.removeEventFromBus({ category: event.category, subCategory: event.subCategory })
|
|
|
|
expect(store.applicationUser.eventBus.length).toBe(0);
|
|
});
|
|
|
|
it("Should return correct event using the getter function eventBusItem", () => {
|
|
let event = {
|
|
category: "TestCategory",
|
|
subCategory: "TestSubCategory",
|
|
eventValue: {
|
|
isDismissible: true,
|
|
messageCopy: "You can get a quote by starting on this page.",
|
|
messageHeadline: "We're sorry, something went wrong.",
|
|
type: "testType",
|
|
},
|
|
};
|
|
|
|
store.addEventToBus(event);
|
|
|
|
const actual = store.eventBusItem(event.category, event.subCategory)
|
|
|
|
expect(actual).toEqual(event.eventValue);
|
|
});
|
|
|
|
it("UpdateVehicle should merge vehicle with response object", () => {
|
|
store.order.vehicle = {
|
|
year: 2020,
|
|
make: "Honda",
|
|
model: "Civic",
|
|
style: "4 door sedan",
|
|
carId: null,
|
|
category: null,
|
|
vin: null,
|
|
imageUrl: null,
|
|
imageVifNumber: null,
|
|
imageColor: null,
|
|
};
|
|
|
|
const response = {data: {
|
|
"carId": "CR00069299",
|
|
"category": "CAR",
|
|
"year": 2020,
|
|
"make": "Honda",
|
|
"model": "Civic",
|
|
"style": "4 door sedan",
|
|
"imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg",
|
|
"imageVifNumber": "13996",
|
|
"imageVifColor": "white"
|
|
}
|
|
};
|
|
|
|
store.updateVehicle(response.data);
|
|
|
|
expect(store.order.vehicle.imageUrl).toEqual(response.data.imageUrl);
|
|
expect(store.order.vehicle.imageVifNumber).toEqual(response.data.imageVifNumber);
|
|
expect(store.order.vehicle.style).toEqual(response.data.style);
|
|
});
|
|
|
|
it("setVehicle should call globalMethods.callHttpClient", () => {
|
|
store.order.vehicle = jest.fn();
|
|
|
|
const response = {data: {
|
|
"carId": "CR00069299",
|
|
"category": "CAR",
|
|
"year": 2020,
|
|
"make": "Honda",
|
|
"model": "Civic",
|
|
"style": "4 door sedan",
|
|
"imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg",
|
|
"imageVifNumber": "13996",
|
|
"imageVifColor": "white"
|
|
}
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));
|
|
|
|
store.setVehicle();
|
|
|
|
expect(globalMethods.callHttpClient).toHaveBeenCalled();
|
|
});
|
|
|
|
it("saveVehicleDamage, should update damage", () => {
|
|
// Arrange
|
|
store.order.damage = {
|
|
glassToReplace: [{ glassName: "Single", glassLocation: "Windshield" }],
|
|
};
|
|
|
|
// Act
|
|
store.saveVehicleDamage( false,
|
|
[{ glassName: "Rear", glassLocation: "quarter" }],
|
|
0);
|
|
|
|
// Assert
|
|
expect(store.order.damage.glassToReplace).toEqual([{ glassName: "Rear", glassLocation: "quarter" }]);
|
|
expect(store.order.damage.isRepair).toEqual(false);
|
|
expect(store.order.damage.numberOfChips).toEqual(null);
|
|
});
|
|
|
|
it("should return registration data if available", () => {
|
|
//Arrange
|
|
const expected = {
|
|
addressQuestions: {
|
|
streetAddress: "test",
|
|
city: "city",
|
|
state: "state",
|
|
zipCode: "zip",
|
|
},
|
|
firstName: "1stName",
|
|
lastName: "Surname",
|
|
}
|
|
|
|
store.order.vehicle.registration = {
|
|
licensePlate: null,
|
|
address: "test",
|
|
city: "city",
|
|
state: "state",
|
|
zipCode: "zip",
|
|
firstName: "1stName",
|
|
lastName: "Surname",
|
|
};
|
|
|
|
//Act
|
|
const actual = store.customerData;
|
|
//Assert
|
|
|
|
expect(actual).toEqual(expected);
|
|
});
|
|
|
|
it("should return customer data if registration data unavailable", () => {
|
|
//Arrange
|
|
const expected = {
|
|
addressQuestions: {
|
|
streetAddress: "test",
|
|
city: "city",
|
|
state: "state",
|
|
zipCode: "zip",
|
|
},
|
|
firstName: "1stName",
|
|
lastName: "Surname",
|
|
}
|
|
|
|
store.order.vehicle.registration.address = null;
|
|
|
|
store.order.customer = {
|
|
licensePlate: null,
|
|
address: "test",
|
|
city: "city",
|
|
state: "state",
|
|
zipCode: "zip",
|
|
firstName: "1stName",
|
|
lastName: "Surname",
|
|
};
|
|
|
|
//Act
|
|
const actual = store.customerData;
|
|
//Assert
|
|
|
|
expect(actual).toEqual(expected);
|
|
});
|
|
|
|
}); |