DigitalConsumer.ISS/src/store/store.spec.js
Kulbhushan Kaushik 59fab86ceb commit
2022-11-14 08:45:12 -05:00

143 lines
No EOL
4.3 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.imageVifColor).toEqual(response.data.imageVifColor);
});
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();
});
});