import { useMainStore } from "./" 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 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 = { "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); expect(store.order.vehicle.imageUrl).toEqual(response.imageUrl); expect(store.order.vehicle.imageVifNumber).toEqual(response.imageVifNumber); expect(store.order.vehicle.imageVifColor).toEqual(response.imageVifColor); }); it("setVehicle should call globalMethods.callHttpClient", () => { store.order.vehicle = jest.fn(); const response = { "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(); }); });