import { globalEvents, globalEventTypes } from "@/constants/events";
import eventBus from "@/helpers/event-bus/event-bus";
import store from "@/store";

describe("event-bus.js", () => {
    let event = {
        isDismissible: true,
        messageCopy: "You can get a quote by starting on this page.",
        messageHeadline: "We're sorry, something went wrong.",
        type: globalEventTypes.Danger,
    };

    it("Puts item on bus and then take it off", () => {
        // Arrange / Act
        eventBus.addEventToBus(
            globalEvents.Categories.GLOBAL_ALERT,
            globalEvents.SubCategories.PAGE_NOT_FOUND,
            event
        );

        // Assert
        expect(
            store.getters.eventBusItem(
                globalEvents.Categories.GLOBAL_ALERT,
                globalEvents.SubCategories.PAGE_NOT_FOUND
            )
        ).toEqual(event);

        expect(store.state.applicationUser.eventBus.length).toEqual(1);

        // Arrange / Act
        const eventValue = eventBus.readAndPopEventFromBus(
            globalEvents.Categories.GLOBAL_ALERT,
            globalEvents.SubCategories.PAGE_NOT_FOUND
        );

        // Assert
        expect(eventValue).toEqual(event);

        expect(store.state.applicationUser.eventBus.length).toEqual(0);
    });

    it("Reads event from bus, should have event value.", () => {
        // Arrange / Act
        eventBus.addEventToBus(
            globalEvents.Categories.GLOBAL_ALERT,
            globalEvents.SubCategories.PAGE_NOT_FOUND,
            event
        );

        // Assert
        expect(
            eventBus.readEventFromBus(
                globalEvents.Categories.GLOBAL_ALERT,
                globalEvents.SubCategories.PAGE_NOT_FOUND
            )
        ).toEqual(event);
    });
});
