import { mount } from "@vue/test-utils";
import navbar from "./nav-bar";

describe("nav-bar.vue", () => {
    test("Should emit ForwardClicked on button click", async () => {
        // Act
        const wrapper = mount(navbar, {
            mixins: [mockMixin],
        });
        wrapper.vm.buttonClick();
        // Assert
        expect(wrapper.emitted()["ForwardClicked"][0]).toHaveBeenCalled;
    });

    test("Should emit BackClicked on link click", async () => {
        // Act
        const wrapper = mount(navbar, {
            mixins: [mockMixin],
        });
        wrapper.vm.linkClick();
        // Assert
        expect(wrapper.emitted()["BackClicked"][0]).toHaveBeenCalled;
    });

    test("Should change button text when update button text is called", async () => {
        // Act
        const wrapper = mount(navbar, {
            mixins: [mockMixin],
        });
        wrapper.vm.updateButtonText("newText");

        // Assert
        expect(wrapper.componentVM.customButtontext).toBe("newText");
    });

    test("should run removeLoader fn on buttonMain and return false for onkeydown fn", async () => {
        // Arrange
        const wrapper = mount(navbar, {
            mixins: [mockMixin],
        });

        // Act
        wrapper.vm.$refs.buttonMain.removeLoader = jest.fn();
        wrapper.vm.removeLoader();
        const spy = jest.spyOn(document, "onkeydown");
        document.onkeydown();

        // Assert
        expect(wrapper.vm.$refs.buttonMain.removeLoader).toHaveBeenCalled();
        expect(spy).toReturnWith(true);
    });
});

const mockMixin = {
    methods: {
        getCmsContent: jest.fn(),
        getFooterInfoBoxHeight: jest.fn(() => 80),
    },
};
