import { shallowMount } from "@vue/test-utils";
import salesforceWebchat from "./salesforce-webchat.vue";
import * as devHelper from "./salesforce-helper-dev";
import * as qaHelper from "./salesforce-helper-qa";
import * as prodHelper from "./salesforce-helper-prod";

describe("salesforceWebchat.vue", () => {
    it("renders correctly", () => {
        const wrapper = shallowMount(salesforceWebchat);
        expect(wrapper.exists()).toBe(true);
    });

    it("has the correct default data", () => {
        const wrapper = shallowMount(salesforceWebchat);
        expect(wrapper.vm.$data).toEqual({});
    });

    it("has the correct default props", () => {
        const wrapper = shallowMount(salesforceWebchat);
        expect(wrapper.props().hideSalesforceWebchatLaunchButton).toBe(false);
    });

    it("calls the correct initialization function based on environment", () => {
        process.env.VUE_APP_CURRENT_ENVIRONMENT = "Prod";
        let wrapper = shallowMount(salesforceWebchat);
        mockProd = jest.spyOn(prodHelper, "initializeSalesforceWebchatForProd");
        wrapper.vm.initializeSalesforceWebchat();
        expect(mockProd).toHaveBeenCalled();

        process.env.VUE_APP_CURRENT_ENVIRONMENT = "QA";
        wrapper = shallowMount(salesforceWebchat);
        mockQa = jest.spyOn(qaHelper, "initializeSalesforceWebchatForQa");
        wrapper.vm.initializeSalesforceWebchat();
        expect(mockQa).toHaveBeenCalled();

        process.env.VUE_APP_CURRENT_ENVIRONMENT = "Dev";
        wrapper = shallowMount(salesforceWebchat);
        mockDev = jest.spyOn(devHelper, "initializeSalesforceWebchatForDev");
        wrapper.vm.initializeSalesforceWebchat();
        expect(mockDev).toHaveBeenCalled();
    });
});
