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 sysHelper from "./salesforce-helper-sys"; import * as prodHelper from "./salesforce-helper-prod"; import { applicationConfig } from "../../constants/application-config"; describe("salesforceWebchat.vue", () => { beforeEach(() => { window.embeddedservice_bootstrap = { settings: {}, }; }); afterEach(() => { delete window.embeddedservice_bootstrap; }); 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({ isWebchatLoaded: false, isWebchatOpen: false, }); }); 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", () => { applicationConfig.CURRENT_ENVIRONMENT = "Prod"; let wrapper = shallowMount(salesforceWebchat); const mockProd = jest.spyOn(prodHelper, "initializeSalesforceWebchatForProd"); wrapper.vm.initializeSalesforceWebchat(); expect(mockProd).toHaveBeenCalled(); applicationConfig.CURRENT_ENVIRONMENT = "QA"; wrapper = shallowMount(salesforceWebchat); const mockQa = jest.spyOn(qaHelper, "initializeSalesforceWebchatForQa"); wrapper.vm.initializeSalesforceWebchat(); expect(mockQa).toHaveBeenCalled(); applicationConfig.CURRENT_ENVIRONMENT = "SysTest"; wrapper = shallowMount(salesforceWebchat); const mockSys = jest.spyOn(sysHelper, "initializeSalesforceWebchatForSys"); wrapper.vm.initializeSalesforceWebchat(); expect(mockSys).toHaveBeenCalled(); applicationConfig.CURRENT_ENVIRONMENT = "Dev"; wrapper = shallowMount(salesforceWebchat); const mockDev = jest.spyOn(devHelper, "initializeSalesforceWebchatForDev"); wrapper.vm.initializeSalesforceWebchat(); expect(mockDev).toHaveBeenCalled(); }); });