DigitalConsumer.FixMyGlass/src/digital-components/salesforce-webchat/salesforce-webchat.spec.js
scottkiener-at-safelite a96d45c4a5 Unit tests
2026-01-23 11:05:27 -05:00

62 lines
2.4 KiB
JavaScript

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();
});
});