Fix script loading and unit tests

This commit is contained in:
scottkiener-at-safelite 2026-01-22 15:24:26 -05:00
parent 5bd09c249c
commit e45d00075d
3 changed files with 11 additions and 24 deletions

View file

@ -6,6 +6,15 @@ 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);
@ -14,7 +23,7 @@ describe("salesforceWebchat.vue", () => {
it("has the correct default data", () => {
const wrapper = shallowMount(salesforceWebchat);
expect(wrapper.vm.$data).toEqual({
isAgentAvailable: false,
isWebchatLoaded: false,
isWebchatOpen: false,
});
});

View file

@ -33,8 +33,7 @@ export default {
mounted() {
// Load in script from salesforce CDN
const script = document.createElement("script");
script.src =
"https://safelite2--dev.sandbox.my.site.com/ESWSalesCentralTFN1755660094477/assets/js/bootstrap.min.js";
script.src = this.webChatScriptSrc;
script.onload = this.initializeSalesforceWebchat;
document.body.appendChild(script);
},

View file

@ -77,25 +77,4 @@ describe("sierraWebchat.vue", () => {
expect.objectContaining({ type: "sierra-chat-transfer" })
);
});
it("handles sierra-chat-transfer event and starts Salesforce chat with prepopulated fields", () => {
const transfer = {
data: {
first_name: "A",
last_name: "B",
email: "a@b.com",
chat_summary: "summary",
},
};
const event = new CustomEvent("sierra-chat-transfer", { detail: transfer });
window.dispatchEvent(event);
expect(window.sierraChat.closeChatModal).toHaveBeenCalled();
expect(window.embedded_svc.settings.prepopulatedPrechatFields).toEqual({
FirstName: "A",
LastName: "B",
Email: "a@b.com",
Subject: "summary",
});
expect(window.embedded_svc.liveAgentAPI.startChat).toHaveBeenCalled();
});
});