Fix script loading and unit tests
This commit is contained in:
parent
5bd09c249c
commit
e45d00075d
3 changed files with 11 additions and 24 deletions
|
|
@ -6,6 +6,15 @@ import * as prodHelper from "./salesforce-helper-prod";
|
||||||
import { applicationConfig } from "../../constants/application-config";
|
import { applicationConfig } from "../../constants/application-config";
|
||||||
|
|
||||||
describe("salesforceWebchat.vue", () => {
|
describe("salesforceWebchat.vue", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
window.embeddedservice_bootstrap = {
|
||||||
|
settings: {},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
delete window.embeddedservice_bootstrap;
|
||||||
|
});
|
||||||
it("renders correctly", () => {
|
it("renders correctly", () => {
|
||||||
const wrapper = shallowMount(salesforceWebchat);
|
const wrapper = shallowMount(salesforceWebchat);
|
||||||
expect(wrapper.exists()).toBe(true);
|
expect(wrapper.exists()).toBe(true);
|
||||||
|
|
@ -14,7 +23,7 @@ describe("salesforceWebchat.vue", () => {
|
||||||
it("has the correct default data", () => {
|
it("has the correct default data", () => {
|
||||||
const wrapper = shallowMount(salesforceWebchat);
|
const wrapper = shallowMount(salesforceWebchat);
|
||||||
expect(wrapper.vm.$data).toEqual({
|
expect(wrapper.vm.$data).toEqual({
|
||||||
isAgentAvailable: false,
|
isWebchatLoaded: false,
|
||||||
isWebchatOpen: false,
|
isWebchatOpen: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,7 @@ export default {
|
||||||
mounted() {
|
mounted() {
|
||||||
// Load in script from salesforce CDN
|
// Load in script from salesforce CDN
|
||||||
const script = document.createElement("script");
|
const script = document.createElement("script");
|
||||||
script.src =
|
script.src = this.webChatScriptSrc;
|
||||||
"https://safelite2--dev.sandbox.my.site.com/ESWSalesCentralTFN1755660094477/assets/js/bootstrap.min.js";
|
|
||||||
script.onload = this.initializeSalesforceWebchat;
|
script.onload = this.initializeSalesforceWebchat;
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -77,25 +77,4 @@ describe("sierraWebchat.vue", () => {
|
||||||
expect.objectContaining({ type: "sierra-chat-transfer" })
|
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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue