CASH-188 | Update unit tests
This commit is contained in:
parent
be188c905d
commit
0965ed1207
3 changed files with 89 additions and 4 deletions
|
|
@ -0,0 +1,38 @@
|
||||||
|
import * as salesforceWebchatHelperdev from './salesforce-helper-dev';
|
||||||
|
import * as salesforceWebchatHelperqa from './salesforce-helper-qa';
|
||||||
|
import * as salesforceWebchatHelperprod from './salesforce-helper-prod';
|
||||||
|
|
||||||
|
const mockEmbeddedSvc = {
|
||||||
|
settings: {},
|
||||||
|
init: jest.fn(),
|
||||||
|
testFlag: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("Salesforce Webchat Helper Tests", () => {
|
||||||
|
describe("Files and exposed methods exist", () => {
|
||||||
|
it("exposes initialization methods", () => {
|
||||||
|
expect(typeof salesforceWebchatHelperdev.initializeSalesforceWebchatForDev).toBe("function");
|
||||||
|
expect(typeof salesforceWebchatHelperqa.initializeSalesforceWebchatForQa).toBe("function");
|
||||||
|
expect(typeof salesforceWebchatHelperprod.initializeSalesforceWebchatForProd).toBe("function");
|
||||||
|
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
describe("Custom code added correctly", ()=> {
|
||||||
|
it("defines a local variable 'embedded_svc' in the initESW method", ()=> {
|
||||||
|
mockEmbeddedSvc.testFlag = "dev";
|
||||||
|
window.embedded_svc = mockEmbeddedSvc;
|
||||||
|
salesforceWebchatHelperdev.initializeSalesforceWebchatForDev();
|
||||||
|
expect(embedded_svc.testFlag).toBe("dev");
|
||||||
|
|
||||||
|
mockEmbeddedSvc.testFlag = "qa";
|
||||||
|
window.embedded_svc = mockEmbeddedSvc;
|
||||||
|
salesforceWebchatHelperqa.initializeSalesforceWebchatForQa();
|
||||||
|
expect(embedded_svc.testFlag).toBe("qa");
|
||||||
|
|
||||||
|
mockEmbeddedSvc.testFlag = "prod";
|
||||||
|
window.embedded_svc = mockEmbeddedSvc;
|
||||||
|
salesforceWebchatHelperprod.initializeSalesforceWebchatForProd();
|
||||||
|
expect(embedded_svc.testFlag).toBe("prod");
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
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("appends script to document body on mount", () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -23,7 +23,11 @@ export default {
|
||||||
// Load in script from salesforce CDN
|
// Load in script from salesforce CDN
|
||||||
const script = document.createElement("script");
|
const script = document.createElement("script");
|
||||||
script.src = "https://service.force.com/embeddedservice/5.0/esw.min.js";
|
script.src = "https://service.force.com/embeddedservice/5.0/esw.min.js";
|
||||||
script.onload = () => {
|
script.onload = this.initializeSalesforceWebchat;
|
||||||
|
document.body.appendChild(script);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
initializeSalesforceWebchat() {
|
||||||
switch (process.env.VUE_APP_CURRENT_ENVIRONMENT) {
|
switch (process.env.VUE_APP_CURRENT_ENVIRONMENT) {
|
||||||
case "Prod":
|
case "Prod":
|
||||||
initializeSalesforceWebchatForProd();
|
initializeSalesforceWebchatForProd();
|
||||||
|
|
@ -37,10 +41,8 @@ export default {
|
||||||
initializeSalesforceWebchatForDev();
|
initializeSalesforceWebchatForDev();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
document.body.appendChild(script);
|
|
||||||
},
|
},
|
||||||
methods: {},
|
|
||||||
computed: {},
|
computed: {},
|
||||||
components: {},
|
components: {},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue