I have an Angular component which uses the AWS connect-streams library. However I am having problems trying to mock this library for unit test purposes.
In my component.ts file I have the following:
public ngOnInit() {
connect.core.initCCP(el, {
ccpUrl: this.ccpUrl,
loginPopup: false,
loginPopupAutoClose: true,
});
connect.contact((contactSessionObj) => {
contactSessionObj.onIncoming((_evt) => {
this.onIncomingHandler(_evt, contactSessionObj);
});
contactSessionObj.onConnected((_evt: any) => {
this.onConnectedHandler(_evt, contactSessionObj);
});
});
private onIncomingHandler(_evt, _contact) {
if (this.isClosed) {
this.toggleWindow();
}
}
private onConnectedHandler(_evt, contact) {
const contactAttributes = contact.getAttributes();
const phoneNumber = contactAttributes.phoneNumber.value;
}
I am trying to mock the connect object but cannot work out the structure that would enable me to test that this.onIncomingHandler() and this.onConnectedHandler() are called when the onIncoming and onConnected callbacks are invoked. This is where I'm at but I realise this approach doesnt quite line up:
window['connect'] = {
core: {
initCCP: () => { },
},
contact: () => {
const contactObj = {};
contactObj['onIncoming'] = (cb) => { cb(); };
contactObj['onConnected'] = (cb) => { cb(); };
return contactObj;
}
};