ashish-sdk
Version:
ThoughtSpot Embed SDK
41 lines (38 loc) • 1.43 kB
text/typescript
import * as _processTriggerInstance from './processTrigger';
import { HostEvent } from '../types';
describe('Unit test for processTrigger', () => {
const iFrame: any = {
contentWindow: {
postMessage: jest.fn(),
},
};
test('when hostevent is reload, childNode should not be the same as iFrame', async () => {
const iFrameElement = document.createElement('iframe');
const html = '<body>Foo</body>';
iFrameElement.src = `data:text/html;charset=utf-8,${encodeURI(html)}`;
const divFrame = document.createElement('div');
divFrame.appendChild(iFrameElement);
const messageType = HostEvent.Reload;
const thoughtSpotHost = 'http://localhost:3000';
const data = {};
_processTriggerInstance.processTrigger(
iFrameElement,
messageType,
thoughtSpotHost,
data,
);
expect(divFrame.childNodes[0]).not.toBe(iFrameElement);
});
test('when hostevent is search, postMessage should be called', async () => {
const messageType = HostEvent.Search;
const thoughtSpotHost = 'http://localhost:3000';
const data = {};
_processTriggerInstance.processTrigger(
iFrame,
messageType,
thoughtSpotHost,
data,
);
expect(iFrame.contentWindow.postMessage).toBeCalled();
});
});