@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
143 lines • 5.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const index_1 = require("../index");
const test_utils_1 = require("../test/test-utils");
const authInstance = tslib_1.__importStar(require("../auth"));
const thoughtSpotHost = 'tshost';
const defaultViewConfig = {
frameParams: {
width: 1280,
height: 720,
},
};
beforeAll(() => {
(0, index_1.init)({
thoughtSpotHost,
authType: index_1.AuthType.None,
});
jest.spyOn(window, 'alert');
jest.spyOn(authInstance, 'postLoginService').mockImplementation(() => Promise.resolve(undefined));
});
describe('test view config', () => {
beforeEach(() => {
document.body.innerHTML = (0, test_utils_1.getDocumentBody)();
});
test('should apply width and height to the iframe', async () => {
const width = 800;
const height = 600;
const searchEmbed = new index_1.SearchEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
frameParams: {
width,
height,
},
});
searchEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
const iframe = (0, test_utils_1.getIFrameEl)();
expect(iframe.style.width).toBe(`${width}px`);
expect(iframe.style.height).toBe(`${height}px`);
});
});
test('should pass hideResults parameter when configured', async () => {
const searchEmbed = new index_1.SearchEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
hideResults: true,
});
searchEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
const iframeSrc = (0, test_utils_1.getIFrameSrc)();
(0, test_utils_1.expectUrlToHaveParamsWithValues)(iframeSrc, {
hideResult: true,
});
});
});
test('should pass forceTable parameter when configured', async () => {
const searchEmbed = new index_1.SearchEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
forceTable: true,
});
searchEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
const iframeSrc = (0, test_utils_1.getIFrameSrc)();
(0, test_utils_1.expectUrlToHaveParamsWithValues)(iframeSrc, {
forceTable: true,
});
});
});
test('should pass enableSearchAssist parameter when configured', async () => {
const searchEmbed = new index_1.SearchEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
enableSearchAssist: true,
});
searchEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
const iframeSrc = (0, test_utils_1.getIFrameSrc)();
(0, test_utils_1.expectUrlToHaveParamsWithValues)(iframeSrc, {
enableSearchAssist: true,
});
});
});
test('should pass hideSearchBar parameter when configured', async () => {
const searchEmbed = new index_1.SearchEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
hideSearchBar: true,
});
searchEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
const iframeSrc = (0, test_utils_1.getIFrameSrc)();
(0, test_utils_1.expectUrlToHaveParamsWithValues)(iframeSrc, {
hideSearchBar: true,
});
});
});
test('should register and trigger event listeners', async () => {
const searchEmbed = new index_1.SearchEmbed((0, test_utils_1.getRootEl)(), defaultViewConfig);
const mockCallback = jest.fn();
searchEmbed.on(index_1.EmbedEvent.Load, mockCallback);
await searchEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
const iframe = (0, test_utils_1.getIFrameEl)();
(0, test_utils_1.postMessageToParent)(iframe.contentWindow, {
type: index_1.EmbedEvent.Load,
});
});
await (0, test_utils_1.executeAfterWait)(() => {
expect(mockCallback).toHaveBeenCalled();
}, test_utils_1.EVENT_WAIT_TIME);
});
test('should pass disabledActions parameter when configured', async () => {
const disabledActions = [index_1.Action.Download, index_1.Action.Share];
const searchEmbed = new index_1.SearchEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
disabledActions,
});
searchEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
const iframeSrc = (0, test_utils_1.getIFrameSrc)();
expect(iframeSrc).toContain('disableAction');
});
});
test('should pass runtime filters when configured', async () => {
const runtimeFilters = [
{
columnName: 'revenue',
operator: index_1.RuntimeFilterOp.GT,
values: [1000],
},
];
const searchEmbed = new index_1.SearchEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
runtimeFilters,
});
searchEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
const iframeSrc = (0, test_utils_1.getIFrameSrc)();
expect(iframeSrc).toContain('col1=revenue');
expect(iframeSrc).toContain('op1=GT');
expect(iframeSrc).toContain('val1=1000');
});
});
});
//# sourceMappingURL=embed.spec.js.map