UNPKG

@thoughtspot/visual-embed-sdk

Version:
945 lines 59.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const liveboard_1 = require("./liveboard"); const index_1 = require("../index"); const types_1 = require("../types"); const test_utils_1 = require("../test/test-utils"); const tsEmbed = tslib_1.__importStar(require("./ts-embed")); const processTriggerInstance = tslib_1.__importStar(require("../utils/processTrigger")); const auth = tslib_1.__importStar(require("../auth")); const previewService = tslib_1.__importStar(require("../utils/graphql/preview-service")); const SessionInfoService = tslib_1.__importStar(require("../utils/sessionInfoService")); const defaultViewConfig = { frameParams: { width: 1280, height: 720, }, }; const liveboardId = 'eca215d4-0d2c-4a55-90e3-d81ef6848ae0'; const activeTabId = '502693ba-9818-4e71-8ecd-d1a194e46861'; const newActiveTabId = '910e2398-eed9-443c-a975-355976629d27'; const vizId = '6e73f724-660e-11eb-ae93-0242ac130002'; const thoughtSpotHost = 'tshost'; const prefixParams = '&isLiveboardEmbed=true'; const prefixParamsVizEmbed = '&isLiveboardEmbed=true&isVizEmbed=true'; const mockGetSessionInfo = (mockSessionInfo) => { jest.spyOn(SessionInfoService, 'getSessionInfo').mockResolvedValue(mockSessionInfo || { releaseVersion: '1.0.0', userGUID: '1234567890', currentOrgId: 1, privileges: [], mixpanelToken: '1234567890', }); }; beforeAll(() => { (0, index_1.init)({ thoughtSpotHost, authType: types_1.AuthType.None, }); jest.spyOn(auth, 'postLoginService').mockImplementation(() => Promise.resolve({})); }); describe('Liveboard/viz embed tests', () => { beforeEach(() => { document.body.innerHTML = (0, test_utils_1.getDocumentBody)(); }); test('should render liveboard', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should render liveboard with data panel v2 flag set to false by default', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}${prefixParams}&enableDataPanelV2=true#/embed/viz/${liveboardId}`); }); }); test('should set disabled actions', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { disabledActions: [types_1.Action.DownloadAsCsv, types_1.Action.DownloadAsPdf, types_1.Action.DownloadAsXlsx], disabledActionReason: 'Action denied', ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&${test_utils_1.defaultParamsWithoutHiddenActions}&disableAction=[%22${types_1.Action.DownloadAsCsv}%22,%22${types_1.Action.DownloadAsPdf}%22,%22${types_1.Action.DownloadAsXlsx}%22]&disableHint=Action%20denied&hideAction=[%22${types_1.Action.ReportError}%22]${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should set hidden actions', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { hiddenActions: [types_1.Action.DownloadAsCsv, types_1.Action.DownloadAsPdf, types_1.Action.DownloadAsXlsx], ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&${test_utils_1.defaultParamsWithoutHiddenActions}&hideAction=[%22${types_1.Action.ReportError}%22,%22${types_1.Action.DownloadAsCsv}%22,%22${types_1.Action.DownloadAsPdf}%22,%22${types_1.Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should set visible actions', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { visibleActions: [types_1.Action.DownloadAsCsv, types_1.Action.DownloadAsPdf, types_1.Action.DownloadAsXlsx], ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&visibleAction=[%22${types_1.Action.DownloadAsCsv}%22,%22${types_1.Action.DownloadAsPdf}%22,%22${types_1.Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should set enable2ColumnLayout to true in url', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { enable2ColumnLayout: true, ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&enable2ColumnLayout=true${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should set isLiveboardStylingAndGroupingEnabled to true in url', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { isLiveboardStylingAndGroupingEnabled: true, ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&isLiveboardStylingAndGroupingEnabled=true${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should set isPNGInScheduledEmailsEnabled to true in url', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { isPNGInScheduledEmailsEnabled: true, ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&isPNGInScheduledEmailsEnabled=true${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should set visible actions as empty array', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { visibleActions: [], ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&visibleAction=[]${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should enable viz transformations true', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { enableVizTransformations: true, ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&enableVizTransform=true${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should enable viz oAuthPollingInterval true', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { oAuthPollingInterval: 1000, isForceRedirect: true, dataSourceId: '12356', ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&oAuthPollingInterval=1000&isForceRedirect=true&dataSourceId=12356${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should disable viz transformations when enableVizTransformations false', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { enableVizTransformations: false, ...defaultViewConfig, liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&enableVizTransform=false${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should render viz', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, vizId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}${prefixParamsVizEmbed}#/embed/viz/${liveboardId}/${vizId}`); }); }); test('should apply runtime filters', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, vizId, runtimeFilters: [ { columnName: 'sales', operator: types_1.RuntimeFilterOp.EQ, values: [1000], }, ], excludeRuntimeFiltersfromURL: false, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&col1=sales&op1=EQ&val1=1000${test_utils_1.defaultParams}${prefixParamsVizEmbed}#/embed/viz/${liveboardId}/${vizId}`); }); }); test('Should add isLiveboardHeaderSticky flag to the iframe src', async () => { const appEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, isLiveboardHeaderSticky: false, }); appEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&isLiveboardHeaderSticky=false${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('Should add isLiveboardCompactHeaderEnabled flag to the iframe src', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, isLiveboardCompactHeaderEnabled: false, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&isLiveboardHeaderV2Enabled=false${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('Should add showLiveboardReverifyBanner flag to the iframe src', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, showLiveboardReverifyBanner: false, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&showLiveboardReverifyBanner=false${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('Should add showLiveboardVerifiedBadge flag to the iframe src', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, showLiveboardVerifiedBadge: false, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&showLiveboardVerifiedBadge=false${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('Should add hideIrrelevantFiltersAtTabLevel flag to the iframe src', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, hideIrrelevantChipsInLiveboardTabs: true, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&hideIrrelevantFiltersAtTabLevel=true${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should add coverAndFilterOptionInPDF flag and set value to true to the iframe src', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, coverAndFilterOptionInPDF: true, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&arePdfCoverFilterPageCheckboxesEnabled=true${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should add coverAndFilterOptionInPDF flag and set value to false to the iframe src', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, coverAndFilterOptionInPDF: false, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&arePdfCoverFilterPageCheckboxesEnabled=false&${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should add liveboardXLSXCSVDownload flag and set value to true to the iframe src', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, liveboardXLSXCSVDownload: true, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&isLiveboardXLSXCSVDownloadEnabled=true${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should add liveboardXLSXCSVDownload flag and set value to false to the iframe src', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, liveboardXLSXCSVDownload: false, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&isLiveboardXLSXCSVDownloadEnabled=false&${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should not append runtime filters in URL if excludeRuntimeFiltersfromURL is true', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, vizId, runtimeFilters: [ { columnName: 'sales', operator: types_1.RuntimeFilterOp.EQ, values: [1000], }, ], }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}${prefixParamsVizEmbed}#/embed/viz/${liveboardId}/${vizId}`); }); }); test('Should not append runtime parameters in URL if excludeRuntimeParametersfromURL is true', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, vizId, runtimeParameters: [ { name: 'sales', value: 1000, }, ], excludeRuntimeParametersfromURL: true, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}${prefixParamsVizEmbed}#/embed/viz/${liveboardId}/${vizId}`); }); }); test('should append runtime filters in URL if excludeRuntimeFiltersfromURL is undefined', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, vizId, runtimeFilters: [ { columnName: 'sales', operator: types_1.RuntimeFilterOp.EQ, values: [1000], }, ], }); liveboardEmbed.render(); const runtimeFilter = 'col1=sales&op1=EQ&val1=1000'; await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}${prefixParamsVizEmbed}&${runtimeFilter}#/embed/viz/${liveboardId}/${vizId}`); }); }); test('should register event handler to adjust iframe height', async () => { const onSpy = jest.spyOn(liveboard_1.LiveboardEmbed.prototype, 'on'); const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, fullHeight: true, liveboardId, vizId, }); liveboardEmbed.render(); (0, test_utils_1.executeAfterWait)(() => { expect(onSpy).toHaveBeenCalledWith(types_1.EmbedEvent.EmbedHeight, expect.anything()); }); }); test('should not call setIFrameHeight if currentPath starts with "/embed/viz/"', () => { const myObject = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, fullHeight: true, liveboardId, }); const spySetIFrameHeight = jest.spyOn(myObject, 'setIFrameHeight'); myObject.render(); myObject.setIframeHeightForNonEmbedLiveboard({ data: { currentPath: '/embed/viz/' }, type: 'Route', }); // Assert that setIFrameHeight is not called expect(spySetIFrameHeight).not.toHaveBeenCalled(); }); test('should not call setIFrameHeight if currentPath starts with "/embed/insights/viz/"', () => { const myObject = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, fullHeight: true, liveboardId, }); const spySetIFrameHeight = jest.spyOn(myObject, 'setIFrameHeight'); myObject.render(); myObject.setIframeHeightForNonEmbedLiveboard({ data: { currentPath: '/embed/insights/viz/' }, type: 'Route', }); // Assert that setIFrameHeight is not called expect(spySetIFrameHeight).not.toHaveBeenCalled(); }); test('should call setIFrameHeight if currentPath starts with "/some/other/path/"', () => { const myObject = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, fullHeight: true, liveboardId, }); const spySetIFrameHeight = jest .spyOn(myObject, 'setIFrameHeight') .mockImplementation(jest.fn()); myObject.render(); myObject.setIframeHeightForNonEmbedLiveboard({ data: { currentPath: '/some/other/path/' }, type: 'Route', }); // Assert that setIFrameHeight is not called expect(spySetIFrameHeight).toHaveBeenCalled(); }); test('Should set the visible vizs', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, visibleVizs: ['abcd', 'pqrs'], }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&pinboardVisibleVizs=[%22abcd%22,%22pqrs%22]${prefixParams}#/embed/viz/${liveboardId}`); }); }); test('should process the trigger, for vizEmbed', async () => { const mockProcessTrigger = spyOn(processTriggerInstance, 'processTrigger'); const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { enableVizTransformations: true, ...defaultViewConfig, vizId: '1234', liveboardId, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(async () => { await liveboardEmbed.trigger(types_1.HostEvent.Pin); expect(mockProcessTrigger).toBeCalled(); }); }); test('should render active tab when activeTab present', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { liveboardId, activeTabId, liveboardV2: true, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&isLiveboardEmbed=true&isPinboardV2Enabled=true#/embed/viz/${liveboardId}/tab/${activeTabId}`); }); }); test('Should set liveboard options', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { liveboardId, activeTabId, liveboardV2: true, defaultHeight: 100, preventLiveboardFilterRemoval: true, enableAskSage: true, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&preventPinboardFilterRemoval=true&isLiveboardEmbed=true&isPinboardV2Enabled=true&enableAskSage=true#/embed/viz/${liveboardId}/tab/${activeTabId}`); }); }); test('Should set contextMenuTrigger options', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { liveboardId, activeTabId, liveboardV2: true, contextMenuTrigger: types_1.ContextMenuTriggerOptions.LEFT_CLICK, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&contextMenuEnabledOnWhichClick=left&isLiveboardEmbed=true&isPinboardV2Enabled=true#/embed/viz/${liveboardId}/tab/${activeTabId}`); }); }); test('Should set hideTabPanel option', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { liveboardId, activeTabId, liveboardV2: true, hideTabPanel: true, }); liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}&hideTabPanel=true&isLiveboardEmbed=true&isPinboardV2Enabled=true#/embed/viz/${liveboardId}/tab/${activeTabId}`); }); }); test('navigateToLiveboard should trigger the navigate event with the correct path', async (done) => { (0, test_utils_1.mockMessageChannel)(); // mock getSessionInfo mockGetSessionInfo(); const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, }); const onSpy = jest.spyOn(liveboardEmbed, 'trigger'); await liveboardEmbed.prerenderGeneric(); (0, test_utils_1.executeAfterWait)(() => { const iframe = (0, test_utils_1.getIFrameEl)(); (0, test_utils_1.postMessageToParent)(iframe.contentWindow, { type: types_1.EmbedEvent.APP_INIT, }); (0, test_utils_1.postMessageToParent)(iframe.contentWindow, { type: types_1.EmbedEvent.AuthInit, }); liveboardEmbed.navigateToLiveboard('lb1', 'viz1'); }); (0, test_utils_1.executeAfterWait)(() => { expect(onSpy).toHaveBeenCalledWith(types_1.HostEvent.Navigate, 'embed/viz/lb1/viz1'); done(); }, 1002); }); test('navigateToLiveboard with preRender', async (done) => { (0, test_utils_1.mockMessageChannel)(); // mock getSessionInfo mockGetSessionInfo(); const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, preRenderId: 'test', }); const onSpy = jest.spyOn(liveboardEmbed, 'trigger'); await liveboardEmbed.prerenderGeneric(); (0, test_utils_1.executeAfterWait)(() => { const iframe = (0, test_utils_1.getIFrameEl)(); (0, test_utils_1.postMessageToParent)(iframe.contentWindow, { type: types_1.EmbedEvent.APP_INIT, }); (0, test_utils_1.postMessageToParent)(iframe.contentWindow, { type: types_1.EmbedEvent.AuthInit, }); }); (0, test_utils_1.executeAfterWait)(() => { liveboardEmbed.navigateToLiveboard('lb1', 'viz1'); expect(onSpy).toHaveBeenCalledWith(types_1.HostEvent.Navigate, 'embed/viz/lb1/viz1'); done(); }, 1002); }); test('should set runtime parametere values in url params', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, runtimeParameters: [ { name: 'Integer Date Range', value: 1, }, ], }); await liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}${prefixParams}&param1=Integer%20Date%20Range&paramVal1=1#/embed/viz/${liveboardId}`); }); }); test('should set showSpotterLimitations parameter in url params', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, showSpotterLimitations: true, }); await liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true${test_utils_1.defaultParams}${prefixParams}&showSpotterLimitations=true#/embed/viz/${liveboardId}`); }); }); test('SetActiveTab Hostevent should not trigger the navigate event with the correct path, for vizEmbed', async () => { const mockProcessTrigger = jest.spyOn(tsEmbed.TsEmbed.prototype, 'trigger'); const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { enableVizTransformations: true, ...defaultViewConfig, liveboardId, vizId, }); liveboardEmbed.render(); (0, test_utils_1.executeAfterWait)(() => { const result = liveboardEmbed.trigger(types_1.HostEvent.SetActiveTab, { tabId: newActiveTabId, }); expect(mockProcessTrigger).not.toBeCalled(); }); }); test('SetActiveTab Hostevent trigger the navigate event with the correct path, not vizEmbed', async () => { const mockProcessTrigger = jest.spyOn(tsEmbed.TsEmbed.prototype, 'trigger'); const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { enableVizTransformations: true, ...defaultViewConfig, liveboardId, }); await liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { const result = liveboardEmbed.trigger(types_1.HostEvent.SetActiveTab, { tabId: newActiveTabId, }); expect(mockProcessTrigger).toHaveBeenCalledWith(types_1.HostEvent.Navigate, `embed/viz/${liveboardId}/tab/${newActiveTabId}`); }); }); describe('PreRender flow for liveboard embed', () => { test('it should preRender generic with liveboard id is not passed', async (done) => { const consoleSpy = jest.spyOn(console, 'error'); const libEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { preRenderId: 'testPreRender', }); const prerenderGenericSpy = jest.spyOn(libEmbed, 'prerenderGeneric'); await libEmbed.preRender(); (0, test_utils_1.executeAfterWait)(() => { const iFrame = document.getElementById(libEmbed.getPreRenderIds().child); // should render the generic link expect(prerenderGenericSpy).toHaveBeenCalledTimes(1); expect(iFrame.src).toMatch(/http:\/\/tshost\/.*&isLiveboardEmbed=true.*#$/); expect(consoleSpy).toHaveBeenCalledTimes(0); done(); }); }); test('Show preview loader should not show the loader if not viz embed or showPreviewLoader is false', async () => { const libEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { liveboardId: '1234', }); await libEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { expect((0, test_utils_1.getRootEl)().innerHTML).not.toContain('ts-viz-preview-loader'); }); }); test('get liveboard url value', async () => { const libEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { liveboardId: '1234', }); await libEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { const url = libEmbed.getLiveboardUrl(); expect(url).toEqual('http://tshost/#/pinboard/1234'); }); }); test('Show preview loader should show the loader if viz embed and showPreviewLoader is true', async () => { jest.spyOn(previewService, 'getPreview').mockResolvedValue({ vizContent: '<div id=test>test</div>', }); const libEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { liveboardId: '1234', vizId: '5678', showPreviewLoader: true, }); await libEmbed.render(); expect(previewService.getPreview).toHaveBeenCalledWith('http://tshost', '5678', '1234'); await (0, test_utils_1.executeAfterWait)(() => { expect((0, test_utils_1.getRootEl)().style.position).toEqual('relative'); expect((0, test_utils_1.getRootEl)().innerHTML).toContain('<div class="ts-viz-preview-loader">'); expect((0, test_utils_1.getRootEl)().innerHTML).toContain('<div id="test">test</div>'); }); libEmbed.test__executeCallbacks(types_1.EmbedEvent.Data, {}); await (0, test_utils_1.executeAfterWait)(() => { expect((0, test_utils_1.getRootEl)().innerHTML).not.toContain('ts-viz-preview-loader'); }); }); test('it should navigateToLiveboard with liveboard id is not passed with EmbedListenerReady event', async (done) => { (0, test_utils_1.mockMessageChannel)(); const consoleSpy = jest.spyOn(console, 'error'); const testPreRenderId = 'testPreRender'; const libEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { preRenderId: testPreRenderId, }); let resizeObserverCb; window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation((resizeObserverCbParam) => { resizeObserverCb = resizeObserverCbParam; return { disconnect: jest.fn(), observe: jest.fn(), unobserve: jest.fn(), }; }); await libEmbed.preRender(); await (0, test_utils_1.waitFor)(() => !!(0, test_utils_1.getIFrameEl)()); const ts = '__tsEmbed'; expect(document.getElementById(libEmbed.getPreRenderIds().wrapper)[ts]).toEqual(libEmbed); await (0, test_utils_1.executeAfterWait)(() => { const iframe = (0, test_utils_1.getIFrameEl)(); (0, test_utils_1.postMessageToParent)(iframe.contentWindow, { type: types_1.EmbedEvent.EmbedListenerReady, }); }); const testLiveboardId = 'testLiveboardId'; const newLibEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { preRenderId: testPreRenderId, liveboardId: testLiveboardId, vizId: 'testVizId', activeTabId: 'testActiveTabId', }); const navigateToLiveboardSpy = jest.spyOn(newLibEmbed, 'navigateToLiveboard'); await newLibEmbed.showPreRender(); (0, test_utils_1.executeAfterWait)(() => { const iFrame = document.getElementById(libEmbed.getPreRenderIds().child); // should render the generic link expect(navigateToLiveboardSpy).toHaveBeenCalledWith(testLiveboardId, 'testVizId', 'testActiveTabId'); expect(iFrame.src).toMatch(/http:\/\/tshost\/.*&isLiveboardEmbed=true.*#$/); expect(consoleSpy).toHaveBeenCalledTimes(0); done(); }); }); test('it should navigateToLiveboard with liveboard id is not passed with AuthInit event', async (done) => { (0, test_utils_1.mockMessageChannel)(); const consoleSpy = jest.spyOn(console, 'error'); const testPreRenderId = 'testPreRender'; const libEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { preRenderId: testPreRenderId, }); mockGetSessionInfo(); let resizeObserverCb; window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation((resizeObserverCbParam) => { resizeObserverCb = resizeObserverCbParam; return { disconnect: jest.fn(), observe: jest.fn(), unobserve: jest.fn(), }; }); await libEmbed.preRender(); await (0, test_utils_1.waitFor)(() => !!(0, test_utils_1.getIFrameEl)()); const ts = '__tsEmbed'; expect(document.getElementById(libEmbed.getPreRenderIds().wrapper)[ts]).toEqual(libEmbed); const testLiveboardId = 'testLiveboardId'; const newLibEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { preRenderId: testPreRenderId, liveboardId: testLiveboardId, vizId: 'testVizId', activeTabId: 'testActiveTabId', }); const navigateToLiveboardSpy = jest.spyOn(newLibEmbed, 'navigateToLiveboard'); await newLibEmbed.showPreRender(); await (0, test_utils_1.executeAfterWait)(() => { const iFrame = document.getElementById(newLibEmbed.getPreRenderIds().child); (0, test_utils_1.postMessageToParent)(iFrame.contentWindow, { type: types_1.EmbedEvent.AuthInit, }); }); await (0, test_utils_1.executeAfterWait)(() => { const iFrame = document.getElementById(libEmbed.getPreRenderIds().child); // should render the generic link expect(navigateToLiveboardSpy).toHaveBeenCalledWith(testLiveboardId, 'testVizId', 'testActiveTabId'); expect(iFrame.src).toMatch(/http:\/\/tshost\/.*&isLiveboardEmbed=true.*#$/); expect(consoleSpy).toHaveBeenCalledTimes(0); done(); }, 1005); }); test('should replace existing preRender when replaceExistingPreRender is true', async () => { const testPreRenderId = 'testReplacePreRender'; // Stub ResizeObserver for JSDOM window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation(() => ({ disconnect: jest.fn(), observe: jest.fn(), unobserve: jest.fn(), })); // Create initial embed and show preRender (this will create the // preRender wrapper/child) const embedA = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { preRenderId: testPreRenderId, }); await embedA.showPreRender(); await (0, test_utils_1.waitFor)(() => !!(0, test_utils_1.getIFrameEl)()); const ids = embedA.getPreRenderIds(); const oldWrapper = document.getElementById(ids.wrapper); const oldChild = document.getElementById(ids.child); const tsKey = '__tsEmbed'; expect(oldWrapper[tsKey]).toBe(embedA); // Create a new embed instance and preRender with // replaceExistingPreRender = true const embedB = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { preRenderId: testPreRenderId, }); const prerenderGenericSpy = jest.spyOn(embedB, 'prerenderGeneric'); await embedB.preRender(false, true); await (0, test_utils_1.waitFor)(() => { var _a; return ((_a = document.getElementById(ids.wrapper)) === null || _a === void 0 ? void 0 : _a[tsKey]) === embedB; }); const newWrapper = document.getElementById(ids.wrapper); const newChild = document.getElementById(ids.child); // Should have called prerenderGeneric for the new embed instance expect(prerenderGenericSpy).toHaveBeenCalledTimes(1); // Wrapper should be replaced (new wrapper element), child iframe // may be reused expect(newWrapper).not.toBe(oldWrapper); // __tsEmbed on wrapper should now point to the new embed instance expect(newWrapper[tsKey]).toBe(embedB); }); }); describe('LazyLoadingForFullHeight functionality', () => { let mockIFrame; beforeEach(() => { mockIFrame = document.createElement('iframe'); mockIFrame.getBoundingClientRect = jest.fn().mockReturnValue({ top: 100, left: 150, bottom: 600, right: 800, width: 650, height: 500, }); jest.spyOn(document, 'createElement').mockImplementation((tagName) => { if (tagName === 'iframe') { return mockIFrame; } return document.createElement(tagName); }); }); afterEach(() => { jest.restoreAllMocks(); }); test('should set lazyLoadingMargin parameter when provided', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, fullHeight: true, lazyLoadingForFullHeight: true, lazyLoadingMargin: '100px 0px', }); await liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { const iframeSrc = (0, test_utils_1.getIFrameSrc)(); expect(iframeSrc).toContain('isLazyLoadingForEmbedEnabled=true'); expect(iframeSrc).toContain('isFullHeightPinboard=true'); expect(iframeSrc).toContain('rootMarginForLazyLoad=100px%200px'); }, 100); }); test('should set isLazyLoadingForEmbedEnabled=true when both fullHeight and lazyLoadingForFullHeight are enabled', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, fullHeight: true, lazyLoadingForFullHeight: true, }); await liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { const iframeSrc = (0, test_utils_1.getIFrameSrc)(); expect(iframeSrc).toContain('isLazyLoadingForEmbedEnabled=true'); expect(iframeSrc).toContain('isFullHeightPinboard=true'); }, 100); }); test('should not set lazyLoadingForEmbed when lazyLoadingForFullHeight is enabled but fullHeight is false', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, fullHeight: false, lazyLoadingForFullHeight: true, }); await liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { const iframeSrc = (0, test_utils_1.getIFrameSrc)(); expect(iframeSrc).not.toContain('isLazyLoadingForEmbedEnabled=true'); expect(iframeSrc).not.toContain('isFullHeightPinboard=true'); }, 100); }); test('should not set isLazyLoadingForEmbedEnabled when fullHeight is true but lazyLoadingForFullHeight is false', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, fullHeight: true, lazyLoadingForFullHeight: false, }); await liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { const iframeSrc = (0, test_utils_1.getIFrameSrc)(); expect(iframeSrc).not.toContain('isLazyLoadingForEmbedEnabled=true'); expect(iframeSrc).toContain('isFullHeightPinboard=true'); }, 100); }); test('should register event handlers to adjust iframe height', async () => { const onSpy = jest.spyOn(liveboard_1.LiveboardEmbed.prototype, 'on'); const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, fullHeight: true, lazyLoadingForFullHeight: true, }); await liveboardEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { expect(onSpy).toHaveBeenCalledWith(types_1.EmbedEvent.EmbedHeight, expect.anything()); expect(onSpy).toHaveBeenCalledWith(types_1.EmbedEvent.RouteChange, expect.anything()); expect(onSpy).toHaveBeenCalledWith(types_1.EmbedEvent.EmbedIframeCenter, expect.anything()); expect(onSpy).toHaveBeenCalledWith(types_1.EmbedEvent.RequestVisibleEmbedCoordinates, expect.anything()); }, 100); }); test('should send correct visible data when RequestVisibleEmbedCoordinates is triggered', async () => { const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, fullHeight: true, lazyLoadingForFullHeight: true, }); const mockTrigger = jest.spyOn(liveboardEmbed, 'trigger'); await liveboardEmbed.render(); // Trigger the lazy load data calculation liveboardEmbed.sendFullHeightLazyLoadData(); expect(mockTrigger).toHaveBeenCalledWith(types_1.HostEvent.VisibleEmbedCoordinates, { top: 0, height: 500, left: 0, width: 650, }); }); test('should calculate correct visible data for partially visible full height element', async () => { mockIFrame.getBoundingClientRect = jest.fn().mockReturnValue({ top: -50, left: -30, bottom: 700, right: 1024, width: 1054, height: 750, }); const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, fullHeight: true, lazyLoadingForFullHeight: true, }); const mockTrigger = jest.spyOn(liveboardEmbed, 'trigger'); await liveboardEmbed.render(); // Trigger the lazy load data calculation liveboardEmbed.sendFullHeightLazyLoadData(); expect(mockTrigger).toHaveBeenCalledWith(types_1.HostEvent.VisibleEmbedCoordinates, { top: 50, height: 700, left: 30, width: 1024, }); }); test('should add window event listeners for resize and scroll when fullHeight and lazyLoadingForFullHeight are enabled', async () => { const addEventListenerSpy = jest.spyOn(window, 'addEventListener'); const liveboardEmbed = new liveboard_1.LiveboardEmbed((0, test_utils_1.getRootEl)(), { ...defaultViewConfig, liveboardId, fullHeight: true, lazyLoadingForFullHeight: true, }); await liveboardEmbed.render(); // Wait for the post-render events to be registered await (0, test_utils_1.executeAfterWait)(() => { expect(addEventListenerSpy).toHaveBeenCalledWith('resize', expect.anythi