@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
879 lines • 56.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const app_1 = require("./app");
const index_1 = require("../index");
const types_1 = require("../types");
const test_utils_1 = require("../test/test-utils");
const config = tslib_1.__importStar(require("../config"));
const ts_embed_1 = require("./ts-embed");
const logger_1 = require("../utils/logger");
const auth = tslib_1.__importStar(require("../auth"));
const defaultViewConfig = {
frameParams: {
width: 1280,
height: 720,
},
};
const thoughtSpotHost = 'tshost';
const defaultParamsPost = '';
const originalResizeObserver = window.ResizeObserver;
beforeAll(() => {
(0, index_1.init)({
thoughtSpotHost,
authType: types_1.AuthType.None,
});
jest.spyOn(auth, 'postLoginService').mockImplementation(() => Promise.resolve({}));
window.ResizeObserver =
window.ResizeObserver ||
jest.fn().mockImplementation(() => ({
disconnect: jest.fn(),
observe: jest.fn(),
unobserve: jest.fn(),
}));
});
const cleanUp = () => {
document.body.innerHTML = (0, test_utils_1.getDocumentBody)();
window.ResizeObserver = originalResizeObserver;
};
describe('App embed tests', () => {
beforeEach(() => {
cleanUp();
});
test('should render home page by default', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), defaultViewConfig);
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('should hide the primary nav bar', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
showPrimaryNavbar: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('should hide the help and profile buttons from nav bar', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
disableProfileAndHelp: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('should hide the application switcher button from nav bar', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
hideApplicationSwitcher: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&applicationSwitcherHidden=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('should hide the org switcher button from nav bar', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
hideOrgSwitcher: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&orgSwitcherHidden=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
describe('should render the correct routes for pages', () => {
const pageRouteMap = {
[app_1.Page.Search]: 'answer',
[app_1.Page.Answers]: 'answers',
[app_1.Page.Pinboards]: 'pinboards',
[app_1.Page.Liveboards]: 'pinboards',
[app_1.Page.Data]: 'data/tables',
[app_1.Page.Home]: 'home',
[app_1.Page.SpotIQ]: 'insights/results',
[app_1.Page.Monitor]: 'insights/monitor-alerts',
};
const pageIds = Object.keys(pageRouteMap);
for (let i = 0; i < pageIds.length; i++) {
const pageId = pageIds[i];
test(`${pageId}`, async () => {
const route = pageRouteMap[pageId];
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
pageId: pageId,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false${test_utils_1.defaultParams}${defaultParamsPost}#/${route}`);
cleanUp();
});
});
}
const pageRouteMapForModularHome = {
[app_1.Page.Search]: 'answer',
[app_1.Page.Answers]: 'home/answers',
[app_1.Page.Pinboards]: 'home/liveboards',
[app_1.Page.Liveboards]: 'home/liveboards',
[app_1.Page.Data]: 'data/tables',
[app_1.Page.Home]: 'home',
[app_1.Page.SpotIQ]: 'home/spotiq-analysis',
[app_1.Page.Monitor]: 'home/monitor-alerts',
};
const pageIdsForModularHomes = Object.keys(pageRouteMapForModularHome);
for (let i = 0; i < pageIdsForModularHomes.length; i++) {
const pageIdsForModularHome = pageIdsForModularHomes[i];
test(`${pageIdsForModularHome}`, async () => {
const route = pageRouteMapForModularHome[pageIdsForModularHome];
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
modularHomeExperience: true,
pageId: pageIdsForModularHome,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false${test_utils_1.defaultParams}${defaultParamsPost}#/${route}`);
cleanUp();
});
});
}
});
test('should navigate to a path', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
path: 'foo/bar',
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false${test_utils_1.defaultParams}${defaultParamsPost}#/foo/bar`);
});
});
test('should apply runtime filters', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
showPrimaryNavbar: true,
runtimeFilters: [
{
columnName: 'sales',
operator: types_1.RuntimeFilterOp.EQ,
values: [1000],
},
],
excludeRuntimeFiltersfromURL: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=false&profileAndHelpInNavBarHidden=false&col1=sales&op1=EQ&val1=1000${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('should not append runtime filters in URL if excludeRuntimeFiltersfromURL is true', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
showPrimaryNavbar: true,
runtimeFilters: [
{
columnName: 'sales',
operator: types_1.RuntimeFilterOp.EQ,
values: [1000],
},
],
excludeRuntimeFiltersfromURL: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=false&profileAndHelpInNavBarHidden=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('should append runtime filters in URL if excludeRuntimeFiltersfromURL is undefined', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
showPrimaryNavbar: true,
runtimeFilters: [
{
columnName: 'sales',
operator: types_1.RuntimeFilterOp.EQ,
values: [1000],
},
],
});
appEmbed.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&primaryNavHidden=false&profileAndHelpInNavBarHidden=false${test_utils_1.defaultParams}${defaultParamsPost}&${runtimeFilter}#/home`);
});
});
test('should disable and hide actions', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
showPrimaryNavbar: true,
disabledActions: [types_1.Action.Save, types_1.Action.Update],
disabledActionReason: 'Access denied',
hiddenActions: [types_1.Action.Download],
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=false&profileAndHelpInNavBarHidden=false&${test_utils_1.defaultParamsWithoutHiddenActions}&disableAction=[%22save%22,%22update%22]&disableHint=Access%20denied&hideAction=[%22${types_1.Action.ReportError}%22,%22download%22]${defaultParamsPost}#/home`);
});
});
test('should set enable2ColumnLayout to true in url', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
enable2ColumnLayout: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&profileAndHelpInNavBarHidden=false&enable2ColumnLayout=true${defaultParamsPost}#/home`);
});
});
test('should set coverAndFilterOptionInPDF to false in url', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
coverAndFilterOptionInPDF: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&profileAndHelpInNavBarHidden=false&arePdfCoverFilterPageCheckboxesEnabled=false${defaultParamsPost}#/home`);
});
});
test('should set isLiveboardStylingAndGroupingEnabled to true in url', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
isLiveboardStylingAndGroupingEnabled: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&profileAndHelpInNavBarHidden=false&isLiveboardStylingAndGroupingEnabled=true${defaultParamsPost}#/home`);
});
});
test('should set isPNGInScheduledEmailsEnabled to true in url', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
isPNGInScheduledEmailsEnabled: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&profileAndHelpInNavBarHidden=false&isPNGInScheduledEmailsEnabled=true${defaultParamsPost}#/home`);
});
});
test('should set liveboardXLSXCSVDownload to true in url', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
liveboardXLSXCSVDownload: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&profileAndHelpInNavBarHidden=false&isLiveboardXLSXCSVDownloadEnabled=true${defaultParamsPost}#/home`);
});
});
test('should set liveboardXLSXCSVDownload to false in url', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
liveboardXLSXCSVDownload: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&profileAndHelpInNavBarHidden=false&isLiveboardXLSXCSVDownloadEnabled=false${defaultParamsPost}#/home`);
});
});
test('Should add the tag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
showPrimaryNavbar: false,
tag: 'Finance',
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false${test_utils_1.defaultParams}&tag=Finance${defaultParamsPost}#/home`);
});
});
test('Should add enableSearchAssist flagto the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
enableSearchAssist: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&enableSearchAssist=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add enableDataPanelV2 flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
dataPanelV2: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&enableDataPanelV2=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add isLiveboardHeaderSticky flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
isLiveboardHeaderSticky: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&isLiveboardHeaderSticky=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add isLiveboardCompactHeaderEnabled flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
isLiveboardCompactHeaderEnabled: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&isLiveboardHeaderV2Enabled=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add showLiveboardReverifyBanner flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
showLiveboardReverifyBanner: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&showLiveboardReverifyBanner=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add isUnifiedSearchExperienceEnabled flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
isUnifiedSearchExperienceEnabled: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&isUnifiedSearchExperienceEnabled=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add hideIrrelevantFiltersAtTabLevel flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
hideIrrelevantChipsInLiveboardTabs: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&hideIrrelevantFiltersAtTabLevel=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add showLiveboardVerifiedBadge flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
showLiveboardVerifiedBadge: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&showLiveboardVerifiedBadge=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add default values of flags to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&isLiveboardHeaderSticky=true&hideLiveboardHeader=false&showLiveboardDescription=true&showLiveboardTitle=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add modularHomeExperience flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
modularHomeExperience: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add hideHomepageLeftNav flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
hideHomepageLeftNav: false,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&hideHomepageLeftNav=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add hideHamburger, hideObjectSearch, hideNotification flags to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
hideHamburger: true,
hideObjectSearch: true,
hideNotification: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&hideHamburger=true&hideObjectSearch=true&hideNotification=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should not add when hideHamburger, hideObjectSearch, hideNotification values are not true to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
hideHamburger: false,
hideObjectSearch: undefined,
hideNotification: null,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add navigationVersion=v3 when primaryNavbarVersion is Sliding to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
discoveryExperience: {
primaryNavbarVersion: app_1.PrimaryNavbarVersion.Sliding,
homePage: app_1.HomePage.Modular,
},
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=true&navigationVersion=v3${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should not add navigationVersion=v3 when primaryNavbarVersion is not added to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
discoveryExperience: {
homePage: app_1.HomePage.Modular,
},
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add navigationVersion=v3 & modularHomeExperience=true when primaryNavbarVersion is Sliding to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
// Not included the homePage v2 config under discoveryExperience.
discoveryExperience: {
primaryNavbarVersion: app_1.PrimaryNavbarVersion.Sliding,
},
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=true&navigationVersion=v3${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add homepageVersion=v3 & navigationVersion=v3 & modularHomeExperience=true when Sliding and ModularWithStylingChanges configured in the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
discoveryExperience: {
primaryNavbarVersion: app_1.PrimaryNavbarVersion.Sliding,
homePage: app_1.HomePage.ModularWithStylingChanges,
},
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=true&navigationVersion=v3&homepageVersion=v3${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add homepageVersion=v3 & navigationVersion=v3 & modularHomeExperience=true when homePage is ModularWithStylingChanges to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
// primaryNavbarVersion is not included under discoveryExperience,
// then it set navigationVersion=v2 and modularHomeExperience=false.
discoveryExperience: {
homePage: app_1.HomePage.ModularWithStylingChanges,
},
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&navigationVersion=v2&homepageVersion=v3${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add navigationVersion=v2 when primaryNavbarVersion is not added to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&navigationVersion=v2${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add enableAskSage flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
enableAskSage: true,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&enableAskSage=true${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add listpageVersion=v3 when listPageVersion is ListWithUXChanges to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
discoveryExperience: {
listPageVersion: app_1.ListPage.ListWithUXChanges,
},
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&listpageVersion=v3${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add listpageVersion=v2 by default when no discoveryExperience is provided', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&navigationVersion=v2&listpageVersion=v2${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add listpageVersion=v2 by default when discoveryExperience is provided but listPageVersion is not specified', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
discoveryExperience: {
primaryNavbarVersion: app_1.PrimaryNavbarVersion.Sliding,
homePage: app_1.HomePage.Modular,
},
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=true&navigationVersion=v3&listpageVersion=v2${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add listpageVersion=v3 combined with other discoveryExperience options to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
discoveryExperience: {
primaryNavbarVersion: app_1.PrimaryNavbarVersion.Sliding,
homePage: app_1.HomePage.Modular,
listPageVersion: app_1.ListPage.ListWithUXChanges,
},
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=true&navigationVersion=v3&listpageVersion=v3${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add enablePendoHelp flag to the iframe src conditional on navbar', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?enablePendoHelp=true&embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
const noNavEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
enablePendoHelp: false,
});
noNavEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?enablePendoHelp=false&embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add HomePageSearchBarMode flag with object search to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
homePageSearchBarMode: app_1.HomePageSearchBarMode.OBJECT_SEARCH,
});
await appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&homePageSearchBarMode=objectSearch${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add HomePageSearchBarMode flag with ai answer to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
homePageSearchBarMode: app_1.HomePageSearchBarMode.AI_ANSWER,
});
await appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&homePageSearchBarMode=aiAnswer${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add HomePageSearchBarMode flag with none to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
homePageSearchBarMode: app_1.HomePageSearchBarMode.NONE,
});
await appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&homePageSearchBarMode=none${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('Should add dataPanelCustomGroupsAccordionInitialState flag to the iframe src', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
dataPanelCustomGroupsAccordionInitialState: app_1.DataPanelCustomColumnGroupsAccordionState.EXPAND_FIRST,
});
appEmbed.render();
await (0, test_utils_1.executeAfterWait)(() => {
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&modularHomeExperience=false&dataPanelCustomGroupsAccordionInitialState=EXPAND_FIRST${test_utils_1.defaultParams}${defaultParamsPost}#/home`);
});
});
test('should register event handlers to adjust iframe height', async () => {
let embedHeightCallback = () => { };
const onSpy = jest.spyOn(app_1.AppEmbed.prototype, 'on').mockImplementation((event, callback) => {
if (event === types_1.EmbedEvent.RouteChange) {
callback({ data: { currentPath: '/answers' } }, jest.fn());
}
if (event === types_1.EmbedEvent.EmbedHeight) {
embedHeightCallback = callback;
}
if (event === types_1.EmbedEvent.EmbedIframeCenter) {
callback({}, jest.fn());
}
return null;
});
jest.spyOn(ts_embed_1.TsEmbed.prototype, 'getIframeCenter').mockReturnValue({});
jest.spyOn(ts_embed_1.TsEmbed.prototype, 'setIFrameHeight').mockReturnValue({});
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: true,
lazyLoadingForFullHeight: true,
});
// Set the iframe before render
appEmbed.iFrame = document.createElement('iframe');
// Wait for render to complete
await appEmbed.render();
embedHeightCallback({ data: '100%' });
// Verify event handlers were registered
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);
});
describe('Navigate to Page API', () => {
const path = 'pinboard/e0836cad-4fdf-42d4-bd97-567a6b2a6058';
beforeEach(() => {
jest.spyOn(config, 'getThoughtSpotHost').mockImplementation(() => 'http://tshost');
});
test('when app is AppEmbed after navigateToPage function call, new path should be set to iframe', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
frameParams: {
width: '100%',
height: '100%',
},
});
await appEmbed.render();
appEmbed.navigateToPage(path);
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${test_utils_1.defaultParamsForPinboardEmbed}${defaultParamsPost}#/${path}`);
});
test('navigateToPage with noReload should trigger the appropriate event', async () => {
(0, test_utils_1.mockMessageChannel)();
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
frameParams: {
width: '100%',
height: '100%',
},
});
await appEmbed.render();
const iframe = (0, test_utils_1.getIFrameEl)();
iframe.contentWindow.postMessage = jest.fn();
appEmbed.navigateToPage(path, true);
expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(expect.objectContaining({
type: types_1.HostEvent.Navigate,
data: path,
}), `http://${thoughtSpotHost}`, expect.anything());
appEmbed.navigateToPage(-1, true);
expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(expect.objectContaining({
type: types_1.HostEvent.Navigate,
data: -1,
}), `http://${thoughtSpotHost}`, expect.anything());
});
test('Do not allow number path without noReload in navigateToPage', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
frameParams: {
width: '100%',
height: '100%',
},
});
await appEmbed.render();
spyOn(logger_1.logger, 'warn');
appEmbed.navigateToPage(-1);
expect(logger_1.logger.warn).toHaveBeenCalledWith('Path can only by a string when triggered without noReload');
});
test('navigateToPage function use before render', async () => {
spyOn(logger_1.logger, 'log');
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
frameParams: {
width: '100%',
height: '100%',
},
});
appEmbed.navigateToPage(path);
await appEmbed.render();
expect(logger_1.logger.log).toHaveBeenCalledWith('Please call render before invoking this method');
});
});
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 appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: true,
lazyLoadingForFullHeight: true,
lazyLoadingMargin: '100px 0px',
});
await appEmbed.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 () => {
// Mock the iframe element first
mockIFrame.getBoundingClientRect = jest.fn().mockReturnValue({
top: 100,
left: 150,
bottom: 600,
right: 800,
width: 650,
height: 500,
});
Object.defineProperty(mockIFrame, 'scrollHeight', { value: 500 });
// Mock the event handlers
const onSpy = jest.spyOn(app_1.AppEmbed.prototype, 'on').mockImplementation((event, callback) => {
return null;
});
jest.spyOn(ts_embed_1.TsEmbed.prototype, 'getIframeCenter').mockReturnValue({});
jest.spyOn(ts_embed_1.TsEmbed.prototype, 'setIFrameHeight').mockReturnValue({});
// Create the AppEmbed instance
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: true,
lazyLoadingForFullHeight: true,
});
// Set the iframe before render
appEmbed.iFrame = mockIFrame;
// Add the iframe to the DOM
const rootEl = (0, test_utils_1.getRootEl)();
rootEl.appendChild(mockIFrame);
// Wait for render to complete
await appEmbed.render();
// Wait for iframe initialization and URL parameters to be set
await (0, test_utils_1.executeAfterWait)(() => {
const iframeSrc = appEmbed.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 appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: false,
lazyLoadingForFullHeight: true,
});
// Wait for render to complete
await appEmbed.render();
// Wait for iframe initialization and URL parameters to be set
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); // 100ms wait time to ensure iframe src is set
});
test('should not set isLazyLoadingForEmbedEnabled when fullHeight is true but lazyLoadingForFullHeight is false', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: true,
lazyLoadingForFullHeight: false,
});
// Wait for render to complete
await appEmbed.render();
// Wait for iframe initialization and URL parameters to be set
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); // 100ms wait time to ensure iframe src is set
});
test('should register RequestFullHeightLazyLoadData event handler when fullHeight is enabled', async () => {
const onSpy = jest.spyOn(app_1.AppEmbed.prototype, 'on');
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: true,
});
await appEmbed.render();
expect(onSpy).toHaveBeenCalledWith(types_1.EmbedEvent.RequestVisibleEmbedCoordinates, expect.any(Function));
onSpy.mockRestore();
});
test('should send correct visible data when RequestFullHeightLazyLoadData is triggered', async () => {
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: true,
lazyLoadingForFullHeight: true,
});
const mockTrigger = jest.spyOn(appEmbed, 'trigger');
await appEmbed.render();
// Trigger the lazy load data calculation
appEmbed.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 () => {
// Mock iframe partially clipped from top and left
mockIFrame.getBoundingClientRect = jest.fn().mockReturnValue({
top: -50,
left: -30,
bottom: 700,
right: 1024,
width: 1054,
height: 750,
});
const appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: true,
lazyLoadingForFullHeight: true,
});
const mockTrigger = jest.spyOn(appEmbed, 'trigger');
await appEmbed.render();
// Trigger the lazy load data calculation
appEmbed.sendFullHeightLazyLoadData();
expect(mockTrigger).toHaveBeenCalledWith(types_1.HostEvent.VisibleEmbedCoordinates, {
top: 50,
height: 700,
left: 30,
width: 1024, // visible width (from 0 to 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 appEmbed = new app_1.AppEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: true,
lazyLoadingForFullHeight: true,
});
await appEmbed.render();
// Wait for the post-render events to be registered
await (0, test_utils_1.executeAfterWait)(() => {
expect(addEventListenerSpy).toHaveBe