@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
190 lines • 9.77 kB
JavaScript
;
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 auth = tslib_1.__importStar(require("../auth"));
const defaultViewConfig = {
frameParams: {
width: 1280,
height: 720,
},
};
const pinboardId = 'eca215d4-0d2c-4a55-90e3-d81ef6848ae0';
const vizId = '6e73f724-660e-11eb-ae93-0242ac130002';
const thoughtSpotHost = 'tshost';
const prefixParams = '&isLiveboardEmbed=true';
const prefixParamsVizEmbed = '&isLiveboardEmbed=true&isVizEmbed=true';
beforeAll(() => {
(0, index_1.init)({
thoughtSpotHost,
authType: types_1.AuthType.None,
});
jest.spyOn(auth, 'postLoginService').mockReturnValue(true);
});
describe('Pinboard/viz embed tests', () => {
beforeEach(() => {
document.body.innerHTML = (0, test_utils_1.getDocumentBody)();
});
test('should render pinboard', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
pinboardId,
});
pinboardEmbed.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/${pinboardId}`);
});
});
test('should set disabled actions', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
disabledActions: [types_1.Action.DownloadAsCsv, types_1.Action.DownloadAsPdf, types_1.Action.DownloadAsXlsx],
disabledActionReason: 'Action denied',
...defaultViewConfig,
pinboardId,
});
pinboardEmbed.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/${pinboardId}`);
});
});
test('should set hidden actions', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
hiddenActions: [types_1.Action.DownloadAsCsv, types_1.Action.DownloadAsPdf, types_1.Action.DownloadAsXlsx],
...defaultViewConfig,
pinboardId,
});
pinboardEmbed.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/${pinboardId}`);
});
});
test('should set visible actions', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
visibleActions: [types_1.Action.DownloadAsCsv, types_1.Action.DownloadAsPdf, types_1.Action.DownloadAsXlsx],
...defaultViewConfig,
pinboardId,
});
pinboardEmbed.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/${pinboardId}`);
});
});
test('should set visible actions as empty array', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
visibleActions: [],
...defaultViewConfig,
pinboardId,
});
pinboardEmbed.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/${pinboardId}`);
});
});
test('should enable viz transformations true', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
enableVizTransformations: true,
...defaultViewConfig,
pinboardId,
});
pinboardEmbed.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/${pinboardId}`);
});
});
test('should disable viz transformations when enableVizTransformations false', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
enableVizTransformations: false,
...defaultViewConfig,
pinboardId,
});
pinboardEmbed.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/${pinboardId}`);
});
});
test('should render viz', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
pinboardId,
vizId,
});
pinboardEmbed.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/${pinboardId}/${vizId}`);
});
});
test('should apply runtime filters', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
pinboardId,
vizId,
runtimeFilters: [
{
columnName: 'sales',
operator: types_1.RuntimeFilterOp.EQ,
values: [1000],
},
],
excludeRuntimeFiltersfromURL: false,
});
pinboardEmbed.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/${pinboardId}/${vizId}`);
});
});
test('should not append runtime filters in URL if excludeRuntimeFiltersfromURL is true', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
pinboardId,
vizId,
runtimeFilters: [
{
columnName: 'sales',
operator: types_1.RuntimeFilterOp.EQ,
values: [1000],
},
],
excludeRuntimeFiltersfromURL: true,
});
pinboardEmbed.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/${pinboardId}/${vizId}`);
});
});
test('should append runtime filters in URL if excludeRuntimeFiltersfromURL is undefined', async () => {
const liveboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
pinboardId,
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/${pinboardId}/${vizId}`);
});
});
test('should register event handler to adjust iframe height', async () => {
const pinboardEmbed = new liveboard_1.PinboardEmbed((0, test_utils_1.getRootEl)(), {
...defaultViewConfig,
fullHeight: true,
pinboardId,
vizId,
});
const onSpy = jest.spyOn(pinboardEmbed, 'on');
pinboardEmbed.render();
(0, test_utils_1.executeAfterWait)(() => {
expect(onSpy).toHaveBeenCalledWith(types_1.EmbedEvent.EmbedHeight, expect.anything());
});
});
});
//# sourceMappingURL=pinboard.spec.js.map