UNPKG

@thoughtspot/visual-embed-sdk

Version:
151 lines 9.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const sage_1 = require("./sage"); const index_1 = require("../index"); const types_1 = require("../types"); const test_utils_1 = require("../test/test-utils"); const authInstance = tslib_1.__importStar(require("../auth")); const defaultConfig = { disableWorksheetChange: false, hideWorksheetSelector: false, hideSageAnswerHeader: false, hideAutocompleteSuggestions: false, hideSampleQuestions: false, isProductTour: false, dataPanelV2: true, }; const thoughtSpotHost = 'tshost'; beforeAll(() => { (0, index_1.init)({ thoughtSpotHost, authType: types_1.AuthType.None, }); spyOn(window, 'alert'); jest.spyOn(authInstance, 'postLoginService').mockResolvedValue(true); }); describe('Sage embed tests', () => { beforeEach(() => { document.body.innerHTML = (0, test_utils_1.getDocumentBody)(); }); test('should render sage', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), defaultConfig); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=false&isProductTour=false&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka`); }); }); test('should render sage with product tour flag set', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, isProductTour: true }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=false&isProductTour=true&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka`); }); }); test('should render sage with disable worksheet change flag', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, disableWorksheetChange: true, }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=true&hideWorksheetSelector=false&hideEurekaSuggestions=false&isProductTour=false&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka`); }); }); test('should render sage with hide worksheet selector flag', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, hideWorksheetSelector: true, }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=true&hideEurekaSuggestions=false&isProductTour=false&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka`); }); }); test('should render sage with hide Sage Answer Header flag', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, hideSageAnswerHeader: true, }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=false&isProductTour=false&hideSageAnswerHeader=true&hideAction=%5B%22reportError%22%5D#/embed/eureka`); }); }); test('should render sage with hide Autocomplete suggestions flag', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, hideAutocompleteSuggestions: true, }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=true&isProductTour=false&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka`); }); }); test('should render sage with deprecated showObjectSuggestions flag', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { showObjectSuggestions: true, }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=false&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=false&isProductTour=false&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka`); }); }); test('embed url include pre-seed dataSource without populating searchOptions', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, dataSource: 'worksheet-id', }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=false&isProductTour=false&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka?worksheet=worksheet-id`); }); }); test('embed url include pre-seed dataSource and query', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, dataSource: 'worksheet-id', searchOptions: { searchQuery: 'test query', // also tests for query with spaces }, }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=false&isProductTour=false&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka?worksheet=worksheet-id&query=test%20query`); }); }); test('embed url include pre-seed execute flag with query', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, searchOptions: { searchQuery: 'test-query', executeSearch: true, }, }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=false&hideAction=%5B%22reportError%22%5D#/embed/eureka?executeSearch=true&query=test-query`); }); }); test('should set enableDataPanelV2 to true if data panel v2 flag is true', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, dataPanelV2: true, }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=true&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=false&isProductTour=false&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka`); }); }); test('should set enableDataPanelV2 to false if data panel v2 flag is false', async () => { const sageEmbed = new sage_1.SageEmbed((0, test_utils_1.getRootEl)(), { ...defaultConfig, dataPanelV2: false, }); await sageEmbed.render(); await (0, test_utils_1.executeAfterWait)(() => { (0, test_utils_1.expectUrlMatch)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/?embedApp=true&enableDataPanelV2=false&isSageEmbed=true&disableWorksheetChange=false&hideWorksheetSelector=false&hideEurekaSuggestions=false&isProductTour=false&hideSageAnswerHeader=false&hideAction=%5B%22reportError%22%5D#/embed/eureka`); }); }); }); //# sourceMappingURL=sage.spec.js.map