@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
133 lines • 7.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const conversation_1 = require("./conversation");
const authInstance = tslib_1.__importStar(require("../auth"));
const index_1 = require("../index");
const types_1 = require("../types");
const test_utils_1 = require("../test/test-utils");
const errors_1 = require("../errors");
const thoughtSpotHost = 'tshost';
beforeAll(() => {
(0, index_1.init)({
thoughtSpotHost,
authType: types_1.AuthType.None,
});
jest.spyOn(authInstance, 'postLoginService').mockImplementation(() => Promise.resolve({}));
spyOn(window, 'alert');
document.body.innerHTML = (0, test_utils_1.getDocumentBody)();
});
describe('ConversationEmbed', () => {
it('should render the conversation embed', async () => {
const viewConfig = {
worksheetId: 'worksheetId',
searchOptions: {
searchQuery: 'searchQuery',
},
};
const conversationEmbed = new conversation_1.SpotterEmbed((0, test_utils_1.getRootEl)(), viewConfig);
await conversationEmbed.render();
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/v2/?${test_utils_1.defaultParamsWithoutHiddenActions}&isSpotterExperienceEnabled=true#/embed/insights/conv-assist?worksheet=worksheetId&query=searchQuery`);
});
it('should render the conversation embed with worksheets disabled', async () => {
const viewConfig = {
worksheetId: 'worksheetId',
searchOptions: {
searchQuery: 'searchQuery',
},
disableSourceSelection: true,
};
const conversationEmbed = new conversation_1.SpotterEmbed((0, test_utils_1.getRootEl)(), viewConfig);
await conversationEmbed.render();
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/v2/?${test_utils_1.defaultParamsWithoutHiddenActions}&isSpotterExperienceEnabled=true&disableSourceSelection=true#/embed/insights/conv-assist?worksheet=worksheetId&query=searchQuery`);
});
it('should render the conversation embed with spotter limitations text if flag is set', async () => {
const viewConfig = {
worksheetId: 'worksheetId',
searchOptions: {
searchQuery: 'searchQuery',
},
showSpotterLimitations: true,
};
const conversationEmbed = new conversation_1.SpotterEmbed((0, test_utils_1.getRootEl)(), viewConfig);
await conversationEmbed.render();
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/v2/?${test_utils_1.defaultParamsWithoutHiddenActions}&isSpotterExperienceEnabled=true&showSpotterLimitations=true#/embed/insights/conv-assist?worksheet=worksheetId&query=searchQuery`);
});
it('should render the conversation embed with sample questions hidden', async () => {
const viewConfig = {
worksheetId: 'worksheetId',
searchOptions: {
searchQuery: 'searchQuery',
},
hideSampleQuestions: true,
};
const conversationEmbed = new conversation_1.SpotterEmbed((0, test_utils_1.getRootEl)(), viewConfig);
await conversationEmbed.render();
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/v2/?${test_utils_1.defaultParamsWithoutHiddenActions}&isSpotterExperienceEnabled=true&hideSampleQuestions=true#/embed/insights/conv-assist?worksheet=worksheetId&query=searchQuery`);
});
it('should render the conversation embed with worksheets hidden', async () => {
const viewConfig = {
worksheetId: 'worksheetId',
searchOptions: {
searchQuery: 'searchQuery',
},
hideSourceSelection: true,
};
const conversationEmbed = new conversation_1.SpotterEmbed((0, test_utils_1.getRootEl)(), viewConfig);
await conversationEmbed.render();
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/v2/?${test_utils_1.defaultParamsWithoutHiddenActions}&isSpotterExperienceEnabled=true&hideSourceSelection=true#/embed/insights/conv-assist?worksheet=worksheetId&query=searchQuery`);
});
it('should handle error when worksheetId is not provided', async () => {
const viewConfig = {
worksheetId: '',
searchOptions: {
searchQuery: 'searchQuery',
},
};
const conversationEmbed = new conversation_1.SpotterEmbed((0, test_utils_1.getRootEl)(), viewConfig);
conversationEmbed.handleError = jest.fn();
await conversationEmbed.render();
expect(conversationEmbed.handleError).toHaveBeenCalledWith(errors_1.ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND);
});
it('should render the conversation embed if data panel v2 flag is true', async () => {
const viewConfig = {
worksheetId: 'worksheetId',
searchOptions: {
searchQuery: 'searchQuery',
},
dataPanelV2: true,
};
const conversationEmbed = new conversation_1.SpotterEmbed((0, test_utils_1.getRootEl)(), viewConfig);
await conversationEmbed.render();
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/v2/?${test_utils_1.defaultParamsWithoutHiddenActions}&isSpotterExperienceEnabled=true&enableDataPanelV2=true#/embed/insights/conv-assist?worksheet=worksheetId&query=searchQuery`);
});
it('should render the conversation embed with hidden actions of InConversationTraining if set', async () => {
const viewConfig = {
worksheetId: 'worksheetId',
searchOptions: {
searchQuery: 'searchQuery',
},
dataPanelV2: true,
hiddenActions: [index_1.Action.InConversationTraining]
};
const conversationEmbed = new conversation_1.SpotterEmbed((0, test_utils_1.getRootEl)(), viewConfig);
await conversationEmbed.render();
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/v2/?${test_utils_1.defaultParamsWithoutHiddenActions}&hideAction=[%22${index_1.Action.ReportError}%22,%22${index_1.Action.InConversationTraining}%22]&isSpotterExperienceEnabled=true&enableDataPanelV2=true#/embed/insights/conv-assist?worksheet=worksheetId&query=searchQuery`);
});
it('should render the conversation embed with disabled actions of InConversationTraining if set', async () => {
const disabledReason = 'testing disabled reason';
const viewConfig = {
worksheetId: 'worksheetId',
searchOptions: {
searchQuery: 'searchQuery',
},
dataPanelV2: true,
disabledActions: [index_1.Action.InConversationTraining],
disabledActionReason: disabledReason,
};
const conversationEmbed = new conversation_1.SpotterEmbed((0, test_utils_1.getRootEl)(), viewConfig);
await conversationEmbed.render();
(0, test_utils_1.expectUrlMatchesWithParams)((0, test_utils_1.getIFrameSrc)(), `http://${thoughtSpotHost}/v2/?${test_utils_1.defaultParamsWithoutHiddenActions}&${types_1.Param.DisableActions}=[%22${index_1.Action.InConversationTraining}%22]&${types_1.Param.DisableActionReason}=${disabledReason}&isSpotterExperienceEnabled=true&enableDataPanelV2=true#/embed/insights/conv-assist?worksheet=worksheetId&query=searchQuery`);
});
});
//# sourceMappingURL=conversation.spec.js.map