UNPKG

@thoughtspot/visual-embed-sdk

Version:
105 lines 5.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const spotter_utils_1 = require("./spotter-utils"); const types_1 = require("../types"); const errors_1 = require("../errors"); describe('resolveEnablePastConversationsSidebar', () => { it('prefers spotterSidebarConfig value over standalone', () => { expect((0, spotter_utils_1.resolveEnablePastConversationsSidebar)({ spotterSidebarConfigValue: true, standaloneValue: false })).toBe(true); expect((0, spotter_utils_1.resolveEnablePastConversationsSidebar)({ spotterSidebarConfigValue: false, standaloneValue: true })).toBe(false); }); it('falls back to standalone when spotterSidebarConfig value is absent', () => { expect((0, spotter_utils_1.resolveEnablePastConversationsSidebar)({ standaloneValue: true })).toBe(true); }); it('returns undefined when both are absent', () => { expect((0, spotter_utils_1.resolveEnablePastConversationsSidebar)({})).toBeUndefined(); }); }); describe('buildSpotterSidebarAppInitData', () => { const base = { type: 'APP_INIT' }; const noopError = jest.fn(); it('returns base unchanged when no sidebar config or standalone flag', () => { const result = (0, spotter_utils_1.buildSpotterSidebarAppInitData)(base, {}, noopError); expect(result).toBe(base); }); it('nests spotterSidebarConfig under embedParams', () => { var _a; const result = (0, spotter_utils_1.buildSpotterSidebarAppInitData)(base, { spotterSidebarConfig: { enablePastConversationsSidebar: true, spotterSidebarTitle: 'Chats' }, }, noopError); expect((_a = result.embedParams) === null || _a === void 0 ? void 0 : _a.spotterSidebarConfig).toEqual({ enablePastConversationsSidebar: true, spotterSidebarTitle: 'Chats', }); }); it('promotes standalone flag into spotterSidebarConfig.enablePastConversationsSidebar', () => { var _a, _b; const result = (0, spotter_utils_1.buildSpotterSidebarAppInitData)(base, { enablePastConversationsSidebar: true }, noopError); expect((_b = (_a = result.embedParams) === null || _a === void 0 ? void 0 : _a.spotterSidebarConfig) === null || _b === void 0 ? void 0 : _b.enablePastConversationsSidebar).toBe(true); }); it('calls handleError and strips spotterDocumentationUrl when invalid', () => { var _a, _b; const handleError = jest.fn(); const result = (0, spotter_utils_1.buildSpotterSidebarAppInitData)(base, { spotterSidebarConfig: { spotterDocumentationUrl: 'not-a-url' }, }, handleError); expect(handleError).toHaveBeenCalledWith(expect.objectContaining({ errorType: types_1.ErrorDetailsTypes.VALIDATION_ERROR, message: errors_1.ERROR_MESSAGE.INVALID_SPOTTER_DOCUMENTATION_URL, code: types_1.EmbedErrorCodes.INVALID_URL, })); expect((_b = (_a = result.embedParams) === null || _a === void 0 ? void 0 : _a.spotterSidebarConfig) === null || _b === void 0 ? void 0 : _b.spotterDocumentationUrl).toBeUndefined(); }); it('returns base with visualOverridesParams when only visualOverrides is provided', () => { const visualOverrides = { chart: { legend: { show: true, position: 'bottom' }, }, }; const result = (0, spotter_utils_1.buildSpotterSidebarAppInitData)(base, { visualOverrides, }, noopError); expect(result).toEqual({ ...base, embedParams: { visualOverridesParams: visualOverrides }, }); }); it('includes visualOverridesParams with spotterSidebarConfig', () => { var _a, _b, _c; const visualOverrides = { table: { display: { tableTheme: 'ZEBRA' }, }, }; const result = (0, spotter_utils_1.buildSpotterSidebarAppInitData)(base, { spotterSidebarConfig: { enablePastConversationsSidebar: true }, visualOverrides, }, noopError); expect((_b = (_a = result.embedParams) === null || _a === void 0 ? void 0 : _a.spotterSidebarConfig) === null || _b === void 0 ? void 0 : _b.enablePastConversationsSidebar).toBe(true); expect((_c = result.embedParams) === null || _c === void 0 ? void 0 : _c.visualOverridesParams).toEqual(visualOverrides); }); it('includes visualOverridesParams with standalone enablePastConversationsSidebar flag', () => { var _a, _b, _c; const visualOverrides = { chart: { legend: { show: false }, }, }; const result = (0, spotter_utils_1.buildSpotterSidebarAppInitData)(base, { enablePastConversationsSidebar: true, visualOverrides, }, noopError); expect((_b = (_a = result.embedParams) === null || _a === void 0 ? void 0 : _a.spotterSidebarConfig) === null || _b === void 0 ? void 0 : _b.enablePastConversationsSidebar).toBe(true); expect((_c = result.embedParams) === null || _c === void 0 ? void 0 : _c.visualOverridesParams).toEqual(visualOverrides); }); it('does not include visualOverridesParams when it is undefined', () => { var _a, _b, _c; const result = (0, spotter_utils_1.buildSpotterSidebarAppInitData)(base, { spotterSidebarConfig: { enablePastConversationsSidebar: true }, visualOverrides: undefined, }, noopError); expect((_a = result.embedParams) === null || _a === void 0 ? void 0 : _a.visualOverridesParams).toBeUndefined(); expect((_c = (_b = result.embedParams) === null || _b === void 0 ? void 0 : _b.spotterSidebarConfig) === null || _c === void 0 ? void 0 : _c.enablePastConversationsSidebar).toBe(true); }); }); //# sourceMappingURL=spotter-utils.spec.js.map