UNPKG

@thoughtspot/visual-embed-sdk

Version:
103 lines 5.62 kB
import { resolveEnablePastConversationsSidebar, buildSpotterSidebarAppInitData } from './spotter-utils'; import { ErrorDetailsTypes, EmbedErrorCodes } from '../types'; import { ERROR_MESSAGE } from '../errors'; describe('resolveEnablePastConversationsSidebar', () => { it('prefers spotterSidebarConfig value over standalone', () => { expect(resolveEnablePastConversationsSidebar({ spotterSidebarConfigValue: true, standaloneValue: false })).toBe(true); expect(resolveEnablePastConversationsSidebar({ spotterSidebarConfigValue: false, standaloneValue: true })).toBe(false); }); it('falls back to standalone when spotterSidebarConfig value is absent', () => { expect(resolveEnablePastConversationsSidebar({ standaloneValue: true })).toBe(true); }); it('returns undefined when both are absent', () => { expect(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 = buildSpotterSidebarAppInitData(base, {}, noopError); expect(result).toBe(base); }); it('nests spotterSidebarConfig under embedParams', () => { var _a; const result = 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 = 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 = buildSpotterSidebarAppInitData(base, { spotterSidebarConfig: { spotterDocumentationUrl: 'not-a-url' }, }, handleError); expect(handleError).toHaveBeenCalledWith(expect.objectContaining({ errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: ERROR_MESSAGE.INVALID_SPOTTER_DOCUMENTATION_URL, code: 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 = 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 = 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 = 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 = 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