UNPKG

@thoughtspot/visual-embed-sdk

Version:
78 lines 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = require("./util"); const types_1 = require("../types"); describe('React util functions', () => { describe('getViewPropsAndListeners', () => { test('should return empty viewConfig and listeners for empty props', () => { const props = {}; const result = (0, util_1.getViewPropsAndListeners)(props); expect(result.viewConfig).toEqual({}); expect(result.listeners).toEqual({}); }); test('should separate view config properties from props', () => { const props = { frameParams: { width: 100, height: 200 }, showLiveboardTitle: true, liveboardId: 'test-liveboard-id', vizId: 'test-viz-id', className: 'test-class', style: { color: 'red' }, }; const result = (0, util_1.getViewPropsAndListeners)(props); expect(result.viewConfig).toEqual({ frameParams: { width: 100, height: 200 }, showLiveboardTitle: true, liveboardId: 'test-liveboard-id', vizId: 'test-viz-id', className: 'test-class', style: { color: 'red' }, }); expect(result.listeners).toEqual({}); }); test('should separate event handlers from props', () => { const onInit = jest.fn(); const onLoad = jest.fn(); const onData = jest.fn(); const props = { onInit, onLoad, onData, }; const result = (0, util_1.getViewPropsAndListeners)(props); expect(result.viewConfig).toEqual({}); expect(result.listeners).toEqual({ [types_1.EmbedEvent.Init]: onInit, [types_1.EmbedEvent.Load]: onLoad, [types_1.EmbedEvent.Data]: onData, }); }); test('should handle both view config and event handlers', () => { const onInit = jest.fn(); const onAuthInit = jest.fn(); const onQueryChanged = jest.fn(); const props = { liveboardId: 'test-liveboard-id', showLiveboardTitle: false, frameParams: { height: 500 }, onInit, onAuthInit, onQueryChanged, className: 'embed-container', }; const result = (0, util_1.getViewPropsAndListeners)(props); expect(result.viewConfig).toEqual({ liveboardId: 'test-liveboard-id', showLiveboardTitle: false, frameParams: { height: 500 }, className: 'embed-container', }); expect(result.listeners).toEqual({ [types_1.EmbedEvent.Init]: onInit, [types_1.EmbedEvent.AuthInit]: onAuthInit, [types_1.EmbedEvent.QueryChanged]: onQueryChanged, }); }); }); }); //# sourceMappingURL=util.spec.js.map