@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
76 lines • 3.02 kB
JavaScript
import { getViewPropsAndListeners } from './util';
import { EmbedEvent } from '../types';
describe('React util functions', () => {
describe('getViewPropsAndListeners', () => {
test('should return empty viewConfig and listeners for empty props', () => {
const props = {};
const result = 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 = 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 = getViewPropsAndListeners(props);
expect(result.viewConfig).toEqual({});
expect(result.listeners).toEqual({
[EmbedEvent.Init]: onInit,
[EmbedEvent.Load]: onLoad,
[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 = getViewPropsAndListeners(props);
expect(result.viewConfig).toEqual({
liveboardId: 'test-liveboard-id',
showLiveboardTitle: false,
frameParams: { height: 500 },
className: 'embed-container',
});
expect(result.listeners).toEqual({
[EmbedEvent.Init]: onInit,
[EmbedEvent.AuthInit]: onAuthInit,
[EmbedEvent.QueryChanged]: onQueryChanged,
});
});
});
});
//# sourceMappingURL=util.spec.js.map