@thoughtspot/ts-chart-sdk 0.0.1-alpha.8 → 0.0.2-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/main/custom-chart-context.d.ts +17 -3
- package/lib/main/custom-chart-context.d.ts.map +1 -1
- package/lib/main/custom-chart-context.js +138 -33
- package/lib/main/custom-chart-context.js.map +1 -1
- package/lib/main/custom-chart-context.spec.js +259 -164
- package/lib/main/custom-chart-context.spec.js.map +1 -1
- package/lib/main/post-message-event-bridge.d.ts +3 -3
- package/lib/main/post-message-event-bridge.d.ts.map +1 -1
- package/lib/main/post-message-event-bridge.js +24 -36
- package/lib/main/post-message-event-bridge.js.map +1 -1
- package/lib/main/post-message-event-bridge.spec.js +0 -2
- package/lib/main/post-message-event-bridge.spec.js.map +1 -1
- package/lib/main/util.d.ts +2 -0
- package/lib/main/util.d.ts.map +1 -0
- package/lib/main/util.js +9 -0
- package/lib/main/util.js.map +1 -0
- package/lib/react/use-custom-chart-context.spec.js +74 -119
- package/lib/react/use-custom-chart-context.spec.js.map +1 -1
- package/lib/types/chart-to-ts-event.types.d.ts +7 -1
- package/lib/types/chart-to-ts-event.types.d.ts.map +1 -1
- package/lib/types/chart-to-ts-event.types.js.map +1 -1
- package/lib/types/common.types.d.ts +2 -0
- package/lib/types/common.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.d.ts +26 -1
- package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.js +2 -0
- package/lib/types/ts-to-chart-event.types.js.map +1 -1
- package/package.json +5 -4
- package/src/main/custom-chart-context.spec.ts +330 -173
- package/src/main/custom-chart-context.ts +276 -39
- package/src/main/post-message-event-bridge.spec.ts +0 -3
- package/src/main/post-message-event-bridge.ts +36 -62
- package/src/main/util.ts +11 -0
- package/src/react/use-custom-chart-context.spec.tsx +84 -120
- package/src/types/chart-to-ts-event.types.ts +21 -1
- package/src/types/common.types.ts +15 -1
- package/src/types/ts-to-chart-event.types.ts +84 -0
- package/cjs/index.d.ts +0 -9
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -25
- package/cjs/index.js.map +0 -1
- package/cjs/main/custom-chart-context.d.ts +0 -40
- package/cjs/main/custom-chart-context.d.ts.map +0 -1
- package/cjs/main/custom-chart-context.js +0 -218
- package/cjs/main/custom-chart-context.js.map +0 -1
- package/cjs/main/custom-chart-context.spec.d.ts +0 -2
- package/cjs/main/custom-chart-context.spec.d.ts.map +0 -1
- package/cjs/main/custom-chart-context.spec.js +0 -448
- package/cjs/main/custom-chart-context.spec.js.map +0 -1
- package/cjs/main/post-message-event-bridge.d.ts +0 -6
- package/cjs/main/post-message-event-bridge.d.ts.map +0 -1
- package/cjs/main/post-message-event-bridge.js +0 -46
- package/cjs/main/post-message-event-bridge.js.map +0 -1
- package/cjs/main/post-message-event-bridge.spec.d.ts +0 -2
- package/cjs/main/post-message-event-bridge.spec.d.ts.map +0 -1
- package/cjs/main/post-message-event-bridge.spec.js +0 -124
- package/cjs/main/post-message-event-bridge.spec.js.map +0 -1
- package/cjs/react/custom-chart-context-service.d.ts +0 -33
- package/cjs/react/custom-chart-context-service.d.ts.map +0 -1
- package/cjs/react/custom-chart-context-service.js +0 -118
- package/cjs/react/custom-chart-context-service.js.map +0 -1
- package/cjs/react/custom-chart.context.d.ts +0 -26
- package/cjs/react/custom-chart.context.d.ts.map +0 -1
- package/cjs/react/custom-chart.context.js +0 -105
- package/cjs/react/custom-chart.context.js.map +0 -1
- package/cjs/react/custom-chart.spec.d.ts +0 -2
- package/cjs/react/custom-chart.spec.d.ts.map +0 -1
- package/cjs/react/custom-chart.spec.js +0 -72
- package/cjs/react/custom-chart.spec.js.map +0 -1
- package/cjs/react/mocks/custom-chart-context-mock.d.ts +0 -3
- package/cjs/react/mocks/custom-chart-context-mock.d.ts.map +0 -1
- package/cjs/react/mocks/custom-chart-context-mock.js +0 -100
- package/cjs/react/mocks/custom-chart-context-mock.js.map +0 -1
- package/cjs/react/use-custom-chart-context.d.ts +0 -4
- package/cjs/react/use-custom-chart-context.d.ts.map +0 -1
- package/cjs/react/use-custom-chart-context.js +0 -95
- package/cjs/react/use-custom-chart-context.js.map +0 -1
- package/cjs/react/use-custom-chart-context.spec.d.ts +0 -2
- package/cjs/react/use-custom-chart-context.spec.d.ts.map +0 -1
- package/cjs/react/use-custom-chart-context.spec.js +0 -391
- package/cjs/react/use-custom-chart-context.spec.js.map +0 -1
- package/cjs/react/use-custom-chart-context.util.d.ts +0 -6
- package/cjs/react/use-custom-chart-context.util.d.ts.map +0 -1
- package/cjs/react/use-custom-chart-context.util.js +0 -60
- package/cjs/react/use-custom-chart-context.util.js.map +0 -1
- package/cjs/react/use-custom-chart-types.d.ts +0 -23
- package/cjs/react/use-custom-chart-types.d.ts.map +0 -1
- package/cjs/react/use-custom-chart-types.js +0 -3
- package/cjs/react/use-custom-chart-types.js.map +0 -1
- package/cjs/test/test-utils.d.ts +0 -7
- package/cjs/test/test-utils.d.ts.map +0 -1
- package/cjs/test/test-utils.js +0 -14
- package/cjs/test/test-utils.js.map +0 -1
- package/cjs/types/answer-column.types.d.ts +0 -69
- package/cjs/types/answer-column.types.d.ts.map +0 -1
- package/cjs/types/answer-column.types.js +0 -59
- package/cjs/types/answer-column.types.js.map +0 -1
- package/cjs/types/chart-to-ts-event.types.d.ts +0 -92
- package/cjs/types/chart-to-ts-event.types.d.ts.map +0 -1
- package/cjs/types/chart-to-ts-event.types.js +0 -32
- package/cjs/types/chart-to-ts-event.types.js.map +0 -1
- package/cjs/types/common.types.d.ts +0 -50
- package/cjs/types/common.types.d.ts.map +0 -1
- package/cjs/types/common.types.js +0 -3
- package/cjs/types/common.types.js.map +0 -1
- package/cjs/types/configurator.types.d.ts +0 -15
- package/cjs/types/configurator.types.d.ts.map +0 -1
- package/cjs/types/configurator.types.js +0 -3
- package/cjs/types/configurator.types.js.map +0 -1
- package/cjs/types/ts-to-chart-event.types.d.ts +0 -69
- package/cjs/types/ts-to-chart-event.types.d.ts.map +0 -1
- package/cjs/types/ts-to-chart-event.types.js +0 -16
- package/cjs/types/ts-to-chart-event.types.js.map +0 -1
- package/cjs/types/visual-prop.types.d.ts +0 -73
- package/cjs/types/visual-prop.types.d.ts.map +0 -1
- package/cjs/types/visual-prop.types.js +0 -3
- package/cjs/types/visual-prop.types.js.map +0 -1
- package/dist/ts-chart-sdk.d.ts +0 -312
- package/lib/dist/ts-chart-sdk.d.ts +0 -312
- package/lib/react/custom-chart-context-service.d.ts +0 -33
- package/lib/react/custom-chart-context-service.d.ts.map +0 -1
- package/lib/react/custom-chart-context-service.js +0 -91
- package/lib/react/custom-chart-context-service.js.map +0 -1
- package/lib/react/custom-chart.context.d.ts +0 -26
- package/lib/react/custom-chart.context.d.ts.map +0 -1
- package/lib/react/custom-chart.context.js +0 -78
- package/lib/react/custom-chart.context.js.map +0 -1
- package/lib/react/custom-chart.spec.d.ts +0 -2
- package/lib/react/custom-chart.spec.d.ts.map +0 -1
- package/lib/react/custom-chart.spec.js +0 -67
- package/lib/react/custom-chart.spec.js.map +0 -1
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
* @author Chetan Agrawal <chetan.agrawal@thoughtspot.com>
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import _ from 'lodash';
|
|
7
8
|
import { mockInitializeContextPayload } from '../test/test-utils';
|
|
8
9
|
import { ChartToTSEvent, ErrorType } from '../types/chart-to-ts-event.types';
|
|
9
10
|
import { TSToChartEvent } from '../types/ts-to-chart-event.types';
|
|
10
11
|
import { CustomChartContext, getChartContext } from './custom-chart-context';
|
|
11
12
|
import * as PostMessageEventBridge from './post-message-event-bridge';
|
|
12
13
|
|
|
13
|
-
jest.mock('./post-message-event-bridge');
|
|
14
|
+
// jest.mock('./post-message-event-bridge');
|
|
14
15
|
|
|
15
16
|
jest.spyOn(console, 'log').mockImplementation(() => {
|
|
16
17
|
// do nothing.
|
|
@@ -38,6 +39,7 @@ describe('CustomChartContext', () => {
|
|
|
38
39
|
|
|
39
40
|
mockInitMessage.mockImplementation((fn: any) => {
|
|
40
41
|
eventProcessor = fn;
|
|
42
|
+
return () => null;
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
mockPostMessageToHost.mockImplementation(() => {
|
|
@@ -84,35 +86,29 @@ describe('CustomChartContext', () => {
|
|
|
84
86
|
const promise = customChartContext.initialize();
|
|
85
87
|
|
|
86
88
|
// Check that the hasInitializedPromise has resolved
|
|
87
|
-
|
|
88
|
-
eventProcessor({
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
eventType: TSToChartEvent.Initialize,
|
|
92
|
-
source: 'ts-host-app',
|
|
93
|
-
},
|
|
94
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
89
|
+
|
|
90
|
+
const initResp = await eventProcessor({
|
|
91
|
+
payload: mockInitializeContextPayload,
|
|
92
|
+
eventType: TSToChartEvent.Initialize,
|
|
95
93
|
});
|
|
96
94
|
|
|
97
95
|
eventProcessor({
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
eventType: TSToChartEvent.InitializeComplete,
|
|
101
|
-
source: 'ts-host-app',
|
|
102
|
-
},
|
|
103
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
96
|
+
payload: {},
|
|
97
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
104
98
|
});
|
|
105
99
|
|
|
106
100
|
await expect(promise).resolves.toBeUndefined();
|
|
107
|
-
expect(mockPostMessage).toHaveBeenCalledTimes(2);
|
|
108
101
|
|
|
109
|
-
expect(
|
|
102
|
+
expect(initResp).toEqual({
|
|
110
103
|
isConfigValid: false,
|
|
111
104
|
defaultChartConfig: undefined,
|
|
112
105
|
chartConfigEditorDefinition: undefined,
|
|
113
106
|
visualPropEditorDefinition: undefined,
|
|
107
|
+
allowedConfigurations: {
|
|
108
|
+
allowColumnNumberFormatting: false,
|
|
109
|
+
allowColumnConditionalFormatting: false,
|
|
110
|
+
},
|
|
114
111
|
});
|
|
115
|
-
expect(mockPostMessage).toHaveBeenCalled();
|
|
116
112
|
expect(mockPostMessageToHost).not.toHaveBeenCalled();
|
|
117
113
|
});
|
|
118
114
|
|
|
@@ -121,23 +117,14 @@ describe('CustomChartContext', () => {
|
|
|
121
117
|
const promise = customChartContext.initialize();
|
|
122
118
|
|
|
123
119
|
// Check that the hasInitializedPromise has resolved
|
|
124
|
-
const mockPostMessage = jest.fn();
|
|
125
120
|
eventProcessor({
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
eventType: TSToChartEvent.Initialize,
|
|
129
|
-
source: 'ts-host-app',
|
|
130
|
-
},
|
|
131
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
121
|
+
payload: mockInitializeContextPayload,
|
|
122
|
+
eventType: TSToChartEvent.Initialize,
|
|
132
123
|
});
|
|
133
124
|
|
|
134
125
|
eventProcessor({
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
eventType: TSToChartEvent.InitializeComplete,
|
|
138
|
-
source: 'ts-host-app',
|
|
139
|
-
},
|
|
140
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
126
|
+
payload: {},
|
|
127
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
141
128
|
});
|
|
142
129
|
|
|
143
130
|
await expect(promise).resolves.toBeUndefined();
|
|
@@ -183,126 +170,75 @@ describe('CustomChartContext', () => {
|
|
|
183
170
|
eventProcessor = null;
|
|
184
171
|
});
|
|
185
172
|
|
|
186
|
-
test('
|
|
187
|
-
expect(mockInitMessage).toHaveBeenCalled();
|
|
188
|
-
|
|
189
|
-
// mock the event trigger for ChartConfigValidate
|
|
190
|
-
const mockPostMessage = jest.fn();
|
|
191
|
-
eventProcessor({
|
|
192
|
-
data: {
|
|
193
|
-
payload: mockInitializeContextPayload,
|
|
194
|
-
eventType: TSToChartEvent.ChartConfigValidate,
|
|
195
|
-
source: 'incorrect-source',
|
|
196
|
-
},
|
|
197
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
198
|
-
});
|
|
199
|
-
// Check that the event listener was added to the eventListeners
|
|
200
|
-
// object
|
|
201
|
-
expect(mockPostMessage).not.toHaveBeenCalled();
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
test('default internal function testing', () => {
|
|
173
|
+
test('default internal function testing', async () => {
|
|
205
174
|
expect(mockInitMessage).toHaveBeenCalled();
|
|
206
175
|
|
|
207
176
|
// mock the event trigger for ChartConfigValidate
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
payload: mockInitializeContextPayload,
|
|
212
|
-
eventType: TSToChartEvent.ChartConfigValidate,
|
|
213
|
-
source: 'ts-host-app',
|
|
214
|
-
},
|
|
215
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
177
|
+
const validateChartConfigResp = await eventProcessor({
|
|
178
|
+
payload: mockInitializeContextPayload,
|
|
179
|
+
eventType: TSToChartEvent.ChartConfigValidate,
|
|
216
180
|
});
|
|
217
181
|
// Check that the response was received
|
|
218
|
-
expect(
|
|
182
|
+
expect(validateChartConfigResp).toEqual({
|
|
219
183
|
isValid: true,
|
|
220
184
|
});
|
|
221
|
-
mockPostMessage.mockReset();
|
|
222
185
|
|
|
223
186
|
// mock the event trigger for VisualPropsValidate
|
|
224
|
-
eventProcessor({
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
eventType: TSToChartEvent.VisualPropsValidate,
|
|
228
|
-
source: 'ts-host-app',
|
|
229
|
-
},
|
|
230
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
187
|
+
const validateVisualPropsResp = await eventProcessor({
|
|
188
|
+
payload: mockInitializeContextPayload,
|
|
189
|
+
eventType: TSToChartEvent.VisualPropsValidate,
|
|
231
190
|
});
|
|
232
191
|
// Check that the response was received
|
|
233
|
-
expect(
|
|
192
|
+
expect(validateVisualPropsResp).toEqual({
|
|
234
193
|
isValid: true,
|
|
235
194
|
});
|
|
236
195
|
|
|
237
|
-
mockPostMessage.mockReset();
|
|
238
|
-
|
|
239
196
|
// mock the event trigger for TriggerRenderChart
|
|
240
|
-
eventProcessor({
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
eventType: TSToChartEvent.TriggerRenderChart,
|
|
244
|
-
source: 'ts-host-app',
|
|
245
|
-
},
|
|
246
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
197
|
+
const renderResp = await eventProcessor({
|
|
198
|
+
payload: mockInitializeContextPayload,
|
|
199
|
+
eventType: TSToChartEvent.TriggerRenderChart,
|
|
247
200
|
});
|
|
248
201
|
// Check that the response was received
|
|
249
|
-
expect(mockPostMessage).toHaveBeenCalledWith({});
|
|
250
202
|
expect(renderChart).toHaveBeenCalled();
|
|
251
203
|
|
|
252
|
-
mockPostMessage.mockReset();
|
|
253
|
-
|
|
254
204
|
// mock the event trigger for getQueriesFromChartConfig
|
|
255
205
|
eventProcessor({
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
eventType: TSToChartEvent.GetDataQuery,
|
|
259
|
-
source: 'ts-host-app',
|
|
260
|
-
},
|
|
261
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
206
|
+
payload: mockInitializeContextPayload,
|
|
207
|
+
eventType: TSToChartEvent.GetDataQuery,
|
|
262
208
|
});
|
|
263
|
-
|
|
264
|
-
expect(mockPostMessage).toHaveBeenCalledWith({});
|
|
209
|
+
|
|
265
210
|
expect(getQueriesFromChartConfig).toHaveBeenCalled();
|
|
266
211
|
});
|
|
267
212
|
|
|
268
|
-
test('default external function testing', () => {
|
|
213
|
+
test('default external function testing', async () => {
|
|
269
214
|
expect(mockInitMessage).toHaveBeenCalled();
|
|
270
215
|
|
|
271
216
|
// mock the event trigger for DataUpdate
|
|
272
|
-
|
|
273
|
-
eventProcessor({
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
data: 'random data',
|
|
277
|
-
},
|
|
278
|
-
eventType: TSToChartEvent.DataUpdate,
|
|
279
|
-
source: 'ts-host-app',
|
|
217
|
+
|
|
218
|
+
const dataUpdateResp = await eventProcessor({
|
|
219
|
+
payload: {
|
|
220
|
+
data: 'random data',
|
|
280
221
|
},
|
|
281
|
-
|
|
222
|
+
eventType: TSToChartEvent.DataUpdate,
|
|
282
223
|
});
|
|
283
224
|
// Check that the response was received
|
|
284
|
-
expect(
|
|
225
|
+
expect(dataUpdateResp).toEqual({
|
|
285
226
|
triggerRenderChart: true,
|
|
286
227
|
});
|
|
287
228
|
expect(customChartContext.getChartModel().data).toBe('random data');
|
|
288
|
-
mockPostMessage.mockReset();
|
|
289
229
|
|
|
290
230
|
// mock the event trigger for VisualPropsValidate
|
|
291
|
-
eventProcessor({
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
visualProps: null,
|
|
297
|
-
},
|
|
231
|
+
const modelUpdateResp = await eventProcessor({
|
|
232
|
+
payload: {
|
|
233
|
+
chartModel: {
|
|
234
|
+
data: 'random data2',
|
|
235
|
+
visualProps: null,
|
|
298
236
|
},
|
|
299
|
-
eventType: TSToChartEvent.ChartModelUpdate,
|
|
300
|
-
source: 'ts-host-app',
|
|
301
237
|
},
|
|
302
|
-
|
|
238
|
+
eventType: TSToChartEvent.ChartModelUpdate,
|
|
303
239
|
});
|
|
304
240
|
// Check that the response was received
|
|
305
|
-
expect(
|
|
241
|
+
expect(modelUpdateResp).toEqual({
|
|
306
242
|
triggerRenderChart: true,
|
|
307
243
|
});
|
|
308
244
|
expect(customChartContext.getChartModel().data).toBe(
|
|
@@ -310,26 +246,76 @@ describe('CustomChartContext', () => {
|
|
|
310
246
|
);
|
|
311
247
|
expect(customChartContext.getChartModel().visualProps).toBe(null);
|
|
312
248
|
|
|
313
|
-
mockPostMessage.mockReset();
|
|
314
|
-
|
|
315
249
|
// mock the event trigger for VisualPropsUpdate
|
|
316
|
-
eventProcessor({
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
visualProps: 'random data',
|
|
320
|
-
},
|
|
321
|
-
eventType: TSToChartEvent.VisualPropsUpdate,
|
|
322
|
-
source: 'ts-host-app',
|
|
250
|
+
const visualPropsUpdateResp = await eventProcessor({
|
|
251
|
+
payload: {
|
|
252
|
+
visualProps: 'random data',
|
|
323
253
|
},
|
|
324
|
-
|
|
254
|
+
eventType: TSToChartEvent.VisualPropsUpdate,
|
|
325
255
|
});
|
|
326
256
|
// Check that the response was received
|
|
327
|
-
expect(
|
|
257
|
+
expect(visualPropsUpdateResp).toEqual({
|
|
328
258
|
triggerRenderChart: true,
|
|
329
259
|
});
|
|
330
260
|
expect(customChartContext.getChartModel().visualProps).toBe(
|
|
331
261
|
'random data',
|
|
332
262
|
);
|
|
263
|
+
|
|
264
|
+
// mock the event trigger for AxisMenuActionClick
|
|
265
|
+
customChartContext.axisMenuCustomActionPreProcessor([
|
|
266
|
+
{
|
|
267
|
+
customActions: [
|
|
268
|
+
{
|
|
269
|
+
icon: '',
|
|
270
|
+
id: 'custom-action-1',
|
|
271
|
+
label: 'Custom user action 1',
|
|
272
|
+
onClick: () => _.noop(),
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
},
|
|
276
|
+
] as any);
|
|
277
|
+
const axisMenuClickResp = await eventProcessor({
|
|
278
|
+
payload: {
|
|
279
|
+
customAction: {
|
|
280
|
+
id: 'custom-action-1',
|
|
281
|
+
columnIds: ['9f96b5b0-f7e4-4a5e-aa11-4c77fdf42125'],
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
eventType: TSToChartEvent.AxisMenuActionClick,
|
|
285
|
+
});
|
|
286
|
+
// Check that the response was valid which means action gets
|
|
287
|
+
// executed successfully
|
|
288
|
+
expect(axisMenuClickResp).toEqual({
|
|
289
|
+
isValid: true,
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// mock the event trigger for ContextMenuActionClick
|
|
293
|
+
customChartContext.contextMenuCustomActionPreProcessor([
|
|
294
|
+
{
|
|
295
|
+
customActions: [
|
|
296
|
+
{
|
|
297
|
+
icon: '',
|
|
298
|
+
id: 'custom-action-1',
|
|
299
|
+
label: 'Custom user action 1',
|
|
300
|
+
onClick: () => _.noop(),
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
},
|
|
304
|
+
] as any);
|
|
305
|
+
const ctxMenuResp = await eventProcessor({
|
|
306
|
+
payload: {
|
|
307
|
+
customAction: {
|
|
308
|
+
id: 'custom-action-1',
|
|
309
|
+
columnIds: ['9f96b5b0-f7e4-4a5e-aa11-4c77fdf42125'],
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
eventType: TSToChartEvent.ContextMenuActionClick,
|
|
313
|
+
});
|
|
314
|
+
// Check that the response was valid which means action gets
|
|
315
|
+
// executed successfully
|
|
316
|
+
expect(ctxMenuResp).toEqual({
|
|
317
|
+
isValid: true,
|
|
318
|
+
});
|
|
333
319
|
});
|
|
334
320
|
|
|
335
321
|
test('should add an event listener to the specified event type', () => {
|
|
@@ -342,38 +328,30 @@ describe('CustomChartContext', () => {
|
|
|
342
328
|
customChartContext.on(TEST_EVENT_TYPE, testCallbackFn);
|
|
343
329
|
|
|
344
330
|
// mock the event trigger
|
|
345
|
-
|
|
331
|
+
|
|
346
332
|
eventProcessor({
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
eventType: TEST_EVENT_TYPE,
|
|
350
|
-
source: 'ts-host-app',
|
|
351
|
-
},
|
|
352
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
333
|
+
payload: mockInitializeContextPayload,
|
|
334
|
+
eventType: TEST_EVENT_TYPE,
|
|
353
335
|
});
|
|
354
336
|
// Check that the event listener was added to the eventListeners
|
|
355
337
|
// object
|
|
356
338
|
expect(testCallbackFn).toHaveBeenCalled();
|
|
357
339
|
});
|
|
358
340
|
|
|
359
|
-
test('should respond with an error to an unspecified event type', () => {
|
|
341
|
+
test('should respond with an error to an unspecified event type', async () => {
|
|
360
342
|
expect(mockInitMessage).toHaveBeenCalled();
|
|
361
343
|
// Define a test event type and callback function
|
|
362
344
|
const TEST_EVENT_TYPE = 'testEventType' as any;
|
|
363
345
|
|
|
364
346
|
// mock the event trigger
|
|
365
|
-
|
|
366
|
-
eventProcessor({
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
eventType: TEST_EVENT_TYPE,
|
|
370
|
-
source: 'ts-host-app',
|
|
371
|
-
},
|
|
372
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
347
|
+
|
|
348
|
+
const resp = await eventProcessor({
|
|
349
|
+
payload: mockInitializeContextPayload,
|
|
350
|
+
eventType: TEST_EVENT_TYPE,
|
|
373
351
|
});
|
|
374
352
|
// Check that the event listener was added to the eventListeners
|
|
375
353
|
// object
|
|
376
|
-
expect(
|
|
354
|
+
expect(resp).toEqual({
|
|
377
355
|
hasError: true,
|
|
378
356
|
error: `Event type not recognised or processed: ${TEST_EVENT_TYPE}`,
|
|
379
357
|
});
|
|
@@ -407,14 +385,10 @@ describe('CustomChartContext', () => {
|
|
|
407
385
|
customChartContext.on(TEST_EVENT_TYPE, testCallbackFn);
|
|
408
386
|
|
|
409
387
|
// mock the event trigger for the test event type
|
|
410
|
-
|
|
388
|
+
|
|
411
389
|
eventProcessor({
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
eventType: TEST_EVENT_TYPE,
|
|
415
|
-
source: 'ts-host-app',
|
|
416
|
-
},
|
|
417
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
390
|
+
payload: mockInitializeContextPayload,
|
|
391
|
+
eventType: TEST_EVENT_TYPE,
|
|
418
392
|
});
|
|
419
393
|
|
|
420
394
|
// Call the off function to remove the event listener
|
|
@@ -448,22 +422,14 @@ describe('CustomChartContext', () => {
|
|
|
448
422
|
).toHaveLength(1);
|
|
449
423
|
|
|
450
424
|
// Emit events for both event types
|
|
451
|
-
|
|
425
|
+
|
|
452
426
|
eventProcessor({
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
eventType: TEST_EVENT_TYPE_1,
|
|
456
|
-
source: 'ts-host-app',
|
|
457
|
-
},
|
|
458
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
427
|
+
payload: {},
|
|
428
|
+
eventType: TEST_EVENT_TYPE_1,
|
|
459
429
|
});
|
|
460
430
|
eventProcessor({
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
eventType: TEST_EVENT_TYPE_2,
|
|
464
|
-
source: 'ts-host-app',
|
|
465
|
-
},
|
|
466
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
431
|
+
payload: {},
|
|
432
|
+
eventType: TEST_EVENT_TYPE_2,
|
|
467
433
|
});
|
|
468
434
|
|
|
469
435
|
// Check that both callback functions were called
|
|
@@ -530,28 +496,19 @@ describe('CustomChartContext', () => {
|
|
|
530
496
|
|
|
531
497
|
test('should resolve the promise if the chart context is initialized', async () => {
|
|
532
498
|
// Check that the hasInitializedPromise has resolved
|
|
533
|
-
|
|
499
|
+
|
|
534
500
|
eventProcessor({
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
eventType: TSToChartEvent.Initialize,
|
|
538
|
-
source: 'ts-host-app',
|
|
539
|
-
},
|
|
540
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
501
|
+
payload: mockInitializeContextPayload,
|
|
502
|
+
eventType: TSToChartEvent.Initialize,
|
|
541
503
|
});
|
|
542
504
|
|
|
543
505
|
eventProcessor({
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
eventType: TSToChartEvent.InitializeComplete,
|
|
547
|
-
source: 'ts-host-app',
|
|
548
|
-
},
|
|
549
|
-
ports: [{ postMessage: mockPostMessage }],
|
|
506
|
+
payload: {},
|
|
507
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
550
508
|
});
|
|
551
509
|
|
|
552
510
|
const promise = customChartContext.initialize();
|
|
553
511
|
await expect(promise).resolves.toBeUndefined();
|
|
554
|
-
expect(mockPostMessage).toHaveBeenCalledTimes(2);
|
|
555
512
|
|
|
556
513
|
// define mock response for the postMessage response promise
|
|
557
514
|
let resolve: any;
|
|
@@ -605,5 +562,205 @@ describe('CustomChartContext', () => {
|
|
|
605
562
|
ChartToTSEvent.RenderStart,
|
|
606
563
|
);
|
|
607
564
|
});
|
|
565
|
+
test('should process the event payload for context menu custom actions', async () => {
|
|
566
|
+
const mockCustomAction = jest.fn();
|
|
567
|
+
let resolve: any;
|
|
568
|
+
eventProcessor({
|
|
569
|
+
payload: mockInitializeContextPayload,
|
|
570
|
+
eventType: TSToChartEvent.Initialize,
|
|
571
|
+
});
|
|
572
|
+
eventProcessor({
|
|
573
|
+
payload: {},
|
|
574
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
575
|
+
});
|
|
576
|
+
customChartContext.initialize();
|
|
577
|
+
mockPostMessageToHost.mockImplementation(
|
|
578
|
+
() =>
|
|
579
|
+
new global.Promise<any>((res) => {
|
|
580
|
+
resolve = res;
|
|
581
|
+
}),
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
// Define a test event type and payload
|
|
585
|
+
const TEST_EVENT_TYPE = ChartToTSEvent.OpenContextMenu as any;
|
|
586
|
+
const testPayload = {
|
|
587
|
+
customActions: [
|
|
588
|
+
{
|
|
589
|
+
id: 'custom-action-1',
|
|
590
|
+
label: 'Custom user action 1',
|
|
591
|
+
icon: '',
|
|
592
|
+
onClick: mockCustomAction,
|
|
593
|
+
},
|
|
594
|
+
],
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
// Call the emitEvent function and wait for it to resolve
|
|
598
|
+
customChartContext.emitEvent(TEST_EVENT_TYPE, testPayload);
|
|
599
|
+
|
|
600
|
+
// Check that the result is defined
|
|
601
|
+
expect(mockPostMessageToHost).toHaveBeenCalledWith(
|
|
602
|
+
mockInitializeContextPayload.componentId,
|
|
603
|
+
mockInitializeContextPayload.hostUrl,
|
|
604
|
+
{
|
|
605
|
+
customActions: [
|
|
606
|
+
{
|
|
607
|
+
icon: '',
|
|
608
|
+
id: 'custom-action-1',
|
|
609
|
+
label: 'Custom user action 1',
|
|
610
|
+
},
|
|
611
|
+
],
|
|
612
|
+
},
|
|
613
|
+
TEST_EVENT_TYPE,
|
|
614
|
+
);
|
|
615
|
+
eventProcessor({
|
|
616
|
+
payload: {
|
|
617
|
+
customAction: {
|
|
618
|
+
id: 'custom-action-1',
|
|
619
|
+
clickedPoint: {},
|
|
620
|
+
event: {},
|
|
621
|
+
selectedPoints: [{}],
|
|
622
|
+
},
|
|
623
|
+
},
|
|
624
|
+
eventType: TSToChartEvent.ContextMenuActionClick,
|
|
625
|
+
});
|
|
626
|
+
expect(mockCustomAction).toHaveBeenCalled();
|
|
627
|
+
expect(mockCustomAction).toHaveBeenCalledWith({
|
|
628
|
+
clickedPoint: {},
|
|
629
|
+
event: {},
|
|
630
|
+
id: 'custom-action-1',
|
|
631
|
+
selectedPoints: [{}],
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
test('should process the event payload for axis menu custom actions', async () => {
|
|
635
|
+
const mockCustomAction = jest.fn();
|
|
636
|
+
let resolve: any;
|
|
637
|
+
eventProcessor({
|
|
638
|
+
payload: mockInitializeContextPayload,
|
|
639
|
+
eventType: TSToChartEvent.Initialize,
|
|
640
|
+
});
|
|
641
|
+
eventProcessor({
|
|
642
|
+
payload: {},
|
|
643
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
644
|
+
});
|
|
645
|
+
customChartContext.initialize();
|
|
646
|
+
mockPostMessageToHost.mockImplementation(
|
|
647
|
+
() =>
|
|
648
|
+
new global.Promise<any>((res) => {
|
|
649
|
+
resolve = res;
|
|
650
|
+
}),
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
// Define a test event type and payload
|
|
654
|
+
const TEST_EVENT_TYPE = ChartToTSEvent.OpenAxisMenu as any;
|
|
655
|
+
const testPayload = {
|
|
656
|
+
customActions: [
|
|
657
|
+
{
|
|
658
|
+
id: 'custom-action-1',
|
|
659
|
+
label: 'Custom user action 1',
|
|
660
|
+
icon: '',
|
|
661
|
+
onClick: mockCustomAction,
|
|
662
|
+
},
|
|
663
|
+
],
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
// Call the emitEvent function and wait for it to resolve
|
|
667
|
+
customChartContext.emitEvent(TEST_EVENT_TYPE, testPayload);
|
|
668
|
+
// Check that the result is defined
|
|
669
|
+
expect(mockPostMessageToHost).toHaveBeenCalledWith(
|
|
670
|
+
mockInitializeContextPayload.componentId,
|
|
671
|
+
mockInitializeContextPayload.hostUrl,
|
|
672
|
+
{
|
|
673
|
+
customActions: [
|
|
674
|
+
{
|
|
675
|
+
icon: '',
|
|
676
|
+
id: 'custom-action-1',
|
|
677
|
+
label: 'Custom user action 1',
|
|
678
|
+
},
|
|
679
|
+
],
|
|
680
|
+
},
|
|
681
|
+
TEST_EVENT_TYPE,
|
|
682
|
+
);
|
|
683
|
+
|
|
684
|
+
eventProcessor({
|
|
685
|
+
payload: {
|
|
686
|
+
customAction: {
|
|
687
|
+
id: 'custom-action-1',
|
|
688
|
+
columnIds: ['123'],
|
|
689
|
+
event: {},
|
|
690
|
+
},
|
|
691
|
+
},
|
|
692
|
+
eventType: TSToChartEvent.AxisMenuActionClick,
|
|
693
|
+
});
|
|
694
|
+
expect(mockCustomAction).toHaveBeenCalled();
|
|
695
|
+
expect(mockCustomAction).toHaveBeenCalledWith({
|
|
696
|
+
id: 'custom-action-1',
|
|
697
|
+
columnIds: ['123'],
|
|
698
|
+
event: {},
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
test('should process the event payload for axis menu when custom actions are not defined', async () => {
|
|
703
|
+
let resolve: any;
|
|
704
|
+
eventProcessor({
|
|
705
|
+
payload: mockInitializeContextPayload,
|
|
706
|
+
eventType: TSToChartEvent.Initialize,
|
|
707
|
+
});
|
|
708
|
+
eventProcessor({
|
|
709
|
+
payload: {},
|
|
710
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
711
|
+
});
|
|
712
|
+
customChartContext.initialize();
|
|
713
|
+
mockPostMessageToHost.mockImplementation(
|
|
714
|
+
() =>
|
|
715
|
+
new global.Promise<any>((res) => {
|
|
716
|
+
resolve = res;
|
|
717
|
+
}),
|
|
718
|
+
);
|
|
719
|
+
|
|
720
|
+
// Define a test event type and payload
|
|
721
|
+
const TEST_EVENT_TYPE = ChartToTSEvent.OpenAxisMenu as any;
|
|
722
|
+
const testPayload = {};
|
|
723
|
+
// Call the emitEvent function and wait for it to resolve
|
|
724
|
+
customChartContext.emitEvent(TEST_EVENT_TYPE, testPayload);
|
|
725
|
+
// Check that the result is defined
|
|
726
|
+
expect(mockPostMessageToHost).toHaveBeenCalledWith(
|
|
727
|
+
mockInitializeContextPayload.componentId,
|
|
728
|
+
mockInitializeContextPayload.hostUrl,
|
|
729
|
+
{},
|
|
730
|
+
TEST_EVENT_TYPE,
|
|
731
|
+
);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
test('should process the event payload for context menu when custom actions are not defined', async () => {
|
|
735
|
+
let resolve: any;
|
|
736
|
+
eventProcessor({
|
|
737
|
+
payload: mockInitializeContextPayload,
|
|
738
|
+
eventType: TSToChartEvent.Initialize,
|
|
739
|
+
});
|
|
740
|
+
eventProcessor({
|
|
741
|
+
payload: {},
|
|
742
|
+
eventType: TSToChartEvent.InitializeComplete,
|
|
743
|
+
});
|
|
744
|
+
customChartContext.initialize();
|
|
745
|
+
mockPostMessageToHost.mockImplementation(
|
|
746
|
+
() =>
|
|
747
|
+
new global.Promise<any>((res) => {
|
|
748
|
+
resolve = res;
|
|
749
|
+
}),
|
|
750
|
+
);
|
|
751
|
+
|
|
752
|
+
// Define a test event type and payload
|
|
753
|
+
const TEST_EVENT_TYPE = ChartToTSEvent.OpenContextMenu as any;
|
|
754
|
+
const testPayload = {};
|
|
755
|
+
// Call the emitEvent function and wait for it to resolve
|
|
756
|
+
customChartContext.emitEvent(TEST_EVENT_TYPE, testPayload);
|
|
757
|
+
// Check that the result is defined
|
|
758
|
+
expect(mockPostMessageToHost).toHaveBeenCalledWith(
|
|
759
|
+
mockInitializeContextPayload.componentId,
|
|
760
|
+
mockInitializeContextPayload.hostUrl,
|
|
761
|
+
{},
|
|
762
|
+
TEST_EVENT_TYPE,
|
|
763
|
+
);
|
|
764
|
+
});
|
|
608
765
|
});
|
|
609
766
|
});
|