@thoughtspot/ts-chart-sdk 0.0.2-alpha.2 → 0.0.2-alpha.21

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.
Files changed (107) hide show
  1. package/README.md +126 -50
  2. package/dist/ts-chart-sdk.d.ts +940 -0
  3. package/lib/index.d.ts +4 -0
  4. package/lib/index.d.ts.map +1 -1
  5. package/lib/index.js +4 -0
  6. package/lib/index.js.map +1 -1
  7. package/lib/main/custom-chart-context.d.ts +22 -7
  8. package/lib/main/custom-chart-context.d.ts.map +1 -1
  9. package/lib/main/custom-chart-context.js +59 -4
  10. package/lib/main/custom-chart-context.js.map +1 -1
  11. package/lib/main/custom-chart-context.spec.js +402 -5
  12. package/lib/main/custom-chart-context.spec.js.map +1 -1
  13. package/lib/main/post-message-event-bridge.js +2 -2
  14. package/lib/main/post-message-event-bridge.js.map +1 -1
  15. package/lib/main/util.spec.d.ts +2 -0
  16. package/lib/main/util.spec.d.ts.map +1 -0
  17. package/lib/main/util.spec.js +31 -0
  18. package/lib/main/util.spec.js.map +1 -0
  19. package/lib/react/use-custom-chart-context.spec.js +54 -3
  20. package/lib/react/use-custom-chart-context.spec.js.map +1 -1
  21. package/lib/test/test-conditional-formatting-utils.d.ts +5 -0
  22. package/lib/test/test-conditional-formatting-utils.d.ts.map +1 -0
  23. package/lib/test/test-conditional-formatting-utils.js +43 -0
  24. package/lib/test/test-conditional-formatting-utils.js.map +1 -0
  25. package/lib/types/answer-column.types.d.ts +57 -1
  26. package/lib/types/answer-column.types.d.ts.map +1 -1
  27. package/lib/types/answer-column.types.js +47 -0
  28. package/lib/types/answer-column.types.js.map +1 -1
  29. package/lib/types/chart-to-ts-event.types.d.ts +2 -0
  30. package/lib/types/chart-to-ts-event.types.d.ts.map +1 -1
  31. package/lib/types/chart-to-ts-event.types.js +1 -0
  32. package/lib/types/chart-to-ts-event.types.js.map +1 -1
  33. package/lib/types/common.types.d.ts +103 -4
  34. package/lib/types/common.types.d.ts.map +1 -1
  35. package/lib/types/common.types.js +15 -1
  36. package/lib/types/common.types.js.map +1 -1
  37. package/lib/types/conditional-formatting.types.d.ts +140 -0
  38. package/lib/types/conditional-formatting.types.d.ts.map +1 -0
  39. package/lib/types/conditional-formatting.types.js +60 -0
  40. package/lib/types/conditional-formatting.types.js.map +1 -0
  41. package/lib/types/configurator.types.d.ts +5 -0
  42. package/lib/types/configurator.types.d.ts.map +1 -1
  43. package/lib/types/number-formatting.types.d.ts +55 -0
  44. package/lib/types/number-formatting.types.d.ts.map +1 -0
  45. package/lib/types/number-formatting.types.js +23 -0
  46. package/lib/types/number-formatting.types.js.map +1 -0
  47. package/lib/types/ts-to-chart-event.types.d.ts +10 -5
  48. package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
  49. package/lib/types/ts-to-chart-event.types.js.map +1 -1
  50. package/lib/types/visual-prop.types.d.ts +21 -0
  51. package/lib/types/visual-prop.types.d.ts.map +1 -1
  52. package/lib/utils/conditional-formatting/conditional-formatting.d.ts +10 -0
  53. package/lib/utils/conditional-formatting/conditional-formatting.d.ts.map +1 -0
  54. package/lib/utils/conditional-formatting/conditional-formatting.js +103 -0
  55. package/lib/utils/conditional-formatting/conditional-formatting.js.map +1 -0
  56. package/lib/utils/conditional-formatting/conditional-formatting.spec.d.ts +2 -0
  57. package/lib/utils/conditional-formatting/conditional-formatting.spec.d.ts.map +1 -0
  58. package/lib/utils/conditional-formatting/conditional-formatting.spec.js +142 -0
  59. package/lib/utils/conditional-formatting/conditional-formatting.spec.js.map +1 -0
  60. package/lib/utils/date-formatting.d.ts +103 -0
  61. package/lib/utils/date-formatting.d.ts.map +1 -0
  62. package/lib/utils/date-formatting.js +389 -0
  63. package/lib/utils/date-formatting.js.map +1 -0
  64. package/lib/utils/date-formatting.spec.d.ts +2 -0
  65. package/lib/utils/date-formatting.spec.d.ts.map +1 -0
  66. package/lib/utils/date-formatting.spec.js +394 -0
  67. package/lib/utils/date-formatting.spec.js.map +1 -0
  68. package/lib/utils/date-utils.d.ts +6 -0
  69. package/lib/utils/date-utils.d.ts.map +1 -0
  70. package/lib/utils/date-utils.js +20 -0
  71. package/lib/utils/date-utils.js.map +1 -0
  72. package/lib/utils/date-utils.spec.d.ts +2 -0
  73. package/lib/utils/date-utils.spec.d.ts.map +1 -0
  74. package/lib/utils/date-utils.spec.js +63 -0
  75. package/lib/utils/date-utils.spec.js.map +1 -0
  76. package/lib/utils/formatting-util.d.ts +10 -0
  77. package/lib/utils/formatting-util.d.ts.map +1 -0
  78. package/lib/utils/formatting-util.js +78 -0
  79. package/lib/utils/formatting-util.js.map +1 -0
  80. package/lib/utils/formatting-util.spec.d.ts +2 -0
  81. package/lib/utils/formatting-util.spec.d.ts.map +1 -0
  82. package/lib/utils/formatting-util.spec.js +247 -0
  83. package/lib/utils/formatting-util.spec.js.map +1 -0
  84. package/package.json +6 -4
  85. package/src/index.ts +4 -0
  86. package/src/main/custom-chart-context.spec.ts +474 -9
  87. package/src/main/custom-chart-context.ts +246 -12
  88. package/src/main/post-message-event-bridge.ts +1 -1
  89. package/src/main/util.spec.ts +41 -0
  90. package/src/react/use-custom-chart-context.spec.tsx +65 -3
  91. package/src/test/test-conditional-formatting-utils.ts +95 -0
  92. package/src/types/answer-column.types.ts +102 -1
  93. package/src/types/chart-to-ts-event.types.ts +7 -0
  94. package/src/types/common.types.ts +165 -10
  95. package/src/types/conditional-formatting.types.ts +157 -0
  96. package/src/types/configurator.types.ts +21 -0
  97. package/src/types/number-formatting.types.ts +80 -0
  98. package/src/types/ts-to-chart-event.types.ts +38 -6
  99. package/src/types/visual-prop.types.ts +75 -1
  100. package/src/utils/conditional-formatting/conditional-formatting.spec.ts +469 -0
  101. package/src/utils/conditional-formatting/conditional-formatting.ts +229 -0
  102. package/src/utils/date-formatting.spec.ts +511 -0
  103. package/src/utils/date-formatting.ts +679 -0
  104. package/src/utils/date-utils.spec.ts +93 -0
  105. package/src/utils/date-utils.ts +69 -0
  106. package/src/utils/formatting-util.spec.ts +312 -0
  107. package/src/utils/formatting-util.ts +234 -0
@@ -6,17 +6,25 @@
6
6
 
7
7
  import _ from 'lodash';
8
8
  import { mockInitializeContextPayload } from '../test/test-utils';
9
+ import { ColumnType } from '../types/answer-column.types';
9
10
  import { ChartToTSEvent, ErrorType } from '../types/chart-to-ts-event.types';
10
11
  import { TSToChartEvent } from '../types/ts-to-chart-event.types';
12
+ import { PropElement } from '../types/visual-prop.types';
11
13
  import { CustomChartContext, getChartContext } from './custom-chart-context';
12
14
  import * as PostMessageEventBridge from './post-message-event-bridge';
13
15
 
14
- // jest.mock('./post-message-event-bridge');
15
-
16
16
  jest.spyOn(console, 'log').mockImplementation(() => {
17
17
  // do nothing.
18
18
  });
19
19
 
20
+ const mockFormElements: PropElement = {
21
+ key: 'color',
22
+ type: 'radio',
23
+ defaultValue: 'red',
24
+ values: ['red', 'green', 'yellow'],
25
+ label: 'Colors',
26
+ };
27
+
20
28
  describe('CustomChartContext', () => {
21
29
  let eventProcessor: any;
22
30
 
@@ -107,28 +115,105 @@ describe('CustomChartContext', () => {
107
115
  allowedConfigurations: {
108
116
  allowColumnNumberFormatting: false,
109
117
  allowColumnConditionalFormatting: false,
118
+ allowMeasureNamesAndValues: false,
119
+ },
120
+ chartConfigParameters: {
121
+ measureNameValueColumns: {
122
+ enableMeasureNameColumn: false,
123
+ enableMeasureValueColumn: false,
124
+ measureNameColumnAlias: 'Measure Name',
125
+ measureValueColumnAlias: 'Measure Values',
126
+ },
127
+ batchSizeLimit: 20000,
110
128
  },
111
129
  });
112
- expect(mockPostMessageToHost).not.toHaveBeenCalled();
113
130
  });
114
131
 
115
- test('multiple intializations should throw an error', async () => {
132
+ test('should return responseMessage as empty instead of undefine', async () => {
133
+ expect(mockInitMessage).toHaveBeenCalled();
134
+
135
+ const initResp = await eventProcessor({
136
+ payload: {},
137
+ eventType: TSToChartEvent.InitializeComplete,
138
+ });
139
+ expect(initResp).toEqual({});
140
+ });
141
+
142
+ test('type check string for visualProps on initialize payload should not throw an error.', async () => {
143
+ expect(mockInitMessage).toHaveBeenCalled();
144
+
116
145
  // Call the initialize function and wait for it to resolve
117
146
  const promise = customChartContext.initialize();
118
147
 
119
148
  // Check that the hasInitializedPromise has resolved
120
- eventProcessor({
121
- payload: mockInitializeContextPayload,
149
+
150
+ const mockInitializeContextPayloadWithVisualProps = {
151
+ ...mockInitializeContextPayload,
152
+ chartModel: {
153
+ ...mockInitializeContextPayload.chartModel,
154
+ visualProps: 'visualPropStringPayload',
155
+ },
156
+ };
157
+
158
+ await eventProcessor({
159
+ payload: mockInitializeContextPayloadWithVisualProps,
122
160
  eventType: TSToChartEvent.Initialize,
123
161
  });
124
-
125
162
  eventProcessor({
126
163
  payload: {},
127
164
  eventType: TSToChartEvent.InitializeComplete,
128
165
  });
166
+ await expect(promise).resolves.toBeUndefined();
167
+ const chartModel = customChartContext.getChartModel();
168
+ expect(typeof chartModel.visualProps).toEqual('string');
169
+ expect(chartModel.visualProps).toEqual('visualPropStringPayload');
170
+ });
171
+
172
+ test('type check object for visualProps on initialize payload should not throw an error.', async () => {
173
+ expect(mockInitMessage).toHaveBeenCalled();
129
174
 
175
+ // Call the initialize function and wait for it to resolve
176
+ const promise = customChartContext.initialize();
177
+
178
+ // Check that the hasInitializedPromise has resolved
179
+
180
+ const mockInitializeContextPayloadWithVisualProps = {
181
+ ...mockInitializeContextPayload,
182
+ chartModel: {
183
+ ...mockInitializeContextPayload.chartModel,
184
+ visualProps: {
185
+ data: 'sample data',
186
+ },
187
+ },
188
+ };
189
+
190
+ await eventProcessor({
191
+ payload: mockInitializeContextPayloadWithVisualProps,
192
+ eventType: TSToChartEvent.Initialize,
193
+ });
194
+ eventProcessor({
195
+ payload: {},
196
+ eventType: TSToChartEvent.InitializeComplete,
197
+ });
130
198
  await expect(promise).resolves.toBeUndefined();
199
+ const chartModel = customChartContext.getChartModel();
200
+ expect(typeof chartModel.visualProps).toEqual('object');
201
+ expect(chartModel.visualProps).toEqual({
202
+ data: 'sample data',
203
+ });
204
+ });
131
205
 
206
+ test('multiple intializations should throw an error', async () => {
207
+ // Call the initialize function and wait for it to resolve
208
+ getChartContext({
209
+ getDefaultChartConfig,
210
+ getQueriesFromChartConfig,
211
+ renderChart,
212
+ });
213
+ eventProcessor({
214
+ payload: {},
215
+ eventType: TSToChartEvent.InitializeComplete,
216
+ });
132
217
  let error;
133
218
  try {
134
219
  customChartContext = new CustomChartContext({
@@ -152,6 +237,45 @@ describe('CustomChartContext', () => {
152
237
  }
153
238
  expect(error).toBe(ErrorType.MultipleContextsNotSupported);
154
239
  });
240
+ test('correct app options config should be set on initialize', async () => {
241
+ const mockAppConfigOptions = {
242
+ appOptions: {
243
+ isMobile: false,
244
+ isPrintMode: false,
245
+ isLiveboardContext: false,
246
+ isDebugMode: true,
247
+ },
248
+ };
249
+ expect(mockInitMessage).toHaveBeenCalled();
250
+
251
+ // Call the initialize function and wait for it to resolve
252
+ const promise = customChartContext.initialize();
253
+
254
+ // Check that the hasInitializedPromise has resolved
255
+
256
+ const mockInitializeContextPayloadWithVisualProps = {
257
+ ...mockInitializeContextPayload,
258
+ appConfig: mockAppConfigOptions,
259
+ chartModel: {
260
+ ...mockInitializeContextPayload.chartModel,
261
+ visualProps: {
262
+ data: 'sample data',
263
+ },
264
+ },
265
+ };
266
+
267
+ await eventProcessor({
268
+ payload: mockInitializeContextPayloadWithVisualProps,
269
+ eventType: TSToChartEvent.Initialize,
270
+ });
271
+ eventProcessor({
272
+ payload: {},
273
+ eventType: TSToChartEvent.InitializeComplete,
274
+ });
275
+ await expect(promise).resolves.toBeUndefined();
276
+ const appConfig = customChartContext.getAppConfig();
277
+ expect(appConfig).toStrictEqual(mockAppConfigOptions);
278
+ });
155
279
  });
156
280
 
157
281
  describe('on', () => {
@@ -170,7 +294,349 @@ describe('CustomChartContext', () => {
170
294
  eventProcessor = null;
171
295
  });
172
296
 
173
- test('default internal function testing', async () => {
297
+ test('TSToChartEvent.ChartConfigValidate validation response testing', async () => {
298
+ // Define initial context with object definitions
299
+ customChartContext = new CustomChartContext({
300
+ getDefaultChartConfig,
301
+ getQueriesFromChartConfig,
302
+ renderChart,
303
+ visualPropEditorDefinition: { elements: [] },
304
+ chartConfigEditorDefinition: [],
305
+ });
306
+
307
+ // Trigger event processor with initial context
308
+ const responseWithInitialContext = await eventProcessor({
309
+ payload: mockInitializeContextPayload,
310
+ eventType: TSToChartEvent.ChartConfigValidate,
311
+ source: 'ts-host-app',
312
+ });
313
+ // Verify response with object definitions
314
+ expect(responseWithInitialContext).toStrictEqual({
315
+ isValid: true,
316
+ visualPropEditorDefinition: { elements: [] },
317
+ chartConfigEditorDefinition: [],
318
+ });
319
+
320
+ // Redefine context with function-returned definitions
321
+ customChartContext = new CustomChartContext({
322
+ getDefaultChartConfig,
323
+ getQueriesFromChartConfig,
324
+ renderChart,
325
+ visualPropEditorDefinition: () => {
326
+ return { elements: [] };
327
+ },
328
+ chartConfigEditorDefinition: () => {
329
+ return [
330
+ {
331
+ key: 'x',
332
+ columnSections: [{ label: 'x-axis', key: 'x' }],
333
+ },
334
+ ];
335
+ },
336
+ });
337
+ // Trigger event processor with updated context
338
+ const responseWithUpdatedContext = await eventProcessor({
339
+ payload: mockInitializeContextPayload,
340
+ eventType: TSToChartEvent.ChartConfigValidate,
341
+ source: 'ts-host-app',
342
+ });
343
+ // Verify response with function-returned definitions
344
+ expect(responseWithUpdatedContext).toStrictEqual({
345
+ isValid: true,
346
+ visualPropEditorDefinition: { elements: [] },
347
+ chartConfigEditorDefinition: [
348
+ {
349
+ key: 'x',
350
+ columnSections: [{ label: 'x-axis', key: 'x' }],
351
+ },
352
+ ],
353
+ });
354
+ });
355
+ test('TSToChartEvent.ChartConfigValidate validation response for invalid config', async () => {
356
+ // Define initial context with object definitions
357
+ const mockChartConfigValidate = jest
358
+ .fn()
359
+ .mockReturnValue({ isValid: false });
360
+ customChartContext = new CustomChartContext({
361
+ getDefaultChartConfig,
362
+ getQueriesFromChartConfig,
363
+ renderChart,
364
+ visualPropEditorDefinition: { elements: [] },
365
+ chartConfigEditorDefinition: [],
366
+ validateConfig: mockChartConfigValidate,
367
+ });
368
+
369
+ // Trigger event processor with initial context
370
+ const responseWithInitialContext = await eventProcessor({
371
+ payload: mockInitializeContextPayload,
372
+ eventType: TSToChartEvent.ChartConfigValidate,
373
+ source: 'ts-host-app',
374
+ });
375
+ // Verify response with object definitions
376
+ expect(responseWithInitialContext).toStrictEqual({
377
+ isValid: false,
378
+ });
379
+ });
380
+ test('TSToChartEvent.ChartConfigValidate validation response return invalid without validate function', async () => {
381
+ // Define initial context with object definitions
382
+ customChartContext = new CustomChartContext({
383
+ getDefaultChartConfig,
384
+ getQueriesFromChartConfig,
385
+ renderChart,
386
+ visualPropEditorDefinition: { elements: [] },
387
+ chartConfigEditorDefinition: [],
388
+ validateConfig: undefined,
389
+ });
390
+
391
+ // Trigger event processor with initial context
392
+ const responseWithInitialContext = await eventProcessor({
393
+ payload: mockInitializeContextPayload,
394
+ eventType: TSToChartEvent.ChartConfigValidate,
395
+ source: 'ts-host-app',
396
+ });
397
+ // Verify response with object definitions
398
+ expect(responseWithInitialContext).toStrictEqual({
399
+ isValid: false,
400
+ });
401
+ });
402
+
403
+ test('TSToChartEvent.validateVisualProps validation response testing', () => {
404
+ // Define initial context with object definitions
405
+ customChartContext = new CustomChartContext({
406
+ getDefaultChartConfig,
407
+ getQueriesFromChartConfig,
408
+ renderChart,
409
+ visualPropEditorDefinition: { elements: [] },
410
+ chartConfigEditorDefinition: [],
411
+ });
412
+
413
+ // Trigger event processor with initial context
414
+ const responseWithInitialContext = eventProcessor({
415
+ payload: mockInitializeContextPayload,
416
+ eventType: TSToChartEvent.VisualPropsValidate,
417
+ source: 'ts-host-app',
418
+ });
419
+ // Verify response with object definitions
420
+ expect(responseWithInitialContext).toStrictEqual({
421
+ isValid: true,
422
+ visualPropEditorDefinition: { elements: [] },
423
+ chartConfigEditorDefinition: [],
424
+ });
425
+ // Redefine context with function-returned definitions
426
+ customChartContext = new CustomChartContext({
427
+ getDefaultChartConfig,
428
+ getQueriesFromChartConfig,
429
+ renderChart,
430
+ visualPropEditorDefinition: () => {
431
+ return { elements: [] };
432
+ },
433
+ chartConfigEditorDefinition: () => {
434
+ return [
435
+ {
436
+ key: 'x',
437
+ columnSections: [{ label: 'x-axis', key: 'x' }],
438
+ },
439
+ ];
440
+ },
441
+ });
442
+ // Trigger event processor with updated context
443
+ const responseWithFunctionReturnedValues = eventProcessor({
444
+ payload: mockInitializeContextPayload,
445
+ eventType: TSToChartEvent.VisualPropsValidate,
446
+ source: 'ts-host-app',
447
+ });
448
+ // Verify response with function-returned definitions
449
+ expect(responseWithFunctionReturnedValues).toStrictEqual({
450
+ isValid: true,
451
+ visualPropEditorDefinition: { elements: [] },
452
+ chartConfigEditorDefinition: [
453
+ {
454
+ key: 'x',
455
+ columnSections: [{ label: 'x-axis', key: 'x' }],
456
+ },
457
+ ],
458
+ });
459
+ });
460
+
461
+ test('TSToChartEvent.validateVisualProps should work with activeColumnId', () => {
462
+ // Define initial context with object definitions
463
+ customChartContext = new CustomChartContext({
464
+ getDefaultChartConfig,
465
+ getQueriesFromChartConfig,
466
+ renderChart,
467
+ visualPropEditorDefinition: {
468
+ elements: [mockFormElements],
469
+ columnsVizPropDefinition: [
470
+ {
471
+ type: ColumnType.MEASURE,
472
+ columnSettingsDefinition: {
473
+ 'column-id': { elements: [mockFormElements] },
474
+ },
475
+ },
476
+ ],
477
+ },
478
+ chartConfigEditorDefinition: [],
479
+ });
480
+
481
+ // Trigger event processor with initial context
482
+ const responseWithInitialContext = eventProcessor({
483
+ payload: {
484
+ ...mockInitializeContextPayload,
485
+ activeColumnId: 'column-id',
486
+ },
487
+ eventType: TSToChartEvent.VisualPropsValidate,
488
+ source: 'ts-host-app',
489
+ });
490
+ // Verify response with object definitions
491
+ expect(responseWithInitialContext).toStrictEqual({
492
+ isValid: true,
493
+ visualPropEditorDefinition: {
494
+ elements: [mockFormElements],
495
+ columnsVizPropDefinition: [
496
+ {
497
+ type: ColumnType.MEASURE,
498
+ columnSettingsDefinition: {
499
+ 'column-id': { elements: [mockFormElements] },
500
+ },
501
+ },
502
+ ],
503
+ },
504
+ chartConfigEditorDefinition: [],
505
+ });
506
+ });
507
+
508
+ test('TSToChartEvent.validateVisualProps should be called with correct activeColumnId', () => {
509
+ // Define initial context with object definitions
510
+ const mockValidateVisualProps = jest
511
+ .fn()
512
+ .mockImplementation(
513
+ (_visualProps, _chartModel, activeColumnId) => {
514
+ if (activeColumnId === 'column-id')
515
+ return { isValid: true };
516
+ return { isValid: false };
517
+ },
518
+ );
519
+ customChartContext = new CustomChartContext({
520
+ getDefaultChartConfig,
521
+ getQueriesFromChartConfig,
522
+ renderChart,
523
+ visualPropEditorDefinition: {
524
+ elements: [mockFormElements],
525
+ columnsVizPropDefinition: [
526
+ {
527
+ type: ColumnType.MEASURE,
528
+ columnSettingsDefinition: {
529
+ 'column-id': { elements: [mockFormElements] },
530
+ },
531
+ },
532
+ ],
533
+ },
534
+ chartConfigEditorDefinition: [],
535
+ validateVisualProps: mockValidateVisualProps,
536
+ });
537
+
538
+ // Trigger event processor with initial context
539
+ const responseWithInitialContext = eventProcessor({
540
+ payload: {
541
+ ...mockInitializeContextPayload,
542
+ activeColumnId: 'column-id',
543
+ },
544
+ eventType: TSToChartEvent.VisualPropsValidate,
545
+ source: 'ts-host-app',
546
+ });
547
+ // we only want the correct active columnId to be passed
548
+ expect(mockValidateVisualProps).toHaveBeenCalledWith(
549
+ undefined,
550
+ {},
551
+ 'column-id',
552
+ );
553
+ const validationResponse = eventProcessor({
554
+ payload: {
555
+ ...mockInitializeContextPayload,
556
+ activeColumnId: 'column-id-1',
557
+ },
558
+ eventType: TSToChartEvent.VisualPropsValidate,
559
+ source: 'ts-host-app',
560
+ });
561
+ expect(validationResponse).toStrictEqual({ isValid: false });
562
+ });
563
+ test('TSToChartEvent.validateVisualProps returns invalid if no function is provided.', () => {
564
+ // Define initial context with object definitions
565
+ customChartContext = new CustomChartContext({
566
+ getDefaultChartConfig,
567
+ getQueriesFromChartConfig,
568
+ renderChart,
569
+ visualPropEditorDefinition: {
570
+ elements: [mockFormElements],
571
+ columnsVizPropDefinition: [
572
+ {
573
+ type: ColumnType.MEASURE,
574
+ columnSettingsDefinition: {
575
+ 'column-id': { elements: [mockFormElements] },
576
+ },
577
+ },
578
+ ],
579
+ },
580
+ chartConfigEditorDefinition: [],
581
+ validateVisualProps: undefined, // mocking undefined value
582
+ });
583
+
584
+ const validationResponse = eventProcessor({
585
+ payload: {
586
+ ...mockInitializeContextPayload,
587
+ },
588
+ eventType: TSToChartEvent.VisualPropsValidate,
589
+ source: 'ts-host-app',
590
+ });
591
+ expect(validationResponse).toStrictEqual({ isValid: false });
592
+ });
593
+ test('VisualPropEditorDefintion function should recieve columnId', () => {
594
+ // Define initial context with object definitions
595
+ const mockValidateVisualProps = jest
596
+ .fn()
597
+ .mockImplementation(
598
+ (_visualProps, _chartModel, activeColumnId) => {
599
+ if (activeColumnId === 'column-id')
600
+ return { isValid: true };
601
+ return { isValid: false };
602
+ },
603
+ );
604
+ const mockVisualPropEditorDefintion = jest.fn().mockReturnValue({
605
+ elements: [mockFormElements],
606
+ columnsVizPropDefinition: [
607
+ {
608
+ type: ColumnType.MEASURE,
609
+ columnSettingsDefinition: {
610
+ 'column-id': { elements: [mockFormElements] },
611
+ },
612
+ },
613
+ ],
614
+ });
615
+ customChartContext = new CustomChartContext({
616
+ getDefaultChartConfig,
617
+ getQueriesFromChartConfig,
618
+ renderChart,
619
+ visualPropEditorDefinition: mockVisualPropEditorDefintion,
620
+ chartConfigEditorDefinition: [],
621
+ validateVisualProps: mockValidateVisualProps,
622
+ });
623
+
624
+ // Trigger event processor with initial context
625
+ const responseWithInitialContext = eventProcessor({
626
+ payload: {
627
+ ...mockInitializeContextPayload,
628
+ activeColumnId: 'column-id',
629
+ },
630
+ eventType: TSToChartEvent.VisualPropsValidate,
631
+ source: 'ts-host-app',
632
+ });
633
+ // we only want the correct active columnId to be passed
634
+ expect(mockVisualPropEditorDefintion.mock.calls[0][2]).toBe(
635
+ 'column-id',
636
+ );
637
+ });
638
+
639
+ test('should not trigger post message if host is not accurate', async () => {
174
640
  expect(mockInitMessage).toHaveBeenCalled();
175
641
 
176
642
  // mock the event trigger for ChartConfigValidate
@@ -490,7 +956,6 @@ describe('CustomChartContext', () => {
490
956
  );
491
957
 
492
958
  // Check that the result is defined
493
- expect(mockPostMessageToHost).not.toHaveBeenCalled();
494
959
  await expect(result).rejects.toBeDefined();
495
960
  });
496
961