@thoughtspot/visual-embed-sdk 1.49.3 → 1.50.0

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 (113) hide show
  1. package/cjs/package.json +1 -1
  2. package/cjs/src/authToken.spec.js +5 -0
  3. package/cjs/src/authToken.spec.js.map +1 -1
  4. package/cjs/src/embed/app.d.ts.map +1 -1
  5. package/cjs/src/embed/app.js +6 -0
  6. package/cjs/src/embed/app.js.map +1 -1
  7. package/cjs/src/embed/app.spec.js +11 -2
  8. package/cjs/src/embed/app.spec.js.map +1 -1
  9. package/cjs/src/embed/conversation.d.ts +12 -0
  10. package/cjs/src/embed/conversation.d.ts.map +1 -1
  11. package/cjs/src/embed/conversation.js.map +1 -1
  12. package/cjs/src/embed/conversation.spec.js +30 -0
  13. package/cjs/src/embed/conversation.spec.js.map +1 -1
  14. package/cjs/src/embed/embedConfig.spec.d.ts +2 -0
  15. package/cjs/src/embed/embedConfig.spec.d.ts.map +1 -0
  16. package/cjs/src/embed/embedConfig.spec.js +74 -0
  17. package/cjs/src/embed/embedConfig.spec.js.map +1 -0
  18. package/cjs/src/embed/host-events.spec.d.ts +2 -0
  19. package/cjs/src/embed/host-events.spec.d.ts.map +1 -0
  20. package/cjs/src/embed/host-events.spec.js +1219 -0
  21. package/cjs/src/embed/host-events.spec.js.map +1 -0
  22. package/cjs/src/mixpanel-service.spec.js +14 -0
  23. package/cjs/src/mixpanel-service.spec.js.map +1 -1
  24. package/cjs/src/types.d.ts +93 -6
  25. package/cjs/src/types.d.ts.map +1 -1
  26. package/cjs/src/types.js +88 -3
  27. package/cjs/src/types.js.map +1 -1
  28. package/cjs/src/utils/custom-actions.spec.js +26 -0
  29. package/cjs/src/utils/custom-actions.spec.js.map +1 -1
  30. package/cjs/src/utils/processData.spec.js +30 -0
  31. package/cjs/src/utils/processData.spec.js.map +1 -1
  32. package/cjs/src/utils/reporting.spec.js +21 -0
  33. package/cjs/src/utils/reporting.spec.js.map +1 -1
  34. package/cjs/src/utils/sessionInfoService.spec.d.ts +2 -0
  35. package/cjs/src/utils/sessionInfoService.spec.d.ts.map +1 -0
  36. package/cjs/src/utils/sessionInfoService.spec.js +130 -0
  37. package/cjs/src/utils/sessionInfoService.spec.js.map +1 -0
  38. package/cjs/src/utils.spec.js +158 -0
  39. package/cjs/src/utils.spec.js.map +1 -1
  40. package/dist/{index-DsSQndIB.js → index-B5xoN6Cp.js} +1 -1
  41. package/dist/src/embed/app.d.ts.map +1 -1
  42. package/dist/src/embed/conversation.d.ts +12 -0
  43. package/dist/src/embed/conversation.d.ts.map +1 -1
  44. package/dist/src/embed/embedConfig.spec.d.ts +2 -0
  45. package/dist/src/embed/embedConfig.spec.d.ts.map +1 -0
  46. package/dist/src/embed/host-events.spec.d.ts +2 -0
  47. package/dist/src/embed/host-events.spec.d.ts.map +1 -0
  48. package/dist/src/types.d.ts +93 -6
  49. package/dist/src/types.d.ts.map +1 -1
  50. package/dist/src/utils/sessionInfoService.spec.d.ts +2 -0
  51. package/dist/src/utils/sessionInfoService.spec.d.ts.map +1 -0
  52. package/dist/tsembed-react.es.js +97 -6
  53. package/dist/tsembed-react.js +96 -5
  54. package/dist/tsembed.es.js +97 -6
  55. package/dist/tsembed.js +96 -5
  56. package/dist/visual-embed-sdk-react-full.d.ts +105 -6
  57. package/dist/visual-embed-sdk-react.d.ts +105 -6
  58. package/dist/visual-embed-sdk.d.ts +105 -6
  59. package/lib/package.json +1 -1
  60. package/lib/src/authToken.spec.js +5 -0
  61. package/lib/src/authToken.spec.js.map +1 -1
  62. package/lib/src/embed/app.d.ts.map +1 -1
  63. package/lib/src/embed/app.js +6 -0
  64. package/lib/src/embed/app.js.map +1 -1
  65. package/lib/src/embed/app.spec.js +11 -2
  66. package/lib/src/embed/app.spec.js.map +1 -1
  67. package/lib/src/embed/conversation.d.ts +12 -0
  68. package/lib/src/embed/conversation.d.ts.map +1 -1
  69. package/lib/src/embed/conversation.js.map +1 -1
  70. package/lib/src/embed/conversation.spec.js +30 -0
  71. package/lib/src/embed/conversation.spec.js.map +1 -1
  72. package/lib/src/embed/embedConfig.spec.d.ts +2 -0
  73. package/lib/src/embed/embedConfig.spec.d.ts.map +1 -0
  74. package/lib/src/embed/embedConfig.spec.js +72 -0
  75. package/lib/src/embed/embedConfig.spec.js.map +1 -0
  76. package/lib/src/embed/host-events.spec.d.ts +2 -0
  77. package/lib/src/embed/host-events.spec.d.ts.map +1 -0
  78. package/lib/src/embed/host-events.spec.js +1216 -0
  79. package/lib/src/embed/host-events.spec.js.map +1 -0
  80. package/lib/src/mixpanel-service.spec.js +14 -0
  81. package/lib/src/mixpanel-service.spec.js.map +1 -1
  82. package/lib/src/types.d.ts +93 -6
  83. package/lib/src/types.d.ts.map +1 -1
  84. package/lib/src/types.js +88 -3
  85. package/lib/src/types.js.map +1 -1
  86. package/lib/src/utils/custom-actions.spec.js +26 -0
  87. package/lib/src/utils/custom-actions.spec.js.map +1 -1
  88. package/lib/src/utils/processData.spec.js +30 -0
  89. package/lib/src/utils/processData.spec.js.map +1 -1
  90. package/lib/src/utils/reporting.spec.js +21 -0
  91. package/lib/src/utils/reporting.spec.js.map +1 -1
  92. package/lib/src/utils/sessionInfoService.spec.d.ts +2 -0
  93. package/lib/src/utils/sessionInfoService.spec.d.ts.map +1 -0
  94. package/lib/src/utils/sessionInfoService.spec.js +127 -0
  95. package/lib/src/utils/sessionInfoService.spec.js.map +1 -0
  96. package/lib/src/utils.spec.js +159 -1
  97. package/lib/src/utils.spec.js.map +1 -1
  98. package/lib/src/visual-embed-sdk.d.ts +105 -6
  99. package/package.json +1 -1
  100. package/src/authToken.spec.ts +6 -0
  101. package/src/embed/app.spec.ts +15 -2
  102. package/src/embed/app.ts +6 -0
  103. package/src/embed/conversation.spec.ts +32 -0
  104. package/src/embed/conversation.ts +12 -0
  105. package/src/embed/embedConfig.spec.ts +79 -0
  106. package/src/embed/host-events.spec.ts +1635 -0
  107. package/src/mixpanel-service.spec.ts +15 -0
  108. package/src/types.ts +96 -6
  109. package/src/utils/custom-actions.spec.ts +28 -0
  110. package/src/utils/processData.spec.ts +32 -0
  111. package/src/utils/reporting.spec.ts +27 -0
  112. package/src/utils/sessionInfoService.spec.ts +151 -0
  113. package/src/utils.spec.ts +195 -0
@@ -0,0 +1,1635 @@
1
+ /**
2
+ * Unit tests for HostEvents that had no prior coverage.
3
+ * Covers: postMessage type correctness, !isRendered guard (returns null + handleError),
4
+ * and vizId injection on LiveboardEmbed when viewConfig.vizId is set.
5
+ */
6
+ import {
7
+ init,
8
+ AuthType,
9
+ LiveboardEmbed,
10
+ HostEvent,
11
+ EmbedErrorCodes,
12
+ } from '../index';
13
+ import {
14
+ executeAfterWait,
15
+ getDocumentBody,
16
+ getIFrameEl,
17
+ getRootEl,
18
+ mockMessageChannel,
19
+ messageChannelMock,
20
+ } from '../test/test-utils';
21
+ import * as authInstance from '../auth';
22
+
23
+ const thoughtSpotHost = 'https://tshost';
24
+ const liveboardId = 'eca215d4-0d2c-4a55-90e3-d81ef6848ae0';
25
+ const vizId = '6e73f724-660e-11eb-ae93-0242ac130002';
26
+
27
+ beforeAll(() => {
28
+ init({ thoughtSpotHost, authType: AuthType.None });
29
+ jest.spyOn(authInstance, 'postLoginService').mockImplementation(() => Promise.resolve(true as any));
30
+ });
31
+
32
+ beforeEach(() => {
33
+ document.body.innerHTML = getDocumentBody();
34
+ });
35
+
36
+ // ---------------------------------------------------------------------------
37
+ // Helper: render a LiveboardEmbed and return it with the iframe spy
38
+ // ---------------------------------------------------------------------------
39
+ async function renderLiveboard(extraConfig: Record<string, any> = {}) {
40
+ const lb = new LiveboardEmbed(getRootEl(), {
41
+ frameParams: { width: '100%', height: '100%' },
42
+ liveboardId,
43
+ ...extraConfig,
44
+ });
45
+ await lb.render();
46
+ const iframe = getIFrameEl();
47
+ jest.spyOn(iframe.contentWindow, 'postMessage');
48
+ return { lb, iframe };
49
+ }
50
+
51
+ // Helper: create a LiveboardEmbed that has NOT been rendered, with handleError
52
+ // mocked to prevent the jest-setup console.error → throw.
53
+ function unrenderedLiveboard() {
54
+ const lb = new LiveboardEmbed(getRootEl(), {
55
+ frameParams: { width: '100%', height: '100%' },
56
+ liveboardId,
57
+ });
58
+ jest.spyOn(lb as any, 'handleError').mockImplementation(() => {});
59
+ return lb;
60
+ }
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // 3 – Filter
64
+ // ---------------------------------------------------------------------------
65
+ describe('HostEvent.Filter', () => {
66
+ test('postMessage type is filter (all lowercase)', async () => {
67
+ mockMessageChannel();
68
+ const { lb, iframe } = await renderLiveboard();
69
+ await executeAfterWait(() => {
70
+ lb.trigger(HostEvent.Filter, { columnName: 'col', operator: 'EQ', values: ['v'] } as any);
71
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
72
+ expect.objectContaining({ type: 'filter' }),
73
+ thoughtSpotHost,
74
+ expect.anything(),
75
+ );
76
+ });
77
+ });
78
+
79
+ test('returns null and calls handleError when !isRendered', async () => {
80
+ const lb = unrenderedLiveboard();
81
+ const handleErrorSpy = (lb as any).handleError as jest.Mock;
82
+ const result = await lb.trigger(HostEvent.Filter, {} as any);
83
+ expect(result).toBeNull();
84
+ expect(handleErrorSpy).toHaveBeenCalledWith(
85
+ expect.objectContaining({ code: EmbedErrorCodes.RENDER_NOT_CALLED }),
86
+ );
87
+ });
88
+ });
89
+
90
+ // ---------------------------------------------------------------------------
91
+ // 8 – UpdateRuntimeFilters
92
+ // ---------------------------------------------------------------------------
93
+ describe('HostEvent.UpdateRuntimeFilters', () => {
94
+ test('postMessage type is UpdateRuntimeFilters (PascalCase)', async () => {
95
+ mockMessageChannel();
96
+ const { lb, iframe } = await renderLiveboard();
97
+ await executeAfterWait(() => {
98
+ lb.trigger(HostEvent.UpdateRuntimeFilters, [] as any);
99
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
100
+ expect.objectContaining({ type: 'UpdateRuntimeFilters' }),
101
+ thoughtSpotHost,
102
+ expect.anything(),
103
+ );
104
+ });
105
+ });
106
+
107
+ test('returns null when !isRendered', async () => {
108
+ const lb = unrenderedLiveboard();
109
+ const result = await lb.trigger(HostEvent.UpdateRuntimeFilters, [] as any);
110
+ expect(result).toBeNull();
111
+ });
112
+
113
+ test('vizId is injected when viewConfig.vizId is set and payload is object', async () => {
114
+ mockMessageChannel();
115
+ const { lb, iframe } = await renderLiveboard({ vizId });
116
+ await executeAfterWait(() => {
117
+ lb.trigger(HostEvent.UpdateRuntimeFilters, [{}] as any);
118
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
119
+ expect.objectContaining({ type: 'UpdateRuntimeFilters' }),
120
+ thoughtSpotHost,
121
+ expect.anything(),
122
+ );
123
+ });
124
+ });
125
+ });
126
+
127
+ // ---------------------------------------------------------------------------
128
+ // 10 – OpenFilter
129
+ // ---------------------------------------------------------------------------
130
+ describe('HostEvent.OpenFilter', () => {
131
+ test('postMessage type is openFilter (camelCase)', async () => {
132
+ mockMessageChannel();
133
+ const { lb, iframe } = await renderLiveboard();
134
+ await executeAfterWait(() => {
135
+ lb.trigger(HostEvent.OpenFilter, { columnId: 'col1' } as any);
136
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
137
+ expect.objectContaining({ type: 'openFilter' }),
138
+ thoughtSpotHost,
139
+ expect.anything(),
140
+ );
141
+ });
142
+ });
143
+
144
+ test('returns null when !isRendered', async () => {
145
+ const lb = unrenderedLiveboard();
146
+ const result = await lb.trigger(HostEvent.OpenFilter, {} as any);
147
+ expect(result).toBeNull();
148
+ });
149
+ });
150
+
151
+ // ---------------------------------------------------------------------------
152
+ // 11 – AddColumns
153
+ // ---------------------------------------------------------------------------
154
+ describe('HostEvent.AddColumns', () => {
155
+ test('postMessage type is addColumns (camelCase)', async () => {
156
+ mockMessageChannel();
157
+ const { lb, iframe } = await renderLiveboard();
158
+ await executeAfterWait(() => {
159
+ lb.trigger(HostEvent.AddColumns, { columnIds: ['c1'] } as any);
160
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
161
+ expect.objectContaining({ type: 'addColumns' }),
162
+ thoughtSpotHost,
163
+ expect.anything(),
164
+ );
165
+ });
166
+ });
167
+
168
+ test('returns null when !isRendered', async () => {
169
+ const lb = unrenderedLiveboard();
170
+ const result = await lb.trigger(HostEvent.AddColumns, {} as any);
171
+ expect(result).toBeNull();
172
+ });
173
+ });
174
+
175
+ // ---------------------------------------------------------------------------
176
+ // 12 – RemoveColumn
177
+ // ---------------------------------------------------------------------------
178
+ describe('HostEvent.RemoveColumn', () => {
179
+ test('postMessage type is removeColumn (camelCase)', async () => {
180
+ mockMessageChannel();
181
+ const { lb, iframe } = await renderLiveboard();
182
+ await executeAfterWait(() => {
183
+ lb.trigger(HostEvent.RemoveColumn, { columnId: 'c1' } as any);
184
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
185
+ expect.objectContaining({ type: 'removeColumn' }),
186
+ thoughtSpotHost,
187
+ expect.anything(),
188
+ );
189
+ });
190
+ });
191
+
192
+ test('returns null when !isRendered', async () => {
193
+ const lb = unrenderedLiveboard();
194
+ const result = await lb.trigger(HostEvent.RemoveColumn, {} as any);
195
+ expect(result).toBeNull();
196
+ });
197
+ });
198
+
199
+ // ---------------------------------------------------------------------------
200
+ // 15 – LiveboardInfo
201
+ // ---------------------------------------------------------------------------
202
+ describe('HostEvent.LiveboardInfo', () => {
203
+ test('postMessage type is pinboardInfo', async () => {
204
+ mockMessageChannel();
205
+ const { lb, iframe } = await renderLiveboard();
206
+ await executeAfterWait(() => {
207
+ lb.trigger(HostEvent.LiveboardInfo);
208
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
209
+ expect.objectContaining({ type: 'pinboardInfo' }),
210
+ thoughtSpotHost,
211
+ expect.anything(),
212
+ );
213
+ });
214
+ });
215
+
216
+ test('returns null when !isRendered', async () => {
217
+ const lb = unrenderedLiveboard();
218
+ const result = await lb.trigger(HostEvent.LiveboardInfo);
219
+ expect(result).toBeNull();
220
+ });
221
+ });
222
+
223
+ // ---------------------------------------------------------------------------
224
+ // 16 – Schedule
225
+ // ---------------------------------------------------------------------------
226
+ describe('HostEvent.Schedule', () => {
227
+ test('postMessage type is subscription', async () => {
228
+ mockMessageChannel();
229
+ const { lb, iframe } = await renderLiveboard();
230
+ await executeAfterWait(() => {
231
+ lb.trigger(HostEvent.Schedule);
232
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
233
+ expect.objectContaining({ type: 'subscription' }),
234
+ thoughtSpotHost,
235
+ expect.anything(),
236
+ );
237
+ });
238
+ });
239
+
240
+ test('returns null when !isRendered', async () => {
241
+ const lb = unrenderedLiveboard();
242
+ const result = await lb.trigger(HostEvent.Schedule);
243
+ expect(result).toBeNull();
244
+ });
245
+ });
246
+
247
+ // ---------------------------------------------------------------------------
248
+ // 17 – SchedulesList
249
+ // ---------------------------------------------------------------------------
250
+ describe('HostEvent.SchedulesList', () => {
251
+ test('postMessage type is schedule-list (hyphenated)', async () => {
252
+ mockMessageChannel();
253
+ const { lb, iframe } = await renderLiveboard();
254
+ await executeAfterWait(() => {
255
+ lb.trigger(HostEvent.SchedulesList);
256
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
257
+ expect.objectContaining({ type: 'schedule-list' }),
258
+ thoughtSpotHost,
259
+ expect.anything(),
260
+ );
261
+ });
262
+ });
263
+
264
+ test('returns null when !isRendered', async () => {
265
+ const lb = unrenderedLiveboard();
266
+ const result = await lb.trigger(HostEvent.SchedulesList);
267
+ expect(result).toBeNull();
268
+ });
269
+ });
270
+
271
+ // ---------------------------------------------------------------------------
272
+ // 18 – ExportTML
273
+ // ---------------------------------------------------------------------------
274
+ describe('HostEvent.ExportTML', () => {
275
+ test('postMessage type is exportTSL (uses TSL abbreviation)', async () => {
276
+ mockMessageChannel();
277
+ const { lb, iframe } = await renderLiveboard();
278
+ await executeAfterWait(() => {
279
+ lb.trigger(HostEvent.ExportTML);
280
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
281
+ expect.objectContaining({ type: 'exportTSL' }),
282
+ thoughtSpotHost,
283
+ expect.anything(),
284
+ );
285
+ });
286
+ });
287
+
288
+ test('returns null when !isRendered', async () => {
289
+ const lb = unrenderedLiveboard();
290
+ const result = await lb.trigger(HostEvent.ExportTML);
291
+ expect(result).toBeNull();
292
+ });
293
+ });
294
+
295
+ // ---------------------------------------------------------------------------
296
+ // 19 – EditTML
297
+ // ---------------------------------------------------------------------------
298
+ describe('HostEvent.EditTML', () => {
299
+ test('postMessage type is editTSL', async () => {
300
+ mockMessageChannel();
301
+ const { lb, iframe } = await renderLiveboard();
302
+ await executeAfterWait(() => {
303
+ lb.trigger(HostEvent.EditTML);
304
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
305
+ expect.objectContaining({ type: 'editTSL' }),
306
+ thoughtSpotHost,
307
+ expect.anything(),
308
+ );
309
+ });
310
+ });
311
+
312
+ test('returns null when !isRendered', async () => {
313
+ const lb = unrenderedLiveboard();
314
+ const result = await lb.trigger(HostEvent.EditTML);
315
+ expect(result).toBeNull();
316
+ });
317
+ });
318
+
319
+ // ---------------------------------------------------------------------------
320
+ // 20 – UpdateTML
321
+ // ---------------------------------------------------------------------------
322
+ describe('HostEvent.UpdateTML', () => {
323
+ test('postMessage type is updateTSL', async () => {
324
+ mockMessageChannel();
325
+ const { lb, iframe } = await renderLiveboard();
326
+ await executeAfterWait(() => {
327
+ lb.trigger(HostEvent.UpdateTML);
328
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
329
+ expect.objectContaining({ type: 'updateTSL' }),
330
+ thoughtSpotHost,
331
+ expect.anything(),
332
+ );
333
+ });
334
+ });
335
+
336
+ test('returns null when !isRendered', async () => {
337
+ const lb = unrenderedLiveboard();
338
+ const result = await lb.trigger(HostEvent.UpdateTML);
339
+ expect(result).toBeNull();
340
+ });
341
+ });
342
+
343
+ // ---------------------------------------------------------------------------
344
+ // 21 – DownloadAsPdf
345
+ // ---------------------------------------------------------------------------
346
+ describe('HostEvent.DownloadAsPdf', () => {
347
+ test('postMessage type is downloadAsPdf (camelCase)', async () => {
348
+ mockMessageChannel();
349
+ const { lb, iframe } = await renderLiveboard();
350
+ await executeAfterWait(() => {
351
+ lb.trigger(HostEvent.DownloadAsPdf);
352
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
353
+ expect.objectContaining({ type: 'downloadAsPdf' }),
354
+ thoughtSpotHost,
355
+ expect.anything(),
356
+ );
357
+ });
358
+ });
359
+
360
+ test('returns null when !isRendered', async () => {
361
+ const lb = unrenderedLiveboard();
362
+ const result = await lb.trigger(HostEvent.DownloadAsPdf);
363
+ expect(result).toBeNull();
364
+ });
365
+ });
366
+
367
+ // ---------------------------------------------------------------------------
368
+ // 22 – DownloadLiveboardAsContinuousPDF
369
+ // ---------------------------------------------------------------------------
370
+ describe('HostEvent.DownloadLiveboardAsContinuousPDF', () => {
371
+ test('postMessage type is downloadLiveboardAsContinuousPDF', async () => {
372
+ mockMessageChannel();
373
+ const { lb, iframe } = await renderLiveboard();
374
+ await executeAfterWait(() => {
375
+ lb.trigger(HostEvent.DownloadLiveboardAsContinuousPDF);
376
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
377
+ expect.objectContaining({ type: 'downloadLiveboardAsContinuousPDF' }),
378
+ thoughtSpotHost,
379
+ expect.anything(),
380
+ );
381
+ });
382
+ });
383
+
384
+ test('returns null when !isRendered', async () => {
385
+ const lb = unrenderedLiveboard();
386
+ const result = await lb.trigger(HostEvent.DownloadLiveboardAsContinuousPDF);
387
+ expect(result).toBeNull();
388
+ });
389
+ });
390
+
391
+ // ---------------------------------------------------------------------------
392
+ // 23 – AIHighlights
393
+ // ---------------------------------------------------------------------------
394
+ describe('HostEvent.AIHighlights', () => {
395
+ test('postMessage type is AIHighlights (PascalCase)', async () => {
396
+ mockMessageChannel();
397
+ const { lb, iframe } = await renderLiveboard();
398
+ await executeAfterWait(() => {
399
+ lb.trigger(HostEvent.AIHighlights);
400
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
401
+ expect.objectContaining({ type: 'AIHighlights' }),
402
+ thoughtSpotHost,
403
+ expect.anything(),
404
+ );
405
+ });
406
+ });
407
+
408
+ test('returns null when !isRendered', async () => {
409
+ const lb = unrenderedLiveboard();
410
+ const result = await lb.trigger(HostEvent.AIHighlights);
411
+ expect(result).toBeNull();
412
+ });
413
+ });
414
+
415
+ // ---------------------------------------------------------------------------
416
+ // 24 – MakeACopy
417
+ // ---------------------------------------------------------------------------
418
+ describe('HostEvent.MakeACopy', () => {
419
+ test('postMessage type is makeACopy (camelCase)', async () => {
420
+ mockMessageChannel();
421
+ const { lb, iframe } = await renderLiveboard();
422
+ await executeAfterWait(() => {
423
+ lb.trigger(HostEvent.MakeACopy);
424
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
425
+ expect.objectContaining({ type: 'makeACopy' }),
426
+ thoughtSpotHost,
427
+ expect.anything(),
428
+ );
429
+ });
430
+ });
431
+
432
+ test('returns null when !isRendered', async () => {
433
+ const lb = unrenderedLiveboard();
434
+ const result = await lb.trigger(HostEvent.MakeACopy);
435
+ expect(result).toBeNull();
436
+ });
437
+ });
438
+
439
+ // ---------------------------------------------------------------------------
440
+ // 25 – Remove (maps to 'delete' string)
441
+ // ---------------------------------------------------------------------------
442
+ describe('HostEvent.Remove', () => {
443
+ test("postMessage type is 'delete' (NOT 'Remove')", async () => {
444
+ mockMessageChannel();
445
+ const { lb, iframe } = await renderLiveboard();
446
+ await executeAfterWait(() => {
447
+ lb.trigger(HostEvent.Remove);
448
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
449
+ expect.objectContaining({ type: 'delete' }),
450
+ thoughtSpotHost,
451
+ expect.anything(),
452
+ );
453
+ });
454
+ });
455
+
456
+ test('returns null when !isRendered', async () => {
457
+ const lb = unrenderedLiveboard();
458
+ const result = await lb.trigger(HostEvent.Remove);
459
+ expect(result).toBeNull();
460
+ });
461
+ });
462
+
463
+ // ---------------------------------------------------------------------------
464
+ // 26 – Explore
465
+ // ---------------------------------------------------------------------------
466
+ describe('HostEvent.Explore', () => {
467
+ test('postMessage type is explore (all lowercase)', async () => {
468
+ mockMessageChannel();
469
+ const { lb, iframe } = await renderLiveboard();
470
+ await executeAfterWait(() => {
471
+ lb.trigger(HostEvent.Explore, { vizId: 'v1' } as any);
472
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
473
+ expect.objectContaining({ type: 'explore' }),
474
+ thoughtSpotHost,
475
+ expect.anything(),
476
+ );
477
+ });
478
+ });
479
+
480
+ test('returns null when !isRendered', async () => {
481
+ const lb = unrenderedLiveboard();
482
+ const result = await lb.trigger(HostEvent.Explore, {} as any);
483
+ expect(result).toBeNull();
484
+ });
485
+ });
486
+
487
+ // ---------------------------------------------------------------------------
488
+ // 27 – CreateMonitor
489
+ // ---------------------------------------------------------------------------
490
+ describe('HostEvent.CreateMonitor', () => {
491
+ test('postMessage type is createMonitor (camelCase)', async () => {
492
+ mockMessageChannel();
493
+ const { lb, iframe } = await renderLiveboard();
494
+ await executeAfterWait(() => {
495
+ lb.trigger(HostEvent.CreateMonitor);
496
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
497
+ expect.objectContaining({ type: 'createMonitor' }),
498
+ thoughtSpotHost,
499
+ expect.anything(),
500
+ );
501
+ });
502
+ });
503
+
504
+ test('returns null when !isRendered', async () => {
505
+ const lb = unrenderedLiveboard();
506
+ const result = await lb.trigger(HostEvent.CreateMonitor);
507
+ expect(result).toBeNull();
508
+ });
509
+ });
510
+
511
+ // ---------------------------------------------------------------------------
512
+ // 28 – ManageMonitor
513
+ // ---------------------------------------------------------------------------
514
+ describe('HostEvent.ManageMonitor', () => {
515
+ test('postMessage type is manageMonitor (camelCase)', async () => {
516
+ mockMessageChannel();
517
+ const { lb, iframe } = await renderLiveboard();
518
+ await executeAfterWait(() => {
519
+ lb.trigger(HostEvent.ManageMonitor);
520
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
521
+ expect.objectContaining({ type: 'manageMonitor' }),
522
+ thoughtSpotHost,
523
+ expect.anything(),
524
+ );
525
+ });
526
+ });
527
+
528
+ test('returns null when !isRendered', async () => {
529
+ const lb = unrenderedLiveboard();
530
+ const result = await lb.trigger(HostEvent.ManageMonitor);
531
+ expect(result).toBeNull();
532
+ });
533
+ });
534
+
535
+ // ---------------------------------------------------------------------------
536
+ // 29 – Edit
537
+ // ---------------------------------------------------------------------------
538
+ describe('HostEvent.Edit', () => {
539
+ test('postMessage type is edit (all lowercase)', async () => {
540
+ mockMessageChannel();
541
+ const { lb, iframe } = await renderLiveboard();
542
+ await executeAfterWait(() => {
543
+ lb.trigger(HostEvent.Edit);
544
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
545
+ expect.objectContaining({ type: 'edit' }),
546
+ thoughtSpotHost,
547
+ expect.anything(),
548
+ );
549
+ });
550
+ });
551
+
552
+ test('returns null when !isRendered', async () => {
553
+ const lb = unrenderedLiveboard();
554
+ const result = await lb.trigger(HostEvent.Edit);
555
+ expect(result).toBeNull();
556
+ });
557
+ });
558
+
559
+ // ---------------------------------------------------------------------------
560
+ // 30 – CopyLink (maps to 'embedDocument')
561
+ // ---------------------------------------------------------------------------
562
+ describe('HostEvent.CopyLink', () => {
563
+ test("postMessage type is 'embedDocument' (NOT 'CopyLink')", async () => {
564
+ mockMessageChannel();
565
+ const { lb, iframe } = await renderLiveboard();
566
+ await executeAfterWait(() => {
567
+ lb.trigger(HostEvent.CopyLink);
568
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
569
+ expect.objectContaining({ type: 'embedDocument' }),
570
+ thoughtSpotHost,
571
+ expect.anything(),
572
+ );
573
+ });
574
+ });
575
+
576
+ test('returns null when !isRendered', async () => {
577
+ const lb = unrenderedLiveboard();
578
+ const result = await lb.trigger(HostEvent.CopyLink);
579
+ expect(result).toBeNull();
580
+ });
581
+ });
582
+
583
+ // ---------------------------------------------------------------------------
584
+ // 33 – ShowUnderlyingData
585
+ // ---------------------------------------------------------------------------
586
+ describe('HostEvent.ShowUnderlyingData', () => {
587
+ test('postMessage type is showUnderlyingData (camelCase)', async () => {
588
+ mockMessageChannel();
589
+ const { lb, iframe } = await renderLiveboard();
590
+ await executeAfterWait(() => {
591
+ lb.trigger(HostEvent.ShowUnderlyingData);
592
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
593
+ expect.objectContaining({ type: 'showUnderlyingData' }),
594
+ thoughtSpotHost,
595
+ expect.anything(),
596
+ );
597
+ });
598
+ });
599
+
600
+ test('returns null when !isRendered', async () => {
601
+ const lb = unrenderedLiveboard();
602
+ const result = await lb.trigger(HostEvent.ShowUnderlyingData);
603
+ expect(result).toBeNull();
604
+ });
605
+ });
606
+
607
+ // ---------------------------------------------------------------------------
608
+ // 34 – Delete (maps to 'onDeleteAnswer')
609
+ // ---------------------------------------------------------------------------
610
+ describe('HostEvent.Delete', () => {
611
+ test("postMessage type is 'onDeleteAnswer' (NOT 'delete' or 'Delete')", async () => {
612
+ mockMessageChannel();
613
+ const { lb, iframe } = await renderLiveboard();
614
+ await executeAfterWait(() => {
615
+ lb.trigger(HostEvent.Delete);
616
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
617
+ expect.objectContaining({ type: 'onDeleteAnswer' }),
618
+ thoughtSpotHost,
619
+ expect.anything(),
620
+ );
621
+ });
622
+ });
623
+
624
+ test('returns null when !isRendered', async () => {
625
+ const lb = unrenderedLiveboard();
626
+ const result = await lb.trigger(HostEvent.Delete);
627
+ expect(result).toBeNull();
628
+ });
629
+ });
630
+
631
+ // ---------------------------------------------------------------------------
632
+ // 35 – SpotIQAnalyze
633
+ // ---------------------------------------------------------------------------
634
+ describe('HostEvent.SpotIQAnalyze', () => {
635
+ test('postMessage type is spotIQAnalyze (camelCase)', async () => {
636
+ mockMessageChannel();
637
+ const { lb, iframe } = await renderLiveboard();
638
+ await executeAfterWait(() => {
639
+ lb.trigger(HostEvent.SpotIQAnalyze);
640
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
641
+ expect.objectContaining({ type: 'spotIQAnalyze' }),
642
+ thoughtSpotHost,
643
+ expect.anything(),
644
+ );
645
+ });
646
+ });
647
+
648
+ test('returns null when !isRendered', async () => {
649
+ const lb = unrenderedLiveboard();
650
+ const result = await lb.trigger(HostEvent.SpotIQAnalyze);
651
+ expect(result).toBeNull();
652
+ });
653
+ });
654
+
655
+ // ---------------------------------------------------------------------------
656
+ // 36 – Download (maps to 'downloadAsPng', same as DownloadAsPng)
657
+ // ---------------------------------------------------------------------------
658
+ describe('HostEvent.Download', () => {
659
+ test("postMessage type is 'downloadAsPng' (same string as DownloadAsPng)", async () => {
660
+ mockMessageChannel();
661
+ const { lb, iframe } = await renderLiveboard();
662
+ await executeAfterWait(() => {
663
+ lb.trigger(HostEvent.Download);
664
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
665
+ expect.objectContaining({ type: 'downloadAsPng' }),
666
+ thoughtSpotHost,
667
+ expect.anything(),
668
+ );
669
+ });
670
+ });
671
+
672
+ test('Download and DownloadAsPng share the identical string value', () => {
673
+ expect(HostEvent.Download).toBe(HostEvent.DownloadAsPng);
674
+ });
675
+
676
+ test('returns null when !isRendered', async () => {
677
+ const lb = unrenderedLiveboard();
678
+ const result = await lb.trigger(HostEvent.Download);
679
+ expect(result).toBeNull();
680
+ });
681
+ });
682
+
683
+ // ---------------------------------------------------------------------------
684
+ // 37 – DownloadAsPng
685
+ // ---------------------------------------------------------------------------
686
+ describe('HostEvent.DownloadAsPng', () => {
687
+ test('postMessage type is downloadAsPng', async () => {
688
+ mockMessageChannel();
689
+ const { lb, iframe } = await renderLiveboard();
690
+ await executeAfterWait(() => {
691
+ lb.trigger(HostEvent.DownloadAsPng);
692
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
693
+ expect.objectContaining({ type: 'downloadAsPng' }),
694
+ thoughtSpotHost,
695
+ expect.anything(),
696
+ );
697
+ });
698
+ });
699
+
700
+ test('returns null when !isRendered', async () => {
701
+ const lb = unrenderedLiveboard();
702
+ const result = await lb.trigger(HostEvent.DownloadAsPng);
703
+ expect(result).toBeNull();
704
+ });
705
+ });
706
+
707
+ // ---------------------------------------------------------------------------
708
+ // 39 – DownloadAsXlsx
709
+ // ---------------------------------------------------------------------------
710
+ describe('HostEvent.DownloadAsXlsx', () => {
711
+ test('postMessage type is downloadAsXLSX (capital X-L-S-X)', async () => {
712
+ mockMessageChannel();
713
+ const { lb, iframe } = await renderLiveboard();
714
+ await executeAfterWait(() => {
715
+ lb.trigger(HostEvent.DownloadAsXlsx);
716
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
717
+ expect.objectContaining({ type: 'downloadAsXLSX' }),
718
+ thoughtSpotHost,
719
+ expect.anything(),
720
+ );
721
+ });
722
+ });
723
+
724
+ test('returns null when !isRendered', async () => {
725
+ const lb = unrenderedLiveboard();
726
+ const result = await lb.trigger(HostEvent.DownloadAsXlsx);
727
+ expect(result).toBeNull();
728
+ });
729
+ });
730
+
731
+ // ---------------------------------------------------------------------------
732
+ // 40 – Share
733
+ // ---------------------------------------------------------------------------
734
+ describe('HostEvent.Share', () => {
735
+ test('postMessage type is share (all lowercase)', async () => {
736
+ mockMessageChannel();
737
+ const { lb, iframe } = await renderLiveboard();
738
+ await executeAfterWait(() => {
739
+ lb.trigger(HostEvent.Share);
740
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
741
+ expect.objectContaining({ type: 'share' }),
742
+ thoughtSpotHost,
743
+ expect.anything(),
744
+ );
745
+ });
746
+ });
747
+
748
+ test('returns null when !isRendered', async () => {
749
+ const lb = unrenderedLiveboard();
750
+ const result = await lb.trigger(HostEvent.Share);
751
+ expect(result).toBeNull();
752
+ });
753
+ });
754
+
755
+ // ---------------------------------------------------------------------------
756
+ // 42 – SyncToSheets
757
+ // ---------------------------------------------------------------------------
758
+ describe('HostEvent.SyncToSheets', () => {
759
+ test('postMessage type is sync-to-sheets (hyphenated, all lowercase)', async () => {
760
+ mockMessageChannel();
761
+ const { lb, iframe } = await renderLiveboard();
762
+ await executeAfterWait(() => {
763
+ lb.trigger(HostEvent.SyncToSheets);
764
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
765
+ expect.objectContaining({ type: 'sync-to-sheets' }),
766
+ thoughtSpotHost,
767
+ expect.anything(),
768
+ );
769
+ });
770
+ });
771
+
772
+ test('returns null when !isRendered', async () => {
773
+ const lb = unrenderedLiveboard();
774
+ const result = await lb.trigger(HostEvent.SyncToSheets);
775
+ expect(result).toBeNull();
776
+ });
777
+ });
778
+
779
+ // ---------------------------------------------------------------------------
780
+ // 43 – SyncToOtherApps
781
+ // ---------------------------------------------------------------------------
782
+ describe('HostEvent.SyncToOtherApps', () => {
783
+ test('postMessage type is sync-to-other-apps (hyphenated)', async () => {
784
+ mockMessageChannel();
785
+ const { lb, iframe } = await renderLiveboard();
786
+ await executeAfterWait(() => {
787
+ lb.trigger(HostEvent.SyncToOtherApps);
788
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
789
+ expect.objectContaining({ type: 'sync-to-other-apps' }),
790
+ thoughtSpotHost,
791
+ expect.anything(),
792
+ );
793
+ });
794
+ });
795
+
796
+ test('returns null when !isRendered', async () => {
797
+ const lb = unrenderedLiveboard();
798
+ const result = await lb.trigger(HostEvent.SyncToOtherApps);
799
+ expect(result).toBeNull();
800
+ });
801
+ });
802
+
803
+ // ---------------------------------------------------------------------------
804
+ // 44 – ManagePipelines
805
+ // ---------------------------------------------------------------------------
806
+ describe('HostEvent.ManagePipelines', () => {
807
+ test("postMessage type is 'manage-pipeline' (singular, hyphenated)", async () => {
808
+ mockMessageChannel();
809
+ const { lb, iframe } = await renderLiveboard();
810
+ await executeAfterWait(() => {
811
+ lb.trigger(HostEvent.ManagePipelines);
812
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
813
+ expect.objectContaining({ type: 'manage-pipeline' }),
814
+ thoughtSpotHost,
815
+ expect.anything(),
816
+ );
817
+ });
818
+ });
819
+
820
+ test('returns null when !isRendered', async () => {
821
+ const lb = unrenderedLiveboard();
822
+ const result = await lb.trigger(HostEvent.ManagePipelines);
823
+ expect(result).toBeNull();
824
+ });
825
+ });
826
+
827
+ // ---------------------------------------------------------------------------
828
+ // 45 – ResetSearch
829
+ // ---------------------------------------------------------------------------
830
+ describe('HostEvent.ResetSearch', () => {
831
+ test('postMessage type is resetSearch (camelCase)', async () => {
832
+ mockMessageChannel();
833
+ const { lb, iframe } = await renderLiveboard();
834
+ await executeAfterWait(() => {
835
+ lb.trigger(HostEvent.ResetSearch);
836
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
837
+ expect.objectContaining({ type: 'resetSearch' }),
838
+ thoughtSpotHost,
839
+ expect.anything(),
840
+ );
841
+ });
842
+ });
843
+
844
+ test('returns null when !isRendered', async () => {
845
+ const lb = unrenderedLiveboard();
846
+ const result = await lb.trigger(HostEvent.ResetSearch);
847
+ expect(result).toBeNull();
848
+ });
849
+ });
850
+
851
+ // ---------------------------------------------------------------------------
852
+ // 49 – SetVisibleTabs
853
+ // ---------------------------------------------------------------------------
854
+ describe('HostEvent.SetVisibleTabs', () => {
855
+ test("postMessage type is 'SetPinboardVisibleTabs' (NOT 'SetVisibleTabs')", async () => {
856
+ mockMessageChannel();
857
+ const { lb, iframe } = await renderLiveboard();
858
+ await executeAfterWait(() => {
859
+ lb.trigger(HostEvent.SetVisibleTabs, ['tab1'] as any);
860
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
861
+ expect.objectContaining({ type: 'SetPinboardVisibleTabs' }),
862
+ thoughtSpotHost,
863
+ expect.anything(),
864
+ );
865
+ });
866
+ });
867
+
868
+ test('returns null when !isRendered', async () => {
869
+ const lb = unrenderedLiveboard();
870
+ const result = await lb.trigger(HostEvent.SetVisibleTabs, [] as any);
871
+ expect(result).toBeNull();
872
+ });
873
+ });
874
+
875
+ // ---------------------------------------------------------------------------
876
+ // 50 – SetHiddenTabs
877
+ // ---------------------------------------------------------------------------
878
+ describe('HostEvent.SetHiddenTabs', () => {
879
+ test("postMessage type is 'SetPinboardHiddenTabs' (NOT 'SetHiddenTabs')", async () => {
880
+ mockMessageChannel();
881
+ const { lb, iframe } = await renderLiveboard();
882
+ await executeAfterWait(() => {
883
+ lb.trigger(HostEvent.SetHiddenTabs, ['tab1'] as any);
884
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
885
+ expect.objectContaining({ type: 'SetPinboardHiddenTabs' }),
886
+ thoughtSpotHost,
887
+ expect.anything(),
888
+ );
889
+ });
890
+ });
891
+
892
+ test('returns null when !isRendered', async () => {
893
+ const lb = unrenderedLiveboard();
894
+ const result = await lb.trigger(HostEvent.SetHiddenTabs, [] as any);
895
+ expect(result).toBeNull();
896
+ });
897
+ });
898
+
899
+ // ---------------------------------------------------------------------------
900
+ // 52 – AskSage
901
+ // ---------------------------------------------------------------------------
902
+ describe('HostEvent.AskSage', () => {
903
+ test('postMessage type is AskSage (PascalCase)', async () => {
904
+ mockMessageChannel();
905
+ const { lb, iframe } = await renderLiveboard();
906
+ await executeAfterWait(() => {
907
+ lb.trigger(HostEvent.AskSage);
908
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
909
+ expect.objectContaining({ type: 'AskSage' }),
910
+ thoughtSpotHost,
911
+ expect.anything(),
912
+ );
913
+ });
914
+ });
915
+
916
+ test('returns null when !isRendered', async () => {
917
+ const lb = unrenderedLiveboard();
918
+ const result = await lb.trigger(HostEvent.AskSage);
919
+ expect(result).toBeNull();
920
+ });
921
+ });
922
+
923
+ // ---------------------------------------------------------------------------
924
+ // 53 – UpdateCrossFilter
925
+ // ---------------------------------------------------------------------------
926
+ describe('HostEvent.UpdateCrossFilter', () => {
927
+ test('postMessage type is UpdateCrossFilter (PascalCase)', async () => {
928
+ mockMessageChannel();
929
+ const { lb, iframe } = await renderLiveboard();
930
+ await executeAfterWait(() => {
931
+ lb.trigger(HostEvent.UpdateCrossFilter, {} as any);
932
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
933
+ expect.objectContaining({ type: 'UpdateCrossFilter' }),
934
+ thoughtSpotHost,
935
+ expect.anything(),
936
+ );
937
+ });
938
+ });
939
+
940
+ test('returns null when !isRendered', async () => {
941
+ const lb = unrenderedLiveboard();
942
+ const result = await lb.trigger(HostEvent.UpdateCrossFilter, {} as any);
943
+ expect(result).toBeNull();
944
+ });
945
+ });
946
+
947
+ // ---------------------------------------------------------------------------
948
+ // 56 – UpdateParameters
949
+ // ---------------------------------------------------------------------------
950
+ describe('HostEvent.UpdateParameters', () => {
951
+ test('postMessage type is UpdateParameters (PascalCase)', async () => {
952
+ mockMessageChannel();
953
+ const { lb, iframe } = await renderLiveboard();
954
+ await executeAfterWait(() => {
955
+ lb.trigger(HostEvent.UpdateParameters, {} as any);
956
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
957
+ expect.objectContaining({ type: 'UpdateParameters' }),
958
+ thoughtSpotHost,
959
+ expect.anything(),
960
+ );
961
+ });
962
+ });
963
+
964
+ test('returns null when !isRendered', async () => {
965
+ const lb = unrenderedLiveboard();
966
+ const result = await lb.trigger(HostEvent.UpdateParameters, {} as any);
967
+ expect(result).toBeNull();
968
+ });
969
+ });
970
+
971
+ // ---------------------------------------------------------------------------
972
+ // 60 – SelectPersonalizedView (maps to British spelling)
973
+ // ---------------------------------------------------------------------------
974
+ describe('HostEvent.SelectPersonalizedView', () => {
975
+ test("postMessage type is 'SelectPersonalisedView' (British spelling)", async () => {
976
+ mockMessageChannel();
977
+ const { lb, iframe } = await renderLiveboard();
978
+ await executeAfterWait(() => {
979
+ lb.trigger(HostEvent.SelectPersonalizedView, {} as any);
980
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
981
+ expect.objectContaining({ type: 'SelectPersonalisedView' }),
982
+ thoughtSpotHost,
983
+ expect.anything(),
984
+ );
985
+ });
986
+ });
987
+
988
+ test('returns null when !isRendered', async () => {
989
+ const lb = unrenderedLiveboard();
990
+ const result = await lb.trigger(HostEvent.SelectPersonalizedView, {} as any);
991
+ expect(result).toBeNull();
992
+ });
993
+ });
994
+
995
+ // ---------------------------------------------------------------------------
996
+ // 64 – TransformTableVizData
997
+ // ---------------------------------------------------------------------------
998
+ describe('HostEvent.TransformTableVizData', () => {
999
+ test('postMessage type is TransformTableVizData (PascalCase)', async () => {
1000
+ mockMessageChannel();
1001
+ const { lb, iframe } = await renderLiveboard();
1002
+ await executeAfterWait(() => {
1003
+ lb.trigger(HostEvent.TransformTableVizData, {} as any);
1004
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1005
+ expect.objectContaining({ type: 'TransformTableVizData' }),
1006
+ thoughtSpotHost,
1007
+ expect.anything(),
1008
+ );
1009
+ });
1010
+ });
1011
+
1012
+ test('returns null when !isRendered', async () => {
1013
+ const lb = unrenderedLiveboard();
1014
+ const result = await lb.trigger(HostEvent.TransformTableVizData, {} as any);
1015
+ expect(result).toBeNull();
1016
+ });
1017
+ });
1018
+
1019
+ // ---------------------------------------------------------------------------
1020
+ // 65 – SpotterSearch
1021
+ // ---------------------------------------------------------------------------
1022
+ describe('HostEvent.SpotterSearch', () => {
1023
+ test('postMessage type is SpotterSearch (PascalCase)', async () => {
1024
+ mockMessageChannel();
1025
+ const { lb, iframe } = await renderLiveboard();
1026
+ await executeAfterWait(() => {
1027
+ lb.trigger(HostEvent.SpotterSearch, {} as any);
1028
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1029
+ expect.objectContaining({ type: 'SpotterSearch' }),
1030
+ thoughtSpotHost,
1031
+ expect.anything(),
1032
+ );
1033
+ });
1034
+ });
1035
+
1036
+ test('returns null when !isRendered', async () => {
1037
+ const lb = unrenderedLiveboard();
1038
+ const result = await lb.trigger(HostEvent.SpotterSearch, {} as any);
1039
+ expect(result).toBeNull();
1040
+ });
1041
+ });
1042
+
1043
+ // ---------------------------------------------------------------------------
1044
+ // 66 – EditLastPrompt
1045
+ // ---------------------------------------------------------------------------
1046
+ describe('HostEvent.EditLastPrompt', () => {
1047
+ test('postMessage type is EditLastPrompt (PascalCase)', async () => {
1048
+ mockMessageChannel();
1049
+ const { lb, iframe } = await renderLiveboard();
1050
+ await executeAfterWait(() => {
1051
+ lb.trigger(HostEvent.EditLastPrompt, {} as any);
1052
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1053
+ expect.objectContaining({ type: 'EditLastPrompt' }),
1054
+ thoughtSpotHost,
1055
+ expect.anything(),
1056
+ );
1057
+ });
1058
+ });
1059
+
1060
+ test('returns null when !isRendered', async () => {
1061
+ const lb = unrenderedLiveboard();
1062
+ const result = await lb.trigger(HostEvent.EditLastPrompt, {} as any);
1063
+ expect(result).toBeNull();
1064
+ });
1065
+ });
1066
+
1067
+ // ---------------------------------------------------------------------------
1068
+ // 67 – PreviewSpotterData
1069
+ // ---------------------------------------------------------------------------
1070
+ describe('HostEvent.PreviewSpotterData', () => {
1071
+ test('postMessage type is PreviewSpotterData (PascalCase)', async () => {
1072
+ mockMessageChannel();
1073
+ const { lb, iframe } = await renderLiveboard();
1074
+ await executeAfterWait(() => {
1075
+ lb.trigger(HostEvent.PreviewSpotterData, {} as any);
1076
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1077
+ expect.objectContaining({ type: 'PreviewSpotterData' }),
1078
+ thoughtSpotHost,
1079
+ expect.anything(),
1080
+ );
1081
+ });
1082
+ });
1083
+
1084
+ test('returns null when !isRendered', async () => {
1085
+ const lb = unrenderedLiveboard();
1086
+ const result = await lb.trigger(HostEvent.PreviewSpotterData, {} as any);
1087
+ expect(result).toBeNull();
1088
+ });
1089
+ });
1090
+
1091
+ // ---------------------------------------------------------------------------
1092
+ // 68 – AddToCoaching
1093
+ // ---------------------------------------------------------------------------
1094
+ describe('HostEvent.AddToCoaching', () => {
1095
+ test('postMessage type is addToCoaching (camelCase)', async () => {
1096
+ mockMessageChannel();
1097
+ const { lb, iframe } = await renderLiveboard();
1098
+ await executeAfterWait(() => {
1099
+ lb.trigger(HostEvent.AddToCoaching, {} as any);
1100
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1101
+ expect.objectContaining({ type: 'addToCoaching' }),
1102
+ thoughtSpotHost,
1103
+ expect.anything(),
1104
+ );
1105
+ });
1106
+ });
1107
+
1108
+ test('returns null when !isRendered', async () => {
1109
+ const lb = unrenderedLiveboard();
1110
+ const result = await lb.trigger(HostEvent.AddToCoaching, {} as any);
1111
+ expect(result).toBeNull();
1112
+ });
1113
+ });
1114
+
1115
+ // ---------------------------------------------------------------------------
1116
+ // 69 – DataModelInstructions
1117
+ // ---------------------------------------------------------------------------
1118
+ describe('HostEvent.DataModelInstructions', () => {
1119
+ test('postMessage type is DataModelInstructions (PascalCase)', async () => {
1120
+ mockMessageChannel();
1121
+ const { lb, iframe } = await renderLiveboard();
1122
+ await executeAfterWait(() => {
1123
+ lb.trigger(HostEvent.DataModelInstructions, {} as any);
1124
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1125
+ expect.objectContaining({ type: 'DataModelInstructions' }),
1126
+ thoughtSpotHost,
1127
+ expect.anything(),
1128
+ );
1129
+ });
1130
+ });
1131
+
1132
+ test('returns null when !isRendered', async () => {
1133
+ const lb = unrenderedLiveboard();
1134
+ const result = await lb.trigger(HostEvent.DataModelInstructions, {} as any);
1135
+ expect(result).toBeNull();
1136
+ });
1137
+ });
1138
+
1139
+ // ---------------------------------------------------------------------------
1140
+ // 70 – ResetSpotterConversation
1141
+ // ---------------------------------------------------------------------------
1142
+ describe('HostEvent.ResetSpotterConversation', () => {
1143
+ test('postMessage type is ResetSpotterConversation (PascalCase)', async () => {
1144
+ mockMessageChannel();
1145
+ const { lb, iframe } = await renderLiveboard();
1146
+ await executeAfterWait(() => {
1147
+ lb.trigger(HostEvent.ResetSpotterConversation, {} as any);
1148
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1149
+ expect.objectContaining({ type: 'ResetSpotterConversation' }),
1150
+ thoughtSpotHost,
1151
+ expect.anything(),
1152
+ );
1153
+ });
1154
+ });
1155
+
1156
+ test('returns null when !isRendered', async () => {
1157
+ const lb = unrenderedLiveboard();
1158
+ const result = await lb.trigger(HostEvent.ResetSpotterConversation, {} as any);
1159
+ expect(result).toBeNull();
1160
+ });
1161
+ });
1162
+
1163
+ // ---------------------------------------------------------------------------
1164
+ // 71 – DeleteLastPrompt
1165
+ // ---------------------------------------------------------------------------
1166
+ describe('HostEvent.DeleteLastPrompt', () => {
1167
+ test('postMessage type is DeleteLastPrompt (PascalCase)', async () => {
1168
+ mockMessageChannel();
1169
+ const { lb, iframe } = await renderLiveboard();
1170
+ await executeAfterWait(() => {
1171
+ lb.trigger(HostEvent.DeleteLastPrompt, {} as any);
1172
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1173
+ expect.objectContaining({ type: 'DeleteLastPrompt' }),
1174
+ thoughtSpotHost,
1175
+ expect.anything(),
1176
+ );
1177
+ });
1178
+ });
1179
+
1180
+ test('returns null when !isRendered', async () => {
1181
+ const lb = unrenderedLiveboard();
1182
+ const result = await lb.trigger(HostEvent.DeleteLastPrompt, {} as any);
1183
+ expect(result).toBeNull();
1184
+ });
1185
+ });
1186
+
1187
+ // ---------------------------------------------------------------------------
1188
+ // 72 – AnswerChartSwitcher
1189
+ // ---------------------------------------------------------------------------
1190
+ describe('HostEvent.AnswerChartSwitcher', () => {
1191
+ test('postMessage type is answerChartSwitcher (camelCase)', async () => {
1192
+ mockMessageChannel();
1193
+ const { lb, iframe } = await renderLiveboard();
1194
+ await executeAfterWait(() => {
1195
+ lb.trigger(HostEvent.AnswerChartSwitcher, {} as any);
1196
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1197
+ expect.objectContaining({ type: 'answerChartSwitcher' }),
1198
+ thoughtSpotHost,
1199
+ expect.anything(),
1200
+ );
1201
+ });
1202
+ });
1203
+
1204
+ test('returns null when !isRendered', async () => {
1205
+ const lb = unrenderedLiveboard();
1206
+ const result = await lb.trigger(HostEvent.AnswerChartSwitcher, {} as any);
1207
+ expect(result).toBeNull();
1208
+ });
1209
+ });
1210
+
1211
+ // ---------------------------------------------------------------------------
1212
+ // 75 – AskSpotter
1213
+ // ---------------------------------------------------------------------------
1214
+ describe('HostEvent.AskSpotter', () => {
1215
+ test('postMessage type is AskSpotter (PascalCase)', async () => {
1216
+ mockMessageChannel();
1217
+ const { lb, iframe } = await renderLiveboard();
1218
+ await executeAfterWait(() => {
1219
+ lb.trigger(HostEvent.AskSpotter, {} as any);
1220
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1221
+ expect.objectContaining({ type: 'AskSpotter' }),
1222
+ thoughtSpotHost,
1223
+ expect.anything(),
1224
+ );
1225
+ });
1226
+ });
1227
+
1228
+ test('returns null when !isRendered', async () => {
1229
+ const lb = unrenderedLiveboard();
1230
+ const result = await lb.trigger(HostEvent.AskSpotter, {} as any);
1231
+ expect(result).toBeNull();
1232
+ });
1233
+ });
1234
+
1235
+ // ---------------------------------------------------------------------------
1236
+ // 78 – StartNewSpotterConversation
1237
+ // ---------------------------------------------------------------------------
1238
+ describe('HostEvent.StartNewSpotterConversation', () => {
1239
+ test('postMessage type is StartNewSpotterConversation (PascalCase)', async () => {
1240
+ mockMessageChannel();
1241
+ const { lb, iframe } = await renderLiveboard();
1242
+ await executeAfterWait(() => {
1243
+ lb.trigger(HostEvent.StartNewSpotterConversation, {} as any);
1244
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1245
+ expect.objectContaining({ type: 'StartNewSpotterConversation' }),
1246
+ thoughtSpotHost,
1247
+ expect.anything(),
1248
+ );
1249
+ });
1250
+ });
1251
+
1252
+ test('returns null when !isRendered', async () => {
1253
+ const lb = unrenderedLiveboard();
1254
+ const result = await lb.trigger(HostEvent.StartNewSpotterConversation, {} as any);
1255
+ expect(result).toBeNull();
1256
+ });
1257
+ });
1258
+
1259
+ // ---------------------------------------------------------------------------
1260
+ // 80 – SendTestScheduleEmail
1261
+ // ---------------------------------------------------------------------------
1262
+ describe('HostEvent.SendTestScheduleEmail', () => {
1263
+ test('postMessage type is sendTestScheduleEmail (camelCase)', async () => {
1264
+ mockMessageChannel();
1265
+ const { lb, iframe } = await renderLiveboard();
1266
+ await executeAfterWait(() => {
1267
+ lb.trigger(HostEvent.SendTestScheduleEmail, {} as any);
1268
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1269
+ expect.objectContaining({ type: 'sendTestScheduleEmail' }),
1270
+ thoughtSpotHost,
1271
+ expect.anything(),
1272
+ );
1273
+ });
1274
+ });
1275
+
1276
+ test('returns null when !isRendered', async () => {
1277
+ const lb = unrenderedLiveboard();
1278
+ const result = await lb.trigger(HostEvent.SendTestScheduleEmail, {} as any);
1279
+ expect(result).toBeNull();
1280
+ });
1281
+ });
1282
+
1283
+ // ---------------------------------------------------------------------------
1284
+ // 81 – SpotterVizSendUserMessage
1285
+ // ---------------------------------------------------------------------------
1286
+ describe('HostEvent.SpotterVizSendUserMessage', () => {
1287
+ test('postMessage type is SpotterVizSendUserMessage (PascalCase)', async () => {
1288
+ mockMessageChannel();
1289
+ const { lb, iframe } = await renderLiveboard();
1290
+ await executeAfterWait(() => {
1291
+ lb.trigger(HostEvent.SpotterVizSendUserMessage, {} as any);
1292
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1293
+ expect.objectContaining({ type: 'SpotterVizSendUserMessage' }),
1294
+ thoughtSpotHost,
1295
+ expect.anything(),
1296
+ );
1297
+ });
1298
+ });
1299
+
1300
+ test('returns null when !isRendered', async () => {
1301
+ const lb = unrenderedLiveboard();
1302
+ const result = await lb.trigger(HostEvent.SpotterVizSendUserMessage, {} as any);
1303
+ expect(result).toBeNull();
1304
+ });
1305
+ });
1306
+
1307
+ // ---------------------------------------------------------------------------
1308
+ // 82 – InitSpotterVizConversation
1309
+ // ---------------------------------------------------------------------------
1310
+ describe('HostEvent.InitSpotterVizConversation', () => {
1311
+ test('postMessage type is InitSpotterVizConversation (PascalCase)', async () => {
1312
+ mockMessageChannel();
1313
+ const { lb, iframe } = await renderLiveboard();
1314
+ await executeAfterWait(() => {
1315
+ lb.trigger(HostEvent.InitSpotterVizConversation, {} as any);
1316
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1317
+ expect.objectContaining({ type: 'InitSpotterVizConversation' }),
1318
+ thoughtSpotHost,
1319
+ expect.anything(),
1320
+ );
1321
+ });
1322
+ });
1323
+
1324
+ test('returns null when !isRendered', async () => {
1325
+ const lb = unrenderedLiveboard();
1326
+ const result = await lb.trigger(HostEvent.InitSpotterVizConversation, {} as any);
1327
+ expect(result).toBeNull();
1328
+ });
1329
+ });
1330
+
1331
+ // ---------------------------------------------------------------------------
1332
+ // 83 – RefreshLiveboardBrowserCache
1333
+ // ---------------------------------------------------------------------------
1334
+ describe('HostEvent.RefreshLiveboardBrowserCache', () => {
1335
+ test('postMessage type is refreshLiveboardBrowserCache (camelCase)', async () => {
1336
+ mockMessageChannel();
1337
+ const { lb, iframe } = await renderLiveboard();
1338
+ await executeAfterWait(() => {
1339
+ lb.trigger(HostEvent.RefreshLiveboardBrowserCache, {} as any);
1340
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1341
+ expect.objectContaining({ type: 'refreshLiveboardBrowserCache' }),
1342
+ thoughtSpotHost,
1343
+ expect.anything(),
1344
+ );
1345
+ });
1346
+ });
1347
+
1348
+ test('returns null when !isRendered', async () => {
1349
+ const lb = unrenderedLiveboard();
1350
+ const result = await lb.trigger(HostEvent.RefreshLiveboardBrowserCache, {} as any);
1351
+ expect(result).toBeNull();
1352
+ });
1353
+ });
1354
+
1355
+ // ---------------------------------------------------------------------------
1356
+ // vizId injection tests — verifies LiveboardEmbed injects viewConfig.vizId
1357
+ // ---------------------------------------------------------------------------
1358
+ describe('vizId injection on LiveboardEmbed trigger (object payload)', () => {
1359
+ const eventsWithVizId: Array<[string, HostEvent, any]> = [
1360
+ ['Filter', HostEvent.Filter, { columnName: 'c' }],
1361
+ ['OpenFilter', HostEvent.OpenFilter, { columnId: 'c1' }],
1362
+ ['AddColumns', HostEvent.AddColumns, { columnIds: ['c1'] }],
1363
+ ['RemoveColumn', HostEvent.RemoveColumn, { columnId: 'c1' }],
1364
+ ['LiveboardInfo', HostEvent.LiveboardInfo, {}],
1365
+ ['Schedule', HostEvent.Schedule, {}],
1366
+ ['SchedulesList', HostEvent.SchedulesList, {}],
1367
+ ['ExportTML', HostEvent.ExportTML, {}],
1368
+ ['EditTML', HostEvent.EditTML, {}],
1369
+ ['UpdateTML', HostEvent.UpdateTML, {}],
1370
+ ['DownloadAsPdf', HostEvent.DownloadAsPdf, {}],
1371
+ ['DownloadLiveboardAsContinuousPDF', HostEvent.DownloadLiveboardAsContinuousPDF, {}],
1372
+ ['AIHighlights', HostEvent.AIHighlights, {}],
1373
+ ['MakeACopy', HostEvent.MakeACopy, {}],
1374
+ ['Remove', HostEvent.Remove, {}],
1375
+ ['Explore', HostEvent.Explore, {}],
1376
+ ['CreateMonitor', HostEvent.CreateMonitor, {}],
1377
+ ['ManageMonitor', HostEvent.ManageMonitor, {}],
1378
+ ['Edit', HostEvent.Edit, {}],
1379
+ ['CopyLink', HostEvent.CopyLink, {}],
1380
+ ['ShowUnderlyingData', HostEvent.ShowUnderlyingData, {}],
1381
+ ['Delete', HostEvent.Delete, {}],
1382
+ ['SpotIQAnalyze', HostEvent.SpotIQAnalyze, {}],
1383
+ ['Download', HostEvent.Download, {}],
1384
+ ['DownloadAsPng', HostEvent.DownloadAsPng, {}],
1385
+ ['DownloadAsXlsx', HostEvent.DownloadAsXlsx, {}],
1386
+ ['Share', HostEvent.Share, {}],
1387
+ ['SyncToSheets', HostEvent.SyncToSheets, {}],
1388
+ ['SyncToOtherApps', HostEvent.SyncToOtherApps, {}],
1389
+ ['ManagePipelines', HostEvent.ManagePipelines, {}],
1390
+ ['SelectPersonalizedView', HostEvent.SelectPersonalizedView, {}],
1391
+ ['UpdateCrossFilter', HostEvent.UpdateCrossFilter, {}],
1392
+ ['UpdateParameters', HostEvent.UpdateParameters, {}],
1393
+ ['TransformTableVizData', HostEvent.TransformTableVizData, {}],
1394
+ ['PreviewSpotterData', HostEvent.PreviewSpotterData, {}],
1395
+ ['AnswerChartSwitcher', HostEvent.AnswerChartSwitcher, {}],
1396
+ ];
1397
+
1398
+ test.each(eventsWithVizId)(
1399
+ '%s: viewConfig.vizId is injected into the payload as data.vizId',
1400
+ async (name, event, payload) => {
1401
+ mockMessageChannel();
1402
+ const { lb, iframe } = await renderLiveboard({ vizId });
1403
+ await executeAfterWait(() => {
1404
+ lb.trigger(event, payload as any);
1405
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1406
+ expect.objectContaining({
1407
+ data: expect.objectContaining({ vizId }),
1408
+ }),
1409
+ thoughtSpotHost,
1410
+ expect.anything(),
1411
+ );
1412
+ });
1413
+ },
1414
+ );
1415
+ });
1416
+
1417
+ // ---------------------------------------------------------------------------
1418
+ // Array payload vizId injection — vizId added as a non-indexed property on the
1419
+ // array object (array.length remains unchanged)
1420
+ // ---------------------------------------------------------------------------
1421
+ describe('vizId injection on LiveboardEmbed trigger (array payload)', () => {
1422
+ const arrayEvents: Array<[string, HostEvent]> = [
1423
+ ['UpdateRuntimeFilters', HostEvent.UpdateRuntimeFilters],
1424
+ ['SetVisibleTabs', HostEvent.SetVisibleTabs],
1425
+ ['SetHiddenTabs', HostEvent.SetHiddenTabs],
1426
+ ];
1427
+
1428
+ test.each(arrayEvents)(
1429
+ '%s: vizId is added as a non-indexed property on the array — array.length unchanged',
1430
+ async (name, event) => {
1431
+ mockMessageChannel();
1432
+ const { lb, iframe } = await renderLiveboard({ vizId });
1433
+ const arrayPayload = ['item1', 'item2'];
1434
+ await executeAfterWait(() => {
1435
+ lb.trigger(event, arrayPayload as any);
1436
+ const call = (iframe.contentWindow.postMessage as jest.Mock).mock.calls[0];
1437
+ const sentData = call[0].data;
1438
+ // vizId is set as a property directly on the array object
1439
+ expect((sentData as any).vizId).toBe(vizId);
1440
+ // array.length is unchanged
1441
+ expect(sentData.length).toBe(2);
1442
+ });
1443
+ },
1444
+ );
1445
+
1446
+ test.each(arrayEvents)(
1447
+ '%s: without viewConfig.vizId — array payload is sent as-is (no vizId property)',
1448
+ async (name, event) => {
1449
+ mockMessageChannel();
1450
+ const { lb, iframe } = await renderLiveboard(); // no vizId
1451
+ const arrayPayload = ['item1'];
1452
+ await executeAfterWait(() => {
1453
+ lb.trigger(event, arrayPayload as any);
1454
+ const call = (iframe.contentWindow.postMessage as jest.Mock).mock.calls[0];
1455
+ const sentData = call[0].data;
1456
+ expect((sentData as any).vizId).toBeUndefined();
1457
+ });
1458
+ },
1459
+ );
1460
+ });
1461
+
1462
+ // ---------------------------------------------------------------------------
1463
+ // UpdateRuntimeFilters — without vizId, array payload sent as-is
1464
+ // ---------------------------------------------------------------------------
1465
+ describe('HostEvent.UpdateRuntimeFilters — additional cases', () => {
1466
+ test('without viewConfig.vizId — RuntimeFilter array payload sent as-is', async () => {
1467
+ mockMessageChannel();
1468
+ const { lb, iframe } = await renderLiveboard(); // no vizId
1469
+ const filters = [{ columnName: 'col', operator: 'EQ', values: ['v1'] }];
1470
+ await executeAfterWait(() => {
1471
+ lb.trigger(HostEvent.UpdateRuntimeFilters, filters as any);
1472
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1473
+ expect.objectContaining({ type: 'UpdateRuntimeFilters' }),
1474
+ thoughtSpotHost,
1475
+ expect.anything(),
1476
+ );
1477
+ });
1478
+ });
1479
+ });
1480
+
1481
+ // ---------------------------------------------------------------------------
1482
+ // iframe MessageChannel response resolves the trigger promise
1483
+ // ---------------------------------------------------------------------------
1484
+ describe('trigger promise resolves with iframe response', () => {
1485
+ const responseEvents: Array<[string, HostEvent, any]> = [
1486
+ ['AddColumns', HostEvent.AddColumns, { columnIds: ['c1'] }],
1487
+ ['RemoveColumn', HostEvent.RemoveColumn, { columnId: 'c1' }],
1488
+ ['UpdateTML', HostEvent.UpdateTML, {}],
1489
+ ['AIHighlights', HostEvent.AIHighlights, {}],
1490
+ ['AskSage', HostEvent.AskSage, {}],
1491
+ ['AskSpotter', HostEvent.AskSpotter, {}],
1492
+ ['TransformTableVizData', HostEvent.TransformTableVizData, {}],
1493
+ ['SpotterSearch', HostEvent.SpotterSearch, {}],
1494
+ ];
1495
+
1496
+ test.each(responseEvents)(
1497
+ '%s: trigger promise resolves with the full responseData from iframe',
1498
+ async (name, event, payload) => {
1499
+ mockMessageChannel();
1500
+ const { lb } = await renderLiveboard();
1501
+ const responseData = { test: 'data-from-iframe' };
1502
+
1503
+ // Start the trigger (which internally posts to the MessageChannel)
1504
+ const triggerPromise = lb.trigger(event, payload as any);
1505
+
1506
+ // Simulate the iframe responding via port1
1507
+ messageChannelMock.port1.onmessage({ data: responseData });
1508
+
1509
+ const result = await triggerPromise;
1510
+ expect(result).toEqual(responseData);
1511
+ },
1512
+ );
1513
+ });
1514
+
1515
+ // ---------------------------------------------------------------------------
1516
+ // Context parameter forwarding
1517
+ // ---------------------------------------------------------------------------
1518
+ describe('context parameter forwarded in postMessage payload', () => {
1519
+ test('ExportTML: context is forwarded as context field in postMessage', async () => {
1520
+ mockMessageChannel();
1521
+ const { lb, iframe } = await renderLiveboard();
1522
+ await executeAfterWait(() => {
1523
+ lb.trigger(HostEvent.ExportTML, {} as any, 'Liveboard' as any);
1524
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1525
+ expect.objectContaining({ context: 'Liveboard' }),
1526
+ thoughtSpotHost,
1527
+ expect.anything(),
1528
+ );
1529
+ });
1530
+ });
1531
+
1532
+ test('EditTML: context is forwarded as context field in postMessage', async () => {
1533
+ mockMessageChannel();
1534
+ const { lb, iframe } = await renderLiveboard();
1535
+ await executeAfterWait(() => {
1536
+ lb.trigger(HostEvent.EditTML, {} as any, 'Search' as any);
1537
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1538
+ expect.objectContaining({ context: 'Search' }),
1539
+ thoughtSpotHost,
1540
+ expect.anything(),
1541
+ );
1542
+ });
1543
+ });
1544
+
1545
+ test('DownloadAsPdf: context is forwarded as context field in postMessage', async () => {
1546
+ mockMessageChannel();
1547
+ const { lb, iframe } = await renderLiveboard();
1548
+ await executeAfterWait(() => {
1549
+ lb.trigger(HostEvent.DownloadAsPdf, {} as any, 'Liveboard' as any);
1550
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1551
+ expect.objectContaining({ context: 'Liveboard' }),
1552
+ thoughtSpotHost,
1553
+ expect.anything(),
1554
+ );
1555
+ });
1556
+ });
1557
+
1558
+ test('MakeACopy: context is forwarded as context field in postMessage', async () => {
1559
+ mockMessageChannel();
1560
+ const { lb, iframe } = await renderLiveboard();
1561
+ await executeAfterWait(() => {
1562
+ lb.trigger(HostEvent.MakeACopy, {} as any, 'Answer' as any);
1563
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1564
+ expect.objectContaining({ context: 'Answer' }),
1565
+ thoughtSpotHost,
1566
+ expect.anything(),
1567
+ );
1568
+ });
1569
+ });
1570
+
1571
+ test('CreateMonitor: context is forwarded as context field in postMessage', async () => {
1572
+ mockMessageChannel();
1573
+ const { lb, iframe } = await renderLiveboard();
1574
+ await executeAfterWait(() => {
1575
+ lb.trigger(HostEvent.CreateMonitor, {} as any, 'Liveboard' as any);
1576
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1577
+ expect.objectContaining({ context: 'Liveboard' }),
1578
+ thoughtSpotHost,
1579
+ expect.anything(),
1580
+ );
1581
+ });
1582
+ });
1583
+
1584
+ test('ShowUnderlyingData: context is forwarded as context field in postMessage', async () => {
1585
+ mockMessageChannel();
1586
+ const { lb, iframe } = await renderLiveboard();
1587
+ await executeAfterWait(() => {
1588
+ lb.trigger(HostEvent.ShowUnderlyingData, {} as any, 'Liveboard' as any);
1589
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1590
+ expect.objectContaining({ context: 'Liveboard' }),
1591
+ thoughtSpotHost,
1592
+ expect.anything(),
1593
+ );
1594
+ });
1595
+ });
1596
+
1597
+ test('SpotIQAnalyze: context is forwarded as context field in postMessage', async () => {
1598
+ mockMessageChannel();
1599
+ const { lb, iframe } = await renderLiveboard();
1600
+ await executeAfterWait(() => {
1601
+ lb.trigger(HostEvent.SpotIQAnalyze, {} as any, 'Answer' as any);
1602
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1603
+ expect.objectContaining({ context: 'Answer' }),
1604
+ thoughtSpotHost,
1605
+ expect.anything(),
1606
+ );
1607
+ });
1608
+ });
1609
+
1610
+ test('Edit: context is forwarded as context field in postMessage', async () => {
1611
+ mockMessageChannel();
1612
+ const { lb, iframe } = await renderLiveboard();
1613
+ await executeAfterWait(() => {
1614
+ lb.trigger(HostEvent.Edit, {} as any, 'Liveboard' as any);
1615
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1616
+ expect.objectContaining({ context: 'Liveboard' }),
1617
+ thoughtSpotHost,
1618
+ expect.anything(),
1619
+ );
1620
+ });
1621
+ });
1622
+
1623
+ test('CopyLink: context is forwarded as context field in postMessage', async () => {
1624
+ mockMessageChannel();
1625
+ const { lb, iframe } = await renderLiveboard();
1626
+ await executeAfterWait(() => {
1627
+ lb.trigger(HostEvent.CopyLink, {} as any, 'Liveboard' as any);
1628
+ expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
1629
+ expect.objectContaining({ context: 'Liveboard' }),
1630
+ thoughtSpotHost,
1631
+ expect.anything(),
1632
+ );
1633
+ });
1634
+ });
1635
+ });