@thoughtspot/visual-embed-sdk 1.42.3 → 1.43.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/package.json +1 -1
- package/cjs/src/api-intercept.d.ts +51 -0
- package/cjs/src/api-intercept.d.ts.map +1 -0
- package/cjs/src/api-intercept.js +180 -0
- package/cjs/src/api-intercept.js.map +1 -0
- package/cjs/src/api-intercept.spec.d.ts +2 -0
- package/cjs/src/api-intercept.spec.d.ts.map +1 -0
- package/cjs/src/api-intercept.spec.js +672 -0
- package/cjs/src/api-intercept.spec.js.map +1 -0
- package/cjs/src/css-variables.d.ts +4 -0
- package/cjs/src/css-variables.d.ts.map +1 -1
- package/cjs/src/embed/app.d.ts +0 -5
- package/cjs/src/embed/app.d.ts.map +1 -1
- package/cjs/src/embed/app.js +4 -5
- package/cjs/src/embed/app.js.map +1 -1
- package/cjs/src/embed/app.spec.js +10 -0
- package/cjs/src/embed/app.spec.js.map +1 -1
- package/cjs/src/embed/conversation.d.ts +2 -2
- package/cjs/src/embed/conversation.js +1 -1
- package/cjs/src/embed/conversation.js.map +1 -1
- package/cjs/src/embed/conversation.spec.js +17 -0
- package/cjs/src/embed/conversation.spec.js.map +1 -1
- package/cjs/src/embed/hostEventClient/contracts.d.ts +11 -1
- package/cjs/src/embed/hostEventClient/contracts.d.ts.map +1 -1
- package/cjs/src/embed/hostEventClient/contracts.js +1 -0
- package/cjs/src/embed/hostEventClient/contracts.js.map +1 -1
- package/cjs/src/embed/liveboard.d.ts.map +1 -1
- package/cjs/src/embed/liveboard.js +4 -2
- package/cjs/src/embed/liveboard.js.map +1 -1
- package/cjs/src/embed/liveboard.spec.js +11 -0
- package/cjs/src/embed/liveboard.spec.js.map +1 -1
- package/cjs/src/embed/search.d.ts +0 -7
- package/cjs/src/embed/search.d.ts.map +1 -1
- package/cjs/src/embed/search.js +1 -4
- package/cjs/src/embed/search.js.map +1 -1
- package/cjs/src/embed/ts-embed.d.ts +10 -0
- package/cjs/src/embed/ts-embed.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.js +56 -15
- package/cjs/src/embed/ts-embed.js.map +1 -1
- package/cjs/src/embed/ts-embed.spec.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.spec.js +412 -238
- package/cjs/src/embed/ts-embed.spec.js.map +1 -1
- package/cjs/src/index.d.ts +2 -2
- package/cjs/src/index.d.ts.map +1 -1
- package/cjs/src/index.js +2 -1
- package/cjs/src/index.js.map +1 -1
- package/cjs/src/react/all-types-export.d.ts +1 -1
- package/cjs/src/react/all-types-export.d.ts.map +1 -1
- package/cjs/src/react/all-types-export.js +2 -1
- package/cjs/src/react/all-types-export.js.map +1 -1
- package/cjs/src/types.d.ts +328 -103
- package/cjs/src/types.d.ts.map +1 -1
- package/cjs/src/types.js +265 -85
- package/cjs/src/types.js.map +1 -1
- package/cjs/src/utils/logger.d.ts.map +1 -1
- package/cjs/src/utils/logger.js +1 -2
- package/cjs/src/utils/logger.js.map +1 -1
- package/cjs/src/utils/processData.d.ts +1 -1
- package/cjs/src/utils/processData.d.ts.map +1 -1
- package/cjs/src/utils/processData.js +8 -8
- package/cjs/src/utils/processData.js.map +1 -1
- package/cjs/src/utils/processData.spec.js.map +1 -1
- package/dist/{index-SVcLgSqi.js → index-CpkMygsc.js} +1 -1
- package/dist/src/api-intercept.d.ts +51 -0
- package/dist/src/api-intercept.d.ts.map +1 -0
- package/dist/src/api-intercept.spec.d.ts +2 -0
- package/dist/src/api-intercept.spec.d.ts.map +1 -0
- package/dist/src/css-variables.d.ts +4 -0
- package/dist/src/css-variables.d.ts.map +1 -1
- package/dist/src/embed/app.d.ts +0 -5
- package/dist/src/embed/app.d.ts.map +1 -1
- package/dist/src/embed/conversation.d.ts +2 -2
- package/dist/src/embed/hostEventClient/contracts.d.ts +11 -1
- package/dist/src/embed/hostEventClient/contracts.d.ts.map +1 -1
- package/dist/src/embed/liveboard.d.ts.map +1 -1
- package/dist/src/embed/search.d.ts +0 -7
- package/dist/src/embed/search.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +10 -0
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.spec.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/react/all-types-export.d.ts +1 -1
- package/dist/src/react/all-types-export.d.ts.map +1 -1
- package/dist/src/types.d.ts +328 -103
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/logger.d.ts.map +1 -1
- package/dist/src/utils/processData.d.ts +1 -1
- package/dist/src/utils/processData.d.ts.map +1 -1
- package/dist/tsembed-react.es.js +519 -133
- package/dist/tsembed-react.js +518 -132
- package/dist/tsembed.es.js +2642 -2256
- package/dist/tsembed.js +2640 -2254
- package/dist/visual-embed-sdk-react-full.d.ts +355 -118
- package/dist/visual-embed-sdk-react.d.ts +352 -118
- package/dist/visual-embed-sdk.d.ts +355 -118
- package/lib/package.json +1 -1
- package/lib/src/api-intercept.d.ts +51 -0
- package/lib/src/api-intercept.d.ts.map +1 -0
- package/lib/src/api-intercept.js +173 -0
- package/lib/src/api-intercept.js.map +1 -0
- package/lib/src/api-intercept.spec.d.ts +2 -0
- package/lib/src/api-intercept.spec.d.ts.map +1 -0
- package/lib/src/api-intercept.spec.js +669 -0
- package/lib/src/api-intercept.spec.js.map +1 -0
- package/lib/src/css-variables.d.ts +4 -0
- package/lib/src/css-variables.d.ts.map +1 -1
- package/lib/src/embed/app.d.ts +0 -5
- package/lib/src/embed/app.d.ts.map +1 -1
- package/lib/src/embed/app.js +4 -5
- package/lib/src/embed/app.js.map +1 -1
- package/lib/src/embed/app.spec.js +10 -0
- package/lib/src/embed/app.spec.js.map +1 -1
- package/lib/src/embed/conversation.d.ts +2 -2
- package/lib/src/embed/conversation.js +1 -1
- package/lib/src/embed/conversation.js.map +1 -1
- package/lib/src/embed/conversation.spec.js +17 -0
- package/lib/src/embed/conversation.spec.js.map +1 -1
- package/lib/src/embed/hostEventClient/contracts.d.ts +11 -1
- package/lib/src/embed/hostEventClient/contracts.d.ts.map +1 -1
- package/lib/src/embed/hostEventClient/contracts.js +1 -0
- package/lib/src/embed/hostEventClient/contracts.js.map +1 -1
- package/lib/src/embed/liveboard.d.ts.map +1 -1
- package/lib/src/embed/liveboard.js +4 -2
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +11 -0
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/search.d.ts +0 -7
- package/lib/src/embed/search.d.ts.map +1 -1
- package/lib/src/embed/search.js +1 -4
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +10 -0
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +56 -15
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +412 -238
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/index.d.ts +2 -2
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/index.js +2 -2
- package/lib/src/index.js.map +1 -1
- package/lib/src/react/all-types-export.d.ts +1 -1
- package/lib/src/react/all-types-export.d.ts.map +1 -1
- package/lib/src/react/all-types-export.js +1 -1
- package/lib/src/react/all-types-export.js.map +1 -1
- package/lib/src/types.d.ts +328 -103
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js +264 -84
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/logger.d.ts.map +1 -1
- package/lib/src/utils/logger.js +1 -2
- package/lib/src/utils/logger.js.map +1 -1
- package/lib/src/utils/processData.d.ts +1 -1
- package/lib/src/utils/processData.d.ts.map +1 -1
- package/lib/src/utils/processData.js +8 -8
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/api-intercept.spec.ts +856 -0
- package/src/api-intercept.ts +204 -0
- package/src/css-variables.ts +5 -0
- package/src/embed/app.spec.ts +11 -0
- package/src/embed/app.ts +5 -16
- package/src/embed/conversation.spec.ts +22 -0
- package/src/embed/conversation.ts +3 -3
- package/src/embed/hostEventClient/contracts.ts +10 -0
- package/src/embed/liveboard.spec.ts +12 -0
- package/src/embed/liveboard.ts +6 -2
- package/src/embed/search.ts +1 -14
- package/src/embed/ts-embed.spec.ts +498 -250
- package/src/embed/ts-embed.ts +80 -32
- package/src/index.ts +2 -0
- package/src/react/all-types-export.ts +1 -0
- package/src/types.ts +410 -179
- package/src/utils/logger.ts +1 -2
- package/src/utils/processData.spec.ts +0 -1
- package/src/utils/processData.ts +10 -11
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
ContextMenuTriggerOptions,
|
|
29
29
|
CustomActionTarget,
|
|
30
30
|
CustomActionsPosition,
|
|
31
|
+
DefaultAppInitData,
|
|
31
32
|
} from '../types';
|
|
32
33
|
import {
|
|
33
34
|
executeAfterWait,
|
|
@@ -60,10 +61,12 @@ import { processTrigger } from '../utils/processTrigger';
|
|
|
60
61
|
import { UIPassthroughEvent } from './hostEventClient/contracts';
|
|
61
62
|
import * as sessionInfoService from '../utils/sessionInfoService';
|
|
62
63
|
import * as authToken from '../authToken';
|
|
64
|
+
import * as apiIntercept from '../api-intercept';
|
|
63
65
|
|
|
64
66
|
jest.mock('../utils/processTrigger');
|
|
65
67
|
|
|
66
68
|
const mockProcessTrigger = processTrigger as jest.Mock;
|
|
69
|
+
const mockHandleInterceptEvent = jest.spyOn(apiIntercept, 'handleInterceptEvent');
|
|
67
70
|
const defaultViewConfig = {
|
|
68
71
|
frameParams: {
|
|
69
72
|
width: 1280,
|
|
@@ -110,6 +113,31 @@ const customVariablesForThirdPartyTools = {
|
|
|
110
113
|
key2: '*%^',
|
|
111
114
|
};
|
|
112
115
|
|
|
116
|
+
const getMockAppInitPayload = (data: any) => {
|
|
117
|
+
const defaultData: DefaultAppInitData = {
|
|
118
|
+
customisations,
|
|
119
|
+
authToken: '',
|
|
120
|
+
hostConfig: undefined,
|
|
121
|
+
runtimeFilterParams: null,
|
|
122
|
+
runtimeParameterParams: null,
|
|
123
|
+
hiddenHomeLeftNavItems: [],
|
|
124
|
+
hiddenHomepageModules: [],
|
|
125
|
+
hiddenListColumns: [],
|
|
126
|
+
customActions: [],
|
|
127
|
+
reorderedHomepageModules: [],
|
|
128
|
+
customVariablesForThirdPartyTools,
|
|
129
|
+
interceptTimeout: undefined,
|
|
130
|
+
interceptUrls: [],
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
type: EmbedEvent.APP_INIT,
|
|
134
|
+
data: {
|
|
135
|
+
...defaultData,
|
|
136
|
+
...data,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
113
141
|
describe('Unit test case for ts embed', () => {
|
|
114
142
|
const mockMixPanelEvent = jest.spyOn(mixpanelInstance, 'uploadMixpanelEvent');
|
|
115
143
|
beforeEach(() => {
|
|
@@ -337,22 +365,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
337
365
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
338
366
|
});
|
|
339
367
|
await executeAfterWait(() => {
|
|
340
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
341
|
-
type: EmbedEvent.APP_INIT,
|
|
342
|
-
data: {
|
|
343
|
-
customisations,
|
|
344
|
-
authToken: '',
|
|
345
|
-
runtimeFilterParams: null,
|
|
346
|
-
runtimeParameterParams: null,
|
|
347
|
-
hiddenHomeLeftNavItems: [],
|
|
348
|
-
hiddenHomepageModules: [],
|
|
349
|
-
hiddenListColumns: [],
|
|
350
|
-
customActions: [],
|
|
351
|
-
hostConfig: undefined,
|
|
352
|
-
reorderedHomepageModules: [],
|
|
353
|
-
customVariablesForThirdPartyTools,
|
|
354
|
-
},
|
|
355
|
-
});
|
|
368
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({}));
|
|
356
369
|
});
|
|
357
370
|
});
|
|
358
371
|
|
|
@@ -374,22 +387,9 @@ describe('Unit test case for ts embed', () => {
|
|
|
374
387
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
375
388
|
});
|
|
376
389
|
await executeAfterWait(() => {
|
|
377
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
customisations: customisationsView,
|
|
381
|
-
authToken: '',
|
|
382
|
-
runtimeFilterParams: null,
|
|
383
|
-
runtimeParameterParams: null,
|
|
384
|
-
hiddenHomeLeftNavItems: [],
|
|
385
|
-
hiddenHomepageModules: [],
|
|
386
|
-
hiddenListColumns: [],
|
|
387
|
-
customActions: [],
|
|
388
|
-
hostConfig: undefined,
|
|
389
|
-
reorderedHomepageModules: [],
|
|
390
|
-
customVariablesForThirdPartyTools,
|
|
391
|
-
},
|
|
392
|
-
});
|
|
390
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({
|
|
391
|
+
customisations: customisationsView,
|
|
392
|
+
}));
|
|
393
393
|
});
|
|
394
394
|
});
|
|
395
395
|
|
|
@@ -416,22 +416,9 @@ describe('Unit test case for ts embed', () => {
|
|
|
416
416
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
417
417
|
});
|
|
418
418
|
await executeAfterWait(() => {
|
|
419
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
customisations,
|
|
423
|
-
authToken: '',
|
|
424
|
-
hostConfig: undefined,
|
|
425
|
-
runtimeFilterParams: null,
|
|
426
|
-
runtimeParameterParams: null,
|
|
427
|
-
hiddenHomeLeftNavItems: [],
|
|
428
|
-
hiddenHomepageModules: [HomepageModule.MyLibrary, HomepageModule.Learning],
|
|
429
|
-
hiddenListColumns: [],
|
|
430
|
-
customActions: [],
|
|
431
|
-
reorderedHomepageModules: [],
|
|
432
|
-
customVariablesForThirdPartyTools,
|
|
433
|
-
},
|
|
434
|
-
});
|
|
419
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({
|
|
420
|
+
hiddenHomepageModules: [HomepageModule.MyLibrary, HomepageModule.Learning],
|
|
421
|
+
}));
|
|
435
422
|
});
|
|
436
423
|
});
|
|
437
424
|
|
|
@@ -455,22 +442,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
455
442
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
456
443
|
});
|
|
457
444
|
await executeAfterWait(() => {
|
|
458
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
459
|
-
type: EmbedEvent.APP_INIT,
|
|
460
|
-
data: {
|
|
461
|
-
customisations,
|
|
462
|
-
authToken: '',
|
|
463
|
-
hostConfig: undefined,
|
|
464
|
-
runtimeFilterParams: null,
|
|
465
|
-
runtimeParameterParams: null,
|
|
466
|
-
hiddenHomeLeftNavItems: [],
|
|
467
|
-
hiddenHomepageModules: [],
|
|
468
|
-
hiddenListColumns: [],
|
|
469
|
-
customActions: [],
|
|
470
|
-
reorderedHomepageModules: [],
|
|
471
|
-
customVariablesForThirdPartyTools,
|
|
472
|
-
},
|
|
473
|
-
});
|
|
445
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({}));
|
|
474
446
|
});
|
|
475
447
|
});
|
|
476
448
|
|
|
@@ -497,23 +469,10 @@ describe('Unit test case for ts embed', () => {
|
|
|
497
469
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
498
470
|
});
|
|
499
471
|
await executeAfterWait(() => {
|
|
500
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
authToken: '',
|
|
505
|
-
hostConfig: undefined,
|
|
506
|
-
runtimeFilterParams: null,
|
|
507
|
-
runtimeParameterParams: null,
|
|
508
|
-
hiddenHomeLeftNavItems: [],
|
|
509
|
-
hiddenHomepageModules: [],
|
|
510
|
-
hiddenListColumns: [],
|
|
511
|
-
customActions: [],
|
|
512
|
-
reorderedHomepageModules:
|
|
513
|
-
[HomepageModule.MyLibrary, HomepageModule.Watchlist],
|
|
514
|
-
customVariablesForThirdPartyTools,
|
|
515
|
-
},
|
|
516
|
-
});
|
|
472
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({
|
|
473
|
+
reorderedHomepageModules:
|
|
474
|
+
[HomepageModule.MyLibrary, HomepageModule.Watchlist],
|
|
475
|
+
}));
|
|
517
476
|
});
|
|
518
477
|
});
|
|
519
478
|
|
|
@@ -543,22 +502,9 @@ describe('Unit test case for ts embed', () => {
|
|
|
543
502
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
544
503
|
});
|
|
545
504
|
await executeAfterWait(() => {
|
|
546
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
customisations,
|
|
550
|
-
authToken: '',
|
|
551
|
-
runtimeFilterParams: null,
|
|
552
|
-
runtimeParameterParams: 'param1=color¶mVal1=blue',
|
|
553
|
-
hiddenHomeLeftNavItems: [],
|
|
554
|
-
hiddenHomepageModules: [],
|
|
555
|
-
hiddenListColumns: [],
|
|
556
|
-
customActions: [],
|
|
557
|
-
hostConfig: undefined,
|
|
558
|
-
reorderedHomepageModules: [],
|
|
559
|
-
customVariablesForThirdPartyTools,
|
|
560
|
-
},
|
|
561
|
-
});
|
|
505
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({
|
|
506
|
+
runtimeParameterParams: 'param1=color¶mVal1=blue',
|
|
507
|
+
}));
|
|
562
508
|
});
|
|
563
509
|
});
|
|
564
510
|
|
|
@@ -589,22 +535,9 @@ describe('Unit test case for ts embed', () => {
|
|
|
589
535
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
590
536
|
});
|
|
591
537
|
await executeAfterWait(() => {
|
|
592
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
customisations,
|
|
596
|
-
authToken: '',
|
|
597
|
-
runtimeFilterParams: 'col1=color&op1=EQ&val1=blue',
|
|
598
|
-
runtimeParameterParams: null,
|
|
599
|
-
hiddenHomeLeftNavItems: [],
|
|
600
|
-
hiddenHomepageModules: [],
|
|
601
|
-
hiddenListColumns: [],
|
|
602
|
-
customActions: [],
|
|
603
|
-
hostConfig: undefined,
|
|
604
|
-
reorderedHomepageModules: [],
|
|
605
|
-
customVariablesForThirdPartyTools,
|
|
606
|
-
},
|
|
607
|
-
});
|
|
538
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({
|
|
539
|
+
runtimeFilterParams: 'col1=color&op1=EQ&val1=blue',
|
|
540
|
+
}));
|
|
608
541
|
});
|
|
609
542
|
});
|
|
610
543
|
|
|
@@ -634,22 +567,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
634
567
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
635
568
|
});
|
|
636
569
|
await executeAfterWait(() => {
|
|
637
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
638
|
-
type: EmbedEvent.APP_INIT,
|
|
639
|
-
data: {
|
|
640
|
-
customisations,
|
|
641
|
-
authToken: '',
|
|
642
|
-
runtimeFilterParams: null,
|
|
643
|
-
runtimeParameterParams: null,
|
|
644
|
-
hiddenHomeLeftNavItems: [],
|
|
645
|
-
hiddenHomepageModules: [],
|
|
646
|
-
hiddenListColumns: [],
|
|
647
|
-
customActions: [],
|
|
648
|
-
hostConfig: undefined,
|
|
649
|
-
reorderedHomepageModules: [],
|
|
650
|
-
customVariablesForThirdPartyTools,
|
|
651
|
-
},
|
|
652
|
-
});
|
|
570
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({}));
|
|
653
571
|
});
|
|
654
572
|
});
|
|
655
573
|
|
|
@@ -680,22 +598,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
680
598
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
681
599
|
});
|
|
682
600
|
await executeAfterWait(() => {
|
|
683
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
684
|
-
type: EmbedEvent.APP_INIT,
|
|
685
|
-
data: {
|
|
686
|
-
customisations,
|
|
687
|
-
authToken: '',
|
|
688
|
-
runtimeFilterParams: null,
|
|
689
|
-
runtimeParameterParams: null,
|
|
690
|
-
hiddenHomeLeftNavItems: [],
|
|
691
|
-
hiddenHomepageModules: [],
|
|
692
|
-
hiddenListColumns: [],
|
|
693
|
-
customActions: [],
|
|
694
|
-
hostConfig: undefined,
|
|
695
|
-
reorderedHomepageModules: [],
|
|
696
|
-
customVariablesForThirdPartyTools,
|
|
697
|
-
},
|
|
698
|
-
});
|
|
601
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({}));
|
|
699
602
|
});
|
|
700
603
|
});
|
|
701
604
|
|
|
@@ -723,23 +626,10 @@ describe('Unit test case for ts embed', () => {
|
|
|
723
626
|
});
|
|
724
627
|
|
|
725
628
|
await executeAfterWait(() => {
|
|
726
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
authToken: '',
|
|
731
|
-
hostConfig: undefined,
|
|
732
|
-
runtimeFilterParams: null,
|
|
733
|
-
runtimeParameterParams: null,
|
|
734
|
-
hiddenHomeLeftNavItems:
|
|
735
|
-
[HomeLeftNavItem.Home, HomeLeftNavItem.MonitorSubscription],
|
|
736
|
-
hiddenHomepageModules: [],
|
|
737
|
-
hiddenListColumns: [],
|
|
738
|
-
customActions: [],
|
|
739
|
-
reorderedHomepageModules: [],
|
|
740
|
-
customVariablesForThirdPartyTools,
|
|
741
|
-
},
|
|
742
|
-
});
|
|
629
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({
|
|
630
|
+
hiddenHomeLeftNavItems:
|
|
631
|
+
[HomeLeftNavItem.Home, HomeLeftNavItem.MonitorSubscription],
|
|
632
|
+
}));
|
|
743
633
|
});
|
|
744
634
|
});
|
|
745
635
|
|
|
@@ -894,22 +784,10 @@ describe('Unit test case for ts embed', () => {
|
|
|
894
784
|
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
895
785
|
});
|
|
896
786
|
await executeAfterWait(() => {
|
|
897
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
authToken: 'test_auth_token1',
|
|
902
|
-
runtimeFilterParams: null,
|
|
903
|
-
runtimeParameterParams: null,
|
|
904
|
-
hiddenHomeLeftNavItems: [],
|
|
905
|
-
hiddenHomepageModules: [],
|
|
906
|
-
hiddenListColumns: [],
|
|
907
|
-
customActions: [],
|
|
908
|
-
hostConfig: undefined,
|
|
909
|
-
reorderedHomepageModules: [],
|
|
910
|
-
customVariablesForThirdPartyTools: {},
|
|
911
|
-
},
|
|
912
|
-
});
|
|
787
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({
|
|
788
|
+
authToken: 'test_auth_token1',
|
|
789
|
+
customVariablesForThirdPartyTools: {},
|
|
790
|
+
}));
|
|
913
791
|
});
|
|
914
792
|
|
|
915
793
|
jest.spyOn(authService, 'verifyTokenService').mockClear();
|
|
@@ -965,36 +843,25 @@ describe('Unit test case for ts embed', () => {
|
|
|
965
843
|
});
|
|
966
844
|
|
|
967
845
|
await executeAfterWait(() => {
|
|
968
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
strings: {
|
|
974
|
-
Liveboard: 'Dashboard',
|
|
975
|
-
},
|
|
976
|
-
stringIDsUrl: 'https://sample-string-ids-url.com',
|
|
977
|
-
stringIDs: {
|
|
978
|
-
'liveboard.header.title': 'Dashboard name',
|
|
979
|
-
},
|
|
846
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({
|
|
847
|
+
customisations: {
|
|
848
|
+
content: {
|
|
849
|
+
strings: {
|
|
850
|
+
Liveboard: 'Dashboard',
|
|
980
851
|
},
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
852
|
+
stringIDsUrl: 'https://sample-string-ids-url.com',
|
|
853
|
+
stringIDs: {
|
|
854
|
+
'liveboard.header.title': 'Dashboard name',
|
|
984
855
|
},
|
|
985
856
|
},
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
hiddenHomepageModules: [],
|
|
991
|
-
hiddenListColumns: [],
|
|
992
|
-
customActions: [],
|
|
993
|
-
hostConfig: undefined,
|
|
994
|
-
reorderedHomepageModules: [],
|
|
995
|
-
customVariablesForThirdPartyTools: {},
|
|
857
|
+
style: {
|
|
858
|
+
customCSS: {},
|
|
859
|
+
customCSSUrl: undefined,
|
|
860
|
+
},
|
|
996
861
|
},
|
|
997
|
-
|
|
862
|
+
authToken: 'test_auth_token1',
|
|
863
|
+
customVariablesForThirdPartyTools: {},
|
|
864
|
+
}));
|
|
998
865
|
const customisationContent = mockPort.postMessage.mock.calls[0][0].data.customisations.content;
|
|
999
866
|
expect(customisationContent.stringIDsUrl)
|
|
1000
867
|
.toBe('https://sample-string-ids-url.com');
|
|
@@ -1045,7 +912,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
1045
912
|
type: EmbedEvent.APP_INIT,
|
|
1046
913
|
data: {},
|
|
1047
914
|
};
|
|
1048
|
-
|
|
915
|
+
|
|
1049
916
|
// Create a SearchEmbed with valid custom actions to test
|
|
1050
917
|
// CustomActionsValidationResult
|
|
1051
918
|
const searchEmbed = new SearchEmbed(getRootEl(), {
|
|
@@ -1067,7 +934,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
1067
934
|
}
|
|
1068
935
|
]
|
|
1069
936
|
});
|
|
1070
|
-
|
|
937
|
+
|
|
1071
938
|
searchEmbed.render();
|
|
1072
939
|
const mockPort: any = {
|
|
1073
940
|
postMessage: jest.fn(),
|
|
@@ -1079,44 +946,34 @@ describe('Unit test case for ts embed', () => {
|
|
|
1079
946
|
});
|
|
1080
947
|
|
|
1081
948
|
await executeAfterWait(() => {
|
|
1082
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
customCSS: {},
|
|
1089
|
-
customCSSUrl: undefined,
|
|
1090
|
-
},
|
|
949
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith(getMockAppInitPayload({
|
|
950
|
+
customisations: {
|
|
951
|
+
content: {},
|
|
952
|
+
style: {
|
|
953
|
+
customCSS: {},
|
|
954
|
+
customCSSUrl: undefined,
|
|
1091
955
|
},
|
|
1092
|
-
authToken: 'test_auth_token1',
|
|
1093
|
-
runtimeFilterParams: null,
|
|
1094
|
-
runtimeParameterParams: null,
|
|
1095
|
-
hiddenHomeLeftNavItems: [],
|
|
1096
|
-
hiddenHomepageModules: [],
|
|
1097
|
-
hiddenListColumns: [],
|
|
1098
|
-
customActions: [
|
|
1099
|
-
{
|
|
1100
|
-
id: 'action2',
|
|
1101
|
-
name: 'Another Valid Action',
|
|
1102
|
-
target: CustomActionTarget.VIZ,
|
|
1103
|
-
position: CustomActionsPosition.MENU,
|
|
1104
|
-
metadataIds: { vizIds: ['viz456'] }
|
|
1105
|
-
},
|
|
1106
|
-
{
|
|
1107
|
-
id: 'action1',
|
|
1108
|
-
name: 'Valid Action',
|
|
1109
|
-
target: CustomActionTarget.LIVEBOARD,
|
|
1110
|
-
position: CustomActionsPosition.PRIMARY,
|
|
1111
|
-
metadataIds: { liveboardIds: ['lb123'] }
|
|
1112
|
-
}
|
|
1113
|
-
], // Actions should be sorted by name
|
|
1114
|
-
hostConfig: undefined,
|
|
1115
|
-
reorderedHomepageModules: [],
|
|
1116
|
-
customVariablesForThirdPartyTools: {},
|
|
1117
956
|
},
|
|
1118
|
-
|
|
1119
|
-
|
|
957
|
+
authToken: 'test_auth_token1',
|
|
958
|
+
customActions: [
|
|
959
|
+
{
|
|
960
|
+
id: 'action2',
|
|
961
|
+
name: 'Another Valid Action',
|
|
962
|
+
target: CustomActionTarget.VIZ,
|
|
963
|
+
position: CustomActionsPosition.MENU,
|
|
964
|
+
metadataIds: { vizIds: ['viz456'] }
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
id: 'action1',
|
|
968
|
+
name: 'Valid Action',
|
|
969
|
+
target: CustomActionTarget.LIVEBOARD,
|
|
970
|
+
position: CustomActionsPosition.PRIMARY,
|
|
971
|
+
metadataIds: { liveboardIds: ['lb123'] }
|
|
972
|
+
}
|
|
973
|
+
], // Actions should be sorted by name
|
|
974
|
+
customVariablesForThirdPartyTools: {},
|
|
975
|
+
}));
|
|
976
|
+
|
|
1120
977
|
// Verify that CustomActionsValidationResult structure is
|
|
1121
978
|
// correct
|
|
1122
979
|
const appInitData = mockPort.postMessage.mock.calls[0][0].data;
|
|
@@ -1137,7 +994,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
1137
994
|
})
|
|
1138
995
|
])
|
|
1139
996
|
);
|
|
1140
|
-
|
|
997
|
+
|
|
1141
998
|
// Verify actions are sorted by name (alphabetically)
|
|
1142
999
|
expect(appInitData.customActions[0].name).toBe('Another Valid Action');
|
|
1143
1000
|
expect(appInitData.customActions[1].name).toBe('Valid Action');
|
|
@@ -2444,7 +2301,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
2444
2301
|
});
|
|
2445
2302
|
|
|
2446
2303
|
afterAll((): void => {
|
|
2447
|
-
window.location = location
|
|
2304
|
+
(window.location as any) = location;
|
|
2448
2305
|
});
|
|
2449
2306
|
|
|
2450
2307
|
it('get url params for TS', () => {
|
|
@@ -3362,7 +3219,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
3362
3219
|
new Error('Auth failed'),
|
|
3363
3220
|
);
|
|
3364
3221
|
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
3365
|
-
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
3222
|
+
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
3366
3223
|
await searchEmbed.render();
|
|
3367
3224
|
await executeAfterWait(() => {
|
|
3368
3225
|
expect(getRootEl().innerHTML).toContain('Not logged in');
|
|
@@ -3371,7 +3228,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
3371
3228
|
window.dispatchEvent(onlineEvent);
|
|
3372
3229
|
}).not.toThrow();
|
|
3373
3230
|
});
|
|
3374
|
-
|
|
3231
|
+
|
|
3375
3232
|
errorSpy.mockReset();
|
|
3376
3233
|
});
|
|
3377
3234
|
|
|
@@ -3510,9 +3367,9 @@ describe('Unit test case for ts embed', () => {
|
|
|
3510
3367
|
|
|
3511
3368
|
appEmbed.destroy();
|
|
3512
3369
|
|
|
3513
|
-
// Should be called immediately when
|
|
3370
|
+
// Should be called immediately when config is enabled
|
|
3514
3371
|
expect(triggerSpy).toHaveBeenCalledWith(HostEvent.DestroyEmbed);
|
|
3515
|
-
|
|
3372
|
+
|
|
3516
3373
|
// Wait for the timeout to complete
|
|
3517
3374
|
await new Promise(resolve => setTimeout(resolve, 1100));
|
|
3518
3375
|
|
|
@@ -3535,7 +3392,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
3535
3392
|
await appEmbed.render();
|
|
3536
3393
|
|
|
3537
3394
|
// Mock trigger to resolve quickly (before timeout)
|
|
3538
|
-
const triggerSpy = jest.spyOn(appEmbed, 'trigger').mockImplementation(() =>
|
|
3395
|
+
const triggerSpy = jest.spyOn(appEmbed, 'trigger').mockImplementation(() =>
|
|
3539
3396
|
new Promise(resolve => setTimeout(() => resolve(null), 100))
|
|
3540
3397
|
);
|
|
3541
3398
|
const removeChildSpy = jest.spyOn(Node.prototype, 'removeChild').mockImplementation(() => getRootEl());
|
|
@@ -3565,7 +3422,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
3565
3422
|
await appEmbed.render();
|
|
3566
3423
|
|
|
3567
3424
|
// Mock trigger to take longer than timeout
|
|
3568
|
-
const triggerSpy = jest.spyOn(appEmbed, 'trigger').mockImplementation(() =>
|
|
3425
|
+
const triggerSpy = jest.spyOn(appEmbed, 'trigger').mockImplementation(() =>
|
|
3569
3426
|
new Promise(resolve => setTimeout(() => resolve(null), 500))
|
|
3570
3427
|
);
|
|
3571
3428
|
const removeChildSpy = jest.spyOn(Node.prototype, 'removeChild').mockImplementation(() => getRootEl());
|
|
@@ -3580,4 +3437,395 @@ describe('Unit test case for ts embed', () => {
|
|
|
3580
3437
|
});
|
|
3581
3438
|
});
|
|
3582
3439
|
});
|
|
3440
|
+
|
|
3441
|
+
describe('handleApiInterceptEvent', () => {
|
|
3442
|
+
beforeEach(() => {
|
|
3443
|
+
document.body.innerHTML = getDocumentBody();
|
|
3444
|
+
init({
|
|
3445
|
+
thoughtSpotHost: 'tshost',
|
|
3446
|
+
authType: AuthType.None,
|
|
3447
|
+
});
|
|
3448
|
+
jest.clearAllMocks();
|
|
3449
|
+
mockHandleInterceptEvent.mockClear();
|
|
3450
|
+
});
|
|
3451
|
+
|
|
3452
|
+
test('should call handleInterceptEvent with correct parameters', async () => {
|
|
3453
|
+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
3454
|
+
await searchEmbed.render();
|
|
3455
|
+
|
|
3456
|
+
const mockEventData = {
|
|
3457
|
+
type: EmbedEvent.ApiIntercept,
|
|
3458
|
+
data: JSON.stringify({
|
|
3459
|
+
input: '/prism/?op=GetChartWithData',
|
|
3460
|
+
init: {
|
|
3461
|
+
method: 'POST',
|
|
3462
|
+
body: JSON.stringify({
|
|
3463
|
+
variables: {
|
|
3464
|
+
session: { sessionId: 'session-123' },
|
|
3465
|
+
contextBookId: 'viz-456'
|
|
3466
|
+
}
|
|
3467
|
+
})
|
|
3468
|
+
}
|
|
3469
|
+
})
|
|
3470
|
+
};
|
|
3471
|
+
|
|
3472
|
+
const mockPort: any = {
|
|
3473
|
+
postMessage: jest.fn(),
|
|
3474
|
+
};
|
|
3475
|
+
|
|
3476
|
+
await executeAfterWait(() => {
|
|
3477
|
+
const iframe = getIFrameEl();
|
|
3478
|
+
postMessageToParent(iframe.contentWindow, mockEventData, mockPort);
|
|
3479
|
+
});
|
|
3480
|
+
|
|
3481
|
+
await executeAfterWait(() => {
|
|
3482
|
+
expect(mockHandleInterceptEvent).toHaveBeenCalledTimes(1);
|
|
3483
|
+
const call = mockHandleInterceptEvent.mock.calls[0][0];
|
|
3484
|
+
expect(call.eventData).toEqual(mockEventData);
|
|
3485
|
+
expect(call.executeEvent).toBeInstanceOf(Function);
|
|
3486
|
+
expect(call.getUnsavedAnswerTml).toBeInstanceOf(Function);
|
|
3487
|
+
expect(call.viewConfig).toMatchObject(defaultViewConfig);
|
|
3488
|
+
});
|
|
3489
|
+
});
|
|
3490
|
+
|
|
3491
|
+
test('should execute callbacks through executeEvent function', async () => {
|
|
3492
|
+
let capturedExecuteEvent: any;
|
|
3493
|
+
mockHandleInterceptEvent.mockImplementation((params) => {
|
|
3494
|
+
capturedExecuteEvent = params.executeEvent;
|
|
3495
|
+
});
|
|
3496
|
+
|
|
3497
|
+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
3498
|
+
const mockCallback = jest.fn();
|
|
3499
|
+
searchEmbed.on(EmbedEvent.CustomAction, mockCallback);
|
|
3500
|
+
await searchEmbed.render();
|
|
3501
|
+
|
|
3502
|
+
const mockEventData = {
|
|
3503
|
+
type: EmbedEvent.ApiIntercept,
|
|
3504
|
+
data: JSON.stringify({
|
|
3505
|
+
input: '/prism/?op=GetChartWithData',
|
|
3506
|
+
init: {}
|
|
3507
|
+
})
|
|
3508
|
+
};
|
|
3509
|
+
|
|
3510
|
+
const mockPort: any = {
|
|
3511
|
+
postMessage: jest.fn(),
|
|
3512
|
+
};
|
|
3513
|
+
|
|
3514
|
+
await executeAfterWait(() => {
|
|
3515
|
+
const iframe = getIFrameEl();
|
|
3516
|
+
postMessageToParent(iframe.contentWindow, mockEventData, mockPort);
|
|
3517
|
+
});
|
|
3518
|
+
|
|
3519
|
+
await executeAfterWait(() => {
|
|
3520
|
+
expect(capturedExecuteEvent).toBeDefined();
|
|
3521
|
+
|
|
3522
|
+
// Simulate executeEvent being called by handleInterceptEvent
|
|
3523
|
+
const testData = { test: 'data' };
|
|
3524
|
+
capturedExecuteEvent(EmbedEvent.CustomAction, testData);
|
|
3525
|
+
|
|
3526
|
+
// executeEvent passes data as first param to callback
|
|
3527
|
+
expect(mockCallback).toHaveBeenCalled();
|
|
3528
|
+
expect(mockCallback.mock.calls[0][0]).toEqual(testData);
|
|
3529
|
+
});
|
|
3530
|
+
});
|
|
3531
|
+
|
|
3532
|
+
test('should call triggerUIPassThrough through getUnsavedAnswerTml function', async () => {
|
|
3533
|
+
let capturedGetUnsavedAnswerTml: any;
|
|
3534
|
+
mockHandleInterceptEvent.mockImplementation((params) => {
|
|
3535
|
+
capturedGetUnsavedAnswerTml = params.getUnsavedAnswerTml;
|
|
3536
|
+
});
|
|
3537
|
+
|
|
3538
|
+
const mockTmlResponse = { tml: 'test-tml-content' };
|
|
3539
|
+
mockProcessTrigger.mockResolvedValue([{ value: mockTmlResponse }]);
|
|
3540
|
+
|
|
3541
|
+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
3542
|
+
await searchEmbed.render();
|
|
3543
|
+
|
|
3544
|
+
const mockEventData = {
|
|
3545
|
+
type: EmbedEvent.ApiIntercept,
|
|
3546
|
+
data: JSON.stringify({
|
|
3547
|
+
input: '/prism/?op=GetChartWithData',
|
|
3548
|
+
init: {}
|
|
3549
|
+
})
|
|
3550
|
+
};
|
|
3551
|
+
|
|
3552
|
+
const mockPort: any = {
|
|
3553
|
+
postMessage: jest.fn(),
|
|
3554
|
+
};
|
|
3555
|
+
|
|
3556
|
+
await executeAfterWait(() => {
|
|
3557
|
+
const iframe = getIFrameEl();
|
|
3558
|
+
postMessageToParent(iframe.contentWindow, mockEventData, mockPort);
|
|
3559
|
+
});
|
|
3560
|
+
|
|
3561
|
+
await executeAfterWait(async () => {
|
|
3562
|
+
expect(capturedGetUnsavedAnswerTml).toBeDefined();
|
|
3563
|
+
|
|
3564
|
+
// Clear previous calls
|
|
3565
|
+
mockProcessTrigger.mockClear();
|
|
3566
|
+
|
|
3567
|
+
// Simulate getUnsavedAnswerTml being called by
|
|
3568
|
+
// handleInterceptEvent
|
|
3569
|
+
const result = await capturedGetUnsavedAnswerTml({
|
|
3570
|
+
sessionId: 'session-123',
|
|
3571
|
+
vizId: 'viz-456'
|
|
3572
|
+
});
|
|
3573
|
+
|
|
3574
|
+
expect(mockProcessTrigger).toHaveBeenCalled();
|
|
3575
|
+
const callArgs = mockProcessTrigger.mock.calls[0];
|
|
3576
|
+
// Verify UIPassthrough event is triggered with the right params
|
|
3577
|
+
expect(callArgs[1]).toBe('UiPassthrough');
|
|
3578
|
+
expect(callArgs[3]).toMatchObject({
|
|
3579
|
+
type: 'getUnsavedAnswerTML',
|
|
3580
|
+
parameters: {
|
|
3581
|
+
sessionId: 'session-123',
|
|
3582
|
+
vizId: 'viz-456'
|
|
3583
|
+
}
|
|
3584
|
+
});
|
|
3585
|
+
expect(result).toEqual(mockTmlResponse);
|
|
3586
|
+
});
|
|
3587
|
+
});
|
|
3588
|
+
|
|
3589
|
+
test('should pass viewConfig to handleInterceptEvent', async () => {
|
|
3590
|
+
const customViewConfig = {
|
|
3591
|
+
...defaultViewConfig,
|
|
3592
|
+
interceptUrls: ['/api/test'],
|
|
3593
|
+
interceptTimeout: 5000,
|
|
3594
|
+
};
|
|
3595
|
+
|
|
3596
|
+
const searchEmbed = new SearchEmbed(getRootEl(), customViewConfig);
|
|
3597
|
+
await searchEmbed.render();
|
|
3598
|
+
|
|
3599
|
+
const mockEventData = {
|
|
3600
|
+
type: EmbedEvent.ApiIntercept,
|
|
3601
|
+
data: JSON.stringify({
|
|
3602
|
+
input: '/api/test',
|
|
3603
|
+
init: {}
|
|
3604
|
+
})
|
|
3605
|
+
};
|
|
3606
|
+
|
|
3607
|
+
const mockPort: any = {
|
|
3608
|
+
postMessage: jest.fn(),
|
|
3609
|
+
};
|
|
3610
|
+
|
|
3611
|
+
await executeAfterWait(() => {
|
|
3612
|
+
const iframe = getIFrameEl();
|
|
3613
|
+
postMessageToParent(iframe.contentWindow, mockEventData, mockPort);
|
|
3614
|
+
});
|
|
3615
|
+
|
|
3616
|
+
await executeAfterWait(() => {
|
|
3617
|
+
const call = mockHandleInterceptEvent.mock.calls[0][0];
|
|
3618
|
+
expect(call.viewConfig).toMatchObject({
|
|
3619
|
+
interceptUrls: ['/api/test'],
|
|
3620
|
+
interceptTimeout: 5000,
|
|
3621
|
+
});
|
|
3622
|
+
});
|
|
3623
|
+
});
|
|
3624
|
+
|
|
3625
|
+
test('should handle ApiIntercept event with eventPort', async () => {
|
|
3626
|
+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
3627
|
+
await searchEmbed.render();
|
|
3628
|
+
|
|
3629
|
+
const mockEventData = {
|
|
3630
|
+
type: EmbedEvent.ApiIntercept,
|
|
3631
|
+
data: JSON.stringify({
|
|
3632
|
+
input: '/prism/?op=GetChartWithData',
|
|
3633
|
+
init: {}
|
|
3634
|
+
})
|
|
3635
|
+
};
|
|
3636
|
+
|
|
3637
|
+
const mockPort: any = {
|
|
3638
|
+
postMessage: jest.fn(),
|
|
3639
|
+
};
|
|
3640
|
+
|
|
3641
|
+
await executeAfterWait(() => {
|
|
3642
|
+
const iframe = getIFrameEl();
|
|
3643
|
+
postMessageToParent(iframe.contentWindow, mockEventData, mockPort);
|
|
3644
|
+
});
|
|
3645
|
+
|
|
3646
|
+
await executeAfterWait(() => {
|
|
3647
|
+
expect(mockHandleInterceptEvent).toHaveBeenCalled();
|
|
3648
|
+
|
|
3649
|
+
// Verify the executeEvent function uses the port
|
|
3650
|
+
const executeEventFn = mockHandleInterceptEvent.mock.calls[0][0].executeEvent;
|
|
3651
|
+
expect(executeEventFn).toBeDefined();
|
|
3652
|
+
});
|
|
3653
|
+
});
|
|
3654
|
+
|
|
3655
|
+
test('should not process non-ApiIntercept events through handleApiInterceptEvent', async () => {
|
|
3656
|
+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
3657
|
+
await searchEmbed.render();
|
|
3658
|
+
|
|
3659
|
+
const mockEventData = {
|
|
3660
|
+
type: EmbedEvent.Save,
|
|
3661
|
+
data: { answerId: '123' },
|
|
3662
|
+
};
|
|
3663
|
+
|
|
3664
|
+
const mockPort: any = {
|
|
3665
|
+
postMessage: jest.fn(),
|
|
3666
|
+
};
|
|
3667
|
+
|
|
3668
|
+
await executeAfterWait(() => {
|
|
3669
|
+
const iframe = getIFrameEl();
|
|
3670
|
+
postMessageToParent(iframe.contentWindow, mockEventData, mockPort);
|
|
3671
|
+
});
|
|
3672
|
+
|
|
3673
|
+
await executeAfterWait(() => {
|
|
3674
|
+
expect(mockHandleInterceptEvent).not.toHaveBeenCalled();
|
|
3675
|
+
});
|
|
3676
|
+
});
|
|
3677
|
+
|
|
3678
|
+
test('should handle multiple ApiIntercept events', async () => {
|
|
3679
|
+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
3680
|
+
await searchEmbed.render();
|
|
3681
|
+
|
|
3682
|
+
const mockEventData1 = {
|
|
3683
|
+
type: EmbedEvent.ApiIntercept,
|
|
3684
|
+
data: JSON.stringify({
|
|
3685
|
+
input: '/prism/?op=GetChartWithData',
|
|
3686
|
+
init: {}
|
|
3687
|
+
})
|
|
3688
|
+
};
|
|
3689
|
+
|
|
3690
|
+
const mockEventData2 = {
|
|
3691
|
+
type: EmbedEvent.ApiIntercept,
|
|
3692
|
+
data: JSON.stringify({
|
|
3693
|
+
input: '/prism/?op=LoadContextBook',
|
|
3694
|
+
init: {}
|
|
3695
|
+
})
|
|
3696
|
+
};
|
|
3697
|
+
|
|
3698
|
+
const mockPort: any = {
|
|
3699
|
+
postMessage: jest.fn(),
|
|
3700
|
+
};
|
|
3701
|
+
|
|
3702
|
+
await executeAfterWait(() => {
|
|
3703
|
+
const iframe = getIFrameEl();
|
|
3704
|
+
postMessageToParent(iframe.contentWindow, mockEventData1, mockPort);
|
|
3705
|
+
});
|
|
3706
|
+
|
|
3707
|
+
await executeAfterWait(() => {
|
|
3708
|
+
postMessageToParent(getIFrameEl().contentWindow, mockEventData2, mockPort);
|
|
3709
|
+
});
|
|
3710
|
+
|
|
3711
|
+
await executeAfterWait(() => {
|
|
3712
|
+
expect(mockHandleInterceptEvent).toHaveBeenCalledTimes(2);
|
|
3713
|
+
});
|
|
3714
|
+
});
|
|
3715
|
+
|
|
3716
|
+
test('should pass eventPort to executeCallbacks', async () => {
|
|
3717
|
+
let capturedExecuteEvent: any;
|
|
3718
|
+
mockHandleInterceptEvent.mockImplementation((params) => {
|
|
3719
|
+
capturedExecuteEvent = params.executeEvent;
|
|
3720
|
+
});
|
|
3721
|
+
|
|
3722
|
+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
3723
|
+
const mockCallback = jest.fn();
|
|
3724
|
+
searchEmbed.on(EmbedEvent.ApiIntercept, mockCallback);
|
|
3725
|
+
await searchEmbed.render();
|
|
3726
|
+
|
|
3727
|
+
const mockEventData = {
|
|
3728
|
+
type: EmbedEvent.ApiIntercept,
|
|
3729
|
+
data: JSON.stringify({
|
|
3730
|
+
input: '/prism/?op=GetChartWithData',
|
|
3731
|
+
init: {}
|
|
3732
|
+
})
|
|
3733
|
+
};
|
|
3734
|
+
|
|
3735
|
+
const mockPort: any = {
|
|
3736
|
+
postMessage: jest.fn(),
|
|
3737
|
+
};
|
|
3738
|
+
|
|
3739
|
+
await executeAfterWait(() => {
|
|
3740
|
+
const iframe = getIFrameEl();
|
|
3741
|
+
postMessageToParent(iframe.contentWindow, mockEventData, mockPort);
|
|
3742
|
+
});
|
|
3743
|
+
|
|
3744
|
+
await executeAfterWait(() => {
|
|
3745
|
+
expect(capturedExecuteEvent).toBeDefined();
|
|
3746
|
+
|
|
3747
|
+
// Call executeEvent with a response
|
|
3748
|
+
const responseData = { execute: true };
|
|
3749
|
+
capturedExecuteEvent(EmbedEvent.ApiIntercept, responseData);
|
|
3750
|
+
|
|
3751
|
+
// Verify the callback was invoked with the data
|
|
3752
|
+
expect(mockCallback).toHaveBeenCalled();
|
|
3753
|
+
expect(mockCallback.mock.calls[0][0]).toEqual(responseData);
|
|
3754
|
+
});
|
|
3755
|
+
});
|
|
3756
|
+
|
|
3757
|
+
test('should handle getUnsavedAnswerTml with empty response', async () => {
|
|
3758
|
+
let capturedGetUnsavedAnswerTml: any;
|
|
3759
|
+
mockHandleInterceptEvent.mockImplementation((params) => {
|
|
3760
|
+
capturedGetUnsavedAnswerTml = params.getUnsavedAnswerTml;
|
|
3761
|
+
});
|
|
3762
|
+
|
|
3763
|
+
mockProcessTrigger.mockResolvedValue([]);
|
|
3764
|
+
|
|
3765
|
+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
3766
|
+
await searchEmbed.render();
|
|
3767
|
+
|
|
3768
|
+
const mockEventData = {
|
|
3769
|
+
type: EmbedEvent.ApiIntercept,
|
|
3770
|
+
data: JSON.stringify({
|
|
3771
|
+
input: '/prism/?op=GetChartWithData',
|
|
3772
|
+
init: {}
|
|
3773
|
+
})
|
|
3774
|
+
};
|
|
3775
|
+
|
|
3776
|
+
const mockPort: any = {
|
|
3777
|
+
postMessage: jest.fn(),
|
|
3778
|
+
};
|
|
3779
|
+
|
|
3780
|
+
await executeAfterWait(() => {
|
|
3781
|
+
const iframe = getIFrameEl();
|
|
3782
|
+
postMessageToParent(iframe.contentWindow, mockEventData, mockPort);
|
|
3783
|
+
});
|
|
3784
|
+
|
|
3785
|
+
await executeAfterWait(async () => {
|
|
3786
|
+
expect(capturedGetUnsavedAnswerTml).toBeDefined();
|
|
3787
|
+
|
|
3788
|
+
const result = await capturedGetUnsavedAnswerTml({
|
|
3789
|
+
sessionId: 'session-123',
|
|
3790
|
+
vizId: 'viz-456'
|
|
3791
|
+
});
|
|
3792
|
+
|
|
3793
|
+
expect(result).toBeUndefined();
|
|
3794
|
+
});
|
|
3795
|
+
});
|
|
3796
|
+
|
|
3797
|
+
test('should work with LiveboardEmbed', async () => {
|
|
3798
|
+
const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
|
|
3799
|
+
...defaultViewConfig,
|
|
3800
|
+
liveboardId: 'test-liveboard-id',
|
|
3801
|
+
});
|
|
3802
|
+
await liveboardEmbed.render();
|
|
3803
|
+
|
|
3804
|
+
const mockEventData = {
|
|
3805
|
+
type: EmbedEvent.ApiIntercept,
|
|
3806
|
+
data: JSON.stringify({
|
|
3807
|
+
input: '/prism/?op=LoadContextBook',
|
|
3808
|
+
init: {}
|
|
3809
|
+
})
|
|
3810
|
+
};
|
|
3811
|
+
|
|
3812
|
+
const mockPort: any = {
|
|
3813
|
+
postMessage: jest.fn(),
|
|
3814
|
+
};
|
|
3815
|
+
|
|
3816
|
+
await executeAfterWait(() => {
|
|
3817
|
+
const iframe = getIFrameEl();
|
|
3818
|
+
postMessageToParent(iframe.contentWindow, mockEventData, mockPort);
|
|
3819
|
+
});
|
|
3820
|
+
|
|
3821
|
+
await executeAfterWait(() => {
|
|
3822
|
+
expect(mockHandleInterceptEvent).toHaveBeenCalledTimes(1);
|
|
3823
|
+
expect(mockHandleInterceptEvent).toHaveBeenCalledWith(
|
|
3824
|
+
expect.objectContaining({
|
|
3825
|
+
eventData: mockEventData,
|
|
3826
|
+
})
|
|
3827
|
+
);
|
|
3828
|
+
});
|
|
3829
|
+
});
|
|
3830
|
+
});
|
|
3583
3831
|
});
|