@thoughtspot/visual-embed-sdk 1.20.0-prerender.2 → 1.20.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/README.md +1 -1
- package/dist/src/auth.d.ts +2 -38
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/config.d.ts +0 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/embed/app.d.ts +5 -17
- package/dist/src/embed/app.d.ts.map +1 -1
- package/dist/src/embed/base.d.ts +9 -20
- package/dist/src/embed/base.d.ts.map +1 -1
- package/dist/src/embed/liveboard.d.ts +5 -17
- package/dist/src/embed/liveboard.d.ts.map +1 -1
- package/dist/src/embed/search-bar.d.ts +0 -3
- package/dist/src/embed/search-bar.d.ts.map +1 -1
- package/dist/src/embed/search.d.ts +5 -9
- package/dist/src/embed/search.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +6 -43
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/mixpanel-service.d.ts +0 -8
- package/dist/src/mixpanel-service.d.ts.map +1 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/util.d.ts +0 -4
- package/dist/src/react/util.d.ts.map +1 -1
- package/dist/src/test/test-utils.d.ts +2 -11
- package/dist/src/test/test-utils.d.ts.map +1 -1
- package/dist/src/types.d.ts +76 -273
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/answerService.d.ts +0 -7
- package/dist/src/utils/answerService.d.ts.map +1 -1
- package/dist/src/utils/authService.d.ts +0 -30
- package/dist/src/utils/authService.d.ts.map +1 -1
- package/dist/src/utils/processData.d.ts +0 -12
- package/dist/src/utils/processData.d.ts.map +1 -1
- package/dist/src/utils/processTrigger.d.ts +0 -7
- package/dist/src/utils/processTrigger.d.ts.map +1 -1
- package/dist/src/utils.d.ts +0 -12
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/tsembed.es.js +262 -637
- package/dist/tsembed.js +261 -629
- package/lib/package.json +8 -3
- package/lib/src/auth.d.ts +2 -38
- package/lib/src/auth.d.ts.map +1 -1
- package/lib/src/auth.js +25 -70
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.js +5 -14
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/config.d.ts +0 -1
- package/lib/src/config.d.ts.map +1 -1
- package/lib/src/config.js +3 -5
- package/lib/src/config.js.map +1 -1
- package/lib/src/config.spec.js.map +1 -1
- package/lib/src/embed/app.d.ts +5 -17
- package/lib/src/embed/app.d.ts.map +1 -1
- package/lib/src/embed/app.js +15 -25
- package/lib/src/embed/app.js.map +1 -1
- package/lib/src/embed/app.spec.js +12 -12
- package/lib/src/embed/app.spec.js.map +1 -1
- package/lib/src/embed/base.d.ts +9 -20
- package/lib/src/embed/base.d.ts.map +1 -1
- package/lib/src/embed/base.js +15 -31
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js.map +1 -1
- package/lib/src/embed/embed.spec.js +1 -1
- package/lib/src/embed/embed.spec.js.map +1 -1
- package/lib/src/embed/liveboard.d.ts +5 -17
- package/lib/src/embed/liveboard.d.ts.map +1 -1
- package/lib/src/embed/liveboard.js +37 -49
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +30 -37
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/pinboard.spec.js +26 -14
- package/lib/src/embed/pinboard.spec.js.map +1 -1
- package/lib/src/embed/search-bar.d.ts +0 -3
- package/lib/src/embed/search-bar.d.ts.map +1 -1
- package/lib/src/embed/search-bar.js +6 -5
- package/lib/src/embed/search-bar.js.map +1 -1
- package/lib/src/embed/search.d.ts +5 -9
- package/lib/src/embed/search.d.ts.map +1 -1
- package/lib/src/embed/search.js +14 -18
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/search.spec.js +19 -16
- package/lib/src/embed/search.spec.js.map +1 -1
- package/lib/src/embed/searchEmbed-basic-auth.spec.js +0 -4
- package/lib/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +6 -43
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +72 -117
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +24 -23
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/errors.d.ts.map +1 -1
- package/lib/src/errors.js.map +1 -1
- 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/mixpanel-service.d.ts +0 -8
- package/lib/src/mixpanel-service.d.ts.map +1 -1
- package/lib/src/mixpanel-service.js +1 -13
- package/lib/src/mixpanel-service.js.map +1 -1
- package/lib/src/mixpanel-service.spec.js.map +1 -1
- package/lib/src/react/index.d.ts.map +1 -1
- package/lib/src/react/index.js +6 -6
- package/lib/src/react/index.js.map +1 -1
- package/lib/src/react/index.spec.js +6 -15
- package/lib/src/react/index.spec.js.map +1 -1
- package/lib/src/react/util.d.ts +0 -4
- package/lib/src/react/util.d.ts.map +1 -1
- package/lib/src/react/util.js +0 -4
- package/lib/src/react/util.js.map +1 -1
- package/lib/src/test/test-utils.d.ts +2 -11
- package/lib/src/test/test-utils.d.ts.map +1 -1
- package/lib/src/test/test-utils.js +25 -36
- package/lib/src/test/test-utils.js.map +1 -1
- package/lib/src/types.d.ts +76 -273
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js +54 -200
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/answerService.d.ts +0 -7
- package/lib/src/utils/answerService.d.ts.map +1 -1
- package/lib/src/utils/answerService.js +0 -7
- package/lib/src/utils/answerService.js.map +1 -1
- package/lib/src/utils/answerService.spec.js.map +1 -1
- package/lib/src/utils/authService.d.ts +0 -30
- package/lib/src/utils/authService.d.ts.map +1 -1
- package/lib/src/utils/authService.js +2 -39
- package/lib/src/utils/authService.js.map +1 -1
- package/lib/src/utils/authService.spec.js.map +1 -1
- package/lib/src/utils/processData.d.ts +0 -12
- package/lib/src/utils/processData.d.ts.map +1 -1
- package/lib/src/utils/processData.js +5 -33
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/lib/src/utils/processTrigger.d.ts +0 -7
- package/lib/src/utils/processTrigger.d.ts.map +1 -1
- package/lib/src/utils/processTrigger.js +3 -17
- package/lib/src/utils/processTrigger.js.map +1 -1
- package/lib/src/utils/processTrigger.spec.js.map +1 -1
- package/lib/src/utils.d.ts +0 -12
- package/lib/src/utils.d.ts.map +1 -1
- package/lib/src/utils.js +19 -24
- package/lib/src/utils.js.map +1 -1
- package/lib/src/utils.spec.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +102 -406
- package/package.json +8 -3
- package/src/auth.spec.ts +150 -68
- package/src/auth.ts +108 -102
- package/src/config.spec.ts +4 -2
- package/src/config.ts +3 -5
- package/src/embed/app.spec.ts +14 -25
- package/src/embed/app.ts +35 -47
- package/src/embed/base.spec.ts +9 -3
- package/src/embed/base.ts +53 -51
- package/src/embed/embed.spec.ts +6 -5
- package/src/embed/liveboard.spec.ts +37 -56
- package/src/embed/liveboard.ts +64 -66
- package/src/embed/pinboard.spec.ts +29 -26
- package/src/embed/search-bar.tsx +8 -10
- package/src/embed/search.spec.ts +21 -31
- package/src/embed/search.ts +25 -26
- package/src/embed/searchEmbed-basic-auth.spec.ts +28 -22
- package/src/embed/ts-embed.spec.ts +148 -70
- package/src/embed/ts-embed.ts +157 -147
- package/src/errors.ts +6 -3
- package/src/index.ts +10 -4
- package/src/mixpanel-service.spec.ts +3 -1
- package/src/mixpanel-service.ts +1 -13
- package/src/react/index.spec.tsx +13 -37
- package/src/react/index.tsx +57 -38
- package/src/react/util.ts +4 -8
- package/src/test/test-utils.ts +39 -43
- package/src/types.ts +78 -270
- package/src/utils/answerService.spec.ts +5 -3
- package/src/utils/answerService.ts +17 -21
- package/src/utils/authService.spec.ts +41 -26
- package/src/utils/authService.ts +21 -47
- package/src/utils/processData.spec.ts +59 -26
- package/src/utils/processData.ts +14 -36
- package/src/utils/processTrigger.spec.ts +6 -1
- package/src/utils/processTrigger.ts +9 -18
- package/src/utils.spec.ts +12 -8
- package/src/utils.ts +26 -25
package/src/mixpanel-service.ts
CHANGED
|
@@ -19,7 +19,6 @@ let eventQueue: { eventId: string; eventProps: any }[] = [];
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Pushes the event with its Property key-value map to mixpanel.
|
|
22
|
-
*
|
|
23
22
|
* @param eventId
|
|
24
23
|
* @param eventProps
|
|
25
24
|
*/
|
|
@@ -31,9 +30,6 @@ export function uploadMixpanelEvent(eventId: string, eventProps = {}): void {
|
|
|
31
30
|
mixpanel.track(eventId, eventProps);
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
33
|
function emptyQueue() {
|
|
38
34
|
if (!isMixpanelInitialized) {
|
|
39
35
|
return;
|
|
@@ -44,16 +40,11 @@ function emptyQueue() {
|
|
|
44
40
|
eventQueue = [];
|
|
45
41
|
}
|
|
46
42
|
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param sessionInfo
|
|
50
|
-
*/
|
|
51
43
|
export function initMixpanel(sessionInfo: any): void {
|
|
52
44
|
if (!sessionInfo || !sessionInfo.mixpanelToken) {
|
|
53
45
|
return;
|
|
54
46
|
}
|
|
55
|
-
// On a public cluster the user is anonymous, so don't set the identify to
|
|
56
|
-
// userGUID
|
|
47
|
+
// On a public cluster the user is anonymous, so don't set the identify to userGUID
|
|
57
48
|
const isPublicCluster = !!sessionInfo.isPublicUser;
|
|
58
49
|
const token = sessionInfo.mixpanelToken;
|
|
59
50
|
if (token) {
|
|
@@ -66,9 +57,6 @@ export function initMixpanel(sessionInfo: any): void {
|
|
|
66
57
|
}
|
|
67
58
|
}
|
|
68
59
|
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
60
|
export function testResetMixpanel() {
|
|
73
61
|
isMixpanelInitialized = false;
|
|
74
62
|
eventQueue = [];
|
package/src/react/index.spec.tsx
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import '@testing-library/jest-dom';
|
|
3
3
|
import '@testing-library/jest-dom/extend-expect';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from '@testing-library/react';
|
|
7
|
-
import {
|
|
8
|
-
Action, EmbedEvent, HostEvent, RuntimeFilterOp,
|
|
9
|
-
} from '../types';
|
|
4
|
+
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react';
|
|
5
|
+
import { Action, EmbedEvent, HostEvent, RuntimeFilterOp } from '../types';
|
|
10
6
|
import {
|
|
11
7
|
executeAfterWait,
|
|
12
8
|
getIFrameEl,
|
|
@@ -15,7 +11,11 @@ import {
|
|
|
15
11
|
mockMessageChannel,
|
|
16
12
|
} from '../test/test-utils';
|
|
17
13
|
import {
|
|
18
|
-
SearchEmbed,
|
|
14
|
+
SearchEmbed,
|
|
15
|
+
AppEmbed,
|
|
16
|
+
LiveboardEmbed,
|
|
17
|
+
useEmbedRef,
|
|
18
|
+
SearchBarEmbed,
|
|
19
19
|
} from './index';
|
|
20
20
|
import { AuthType, init } from '../index';
|
|
21
21
|
|
|
@@ -86,7 +86,10 @@ describe('React Components', () => {
|
|
|
86
86
|
const TestComponent = () => {
|
|
87
87
|
const embedRef = useEmbedRef();
|
|
88
88
|
const onLiveboardRendered = () => {
|
|
89
|
-
embedRef.current.trigger(HostEvent.SetVisibleVizs, [
|
|
89
|
+
embedRef.current.trigger(HostEvent.SetVisibleVizs, [
|
|
90
|
+
'viz1',
|
|
91
|
+
'viz2',
|
|
92
|
+
]);
|
|
90
93
|
};
|
|
91
94
|
|
|
92
95
|
return (
|
|
@@ -136,36 +139,9 @@ describe('React Components', () => {
|
|
|
136
139
|
);
|
|
137
140
|
|
|
138
141
|
await waitFor(() => getIFrameEl(container));
|
|
139
|
-
expect(getIFrameSrc(container)).toContain(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
it('Should have the correct container element', async () => {
|
|
143
|
-
const { container } = render(
|
|
144
|
-
<LiveboardEmbed liveboardId="abcd" className="def" />,
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
await waitFor(() => getIFrameEl(container));
|
|
148
|
-
expect(container.querySelector('div')).not.toBe(null);
|
|
149
|
-
expect(
|
|
150
|
-
container.querySelector('div').classList.contains('def'),
|
|
151
|
-
).toBe(true);
|
|
152
|
-
|
|
153
|
-
const { container: containerSibling } = render(
|
|
154
|
-
<LiveboardEmbed
|
|
155
|
-
liveboardId="abcd"
|
|
156
|
-
className="def"
|
|
157
|
-
insertAsSibling={true}
|
|
158
|
-
/>,
|
|
142
|
+
expect(getIFrameSrc(container)).toContain(
|
|
143
|
+
'col1=revenue&op1=EQ&val1=100',
|
|
159
144
|
);
|
|
160
|
-
await waitFor(() => getIFrameEl(containerSibling));
|
|
161
|
-
expect(containerSibling.querySelector('span')).not.toBe(null);
|
|
162
|
-
expect(containerSibling.querySelector('span').style.position).toBe(
|
|
163
|
-
'absolute',
|
|
164
|
-
);
|
|
165
|
-
expect(
|
|
166
|
-
getIFrameEl(containerSibling).classList.contains('def'),
|
|
167
|
-
).toBe(true);
|
|
168
|
-
expect(containerSibling.querySelector('div')).toBe(null);
|
|
169
145
|
});
|
|
170
146
|
|
|
171
147
|
it('Should have the correct container element', async () => {
|
package/src/react/index.tsx
CHANGED
|
@@ -1,27 +1,38 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import useDeepCompareEffect from 'use-deep-compare-effect';
|
|
3
3
|
import { deepMerge } from '../utils';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
SearchBarEmbed as _SearchBarEmbed,
|
|
6
|
+
SearchBarViewConfig,
|
|
7
|
+
} from '../embed/search-bar';
|
|
5
8
|
import { SearchEmbed as _SearchEmbed, SearchViewConfig } from '../embed/search';
|
|
6
9
|
import { AppEmbed as _AppEmbed, AppViewConfig } from '../embed/app';
|
|
7
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
LiveboardEmbed as _LiveboardEmbed,
|
|
12
|
+
LiveboardViewConfig,
|
|
13
|
+
} from '../embed/liveboard';
|
|
8
14
|
import { TsEmbed } from '../embed/ts-embed';
|
|
9
15
|
|
|
10
16
|
import { EmbedEvent, ViewConfig } from '../types';
|
|
11
17
|
import { EmbedProps, getViewPropsAndListeners } from './util';
|
|
12
18
|
|
|
13
|
-
const componentFactory = <
|
|
19
|
+
const componentFactory = <
|
|
20
|
+
T extends typeof TsEmbed,
|
|
21
|
+
U extends EmbedProps,
|
|
22
|
+
V extends ViewConfig
|
|
23
|
+
>(
|
|
14
24
|
EmbedConstructor: T,
|
|
15
|
-
) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
) =>
|
|
26
|
+
React.forwardRef<TsEmbed, U>(
|
|
27
|
+
(props: U, forwardedRef: React.MutableRefObject<TsEmbed>) => {
|
|
28
|
+
const ref = React.useRef<HTMLDivElement>(null);
|
|
29
|
+
const { className, ...embedProps } = props;
|
|
30
|
+
const { viewConfig, listeners } = getViewPropsAndListeners<
|
|
20
31
|
Omit<U, 'className'>,
|
|
21
32
|
V
|
|
22
33
|
>(embedProps);
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
useDeepCompareEffect(() => {
|
|
35
|
+
const tsEmbed = new EmbedConstructor(
|
|
25
36
|
ref!.current,
|
|
26
37
|
deepMerge(
|
|
27
38
|
{
|
|
@@ -34,48 +45,54 @@ const componentFactory = <T extends typeof TsEmbed, U extends EmbedProps, V exte
|
|
|
34
45
|
},
|
|
35
46
|
viewConfig,
|
|
36
47
|
),
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
);
|
|
49
|
+
Object.keys(listeners).forEach((eventName) => {
|
|
50
|
+
tsEmbed.on(
|
|
40
51
|
eventName as EmbedEvent,
|
|
41
52
|
listeners[eventName as EmbedEvent],
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
tsEmbed.render();
|
|
56
|
+
if (forwardedRef) {
|
|
57
|
+
// eslint-disable-next-line no-param-reassign
|
|
58
|
+
forwardedRef.current = tsEmbed;
|
|
59
|
+
}
|
|
60
|
+
return () => {
|
|
61
|
+
tsEmbed.destroy();
|
|
62
|
+
};
|
|
63
|
+
}, [viewConfig, listeners]);
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
? <span
|
|
65
|
+
return viewConfig.insertAsSibling ? (
|
|
66
|
+
<span
|
|
57
67
|
data-testid="tsEmbed"
|
|
58
68
|
ref={ref}
|
|
59
69
|
style={{ position: 'absolute' }}
|
|
60
70
|
></span>
|
|
61
|
-
|
|
71
|
+
) : (
|
|
72
|
+
<div
|
|
62
73
|
data-testid="tsEmbed"
|
|
63
74
|
ref={ref}
|
|
64
|
-
className={className}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
75
|
+
className={className}
|
|
76
|
+
></div>
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
);
|
|
69
80
|
|
|
70
81
|
interface SearchProps extends EmbedProps, SearchViewConfig {}
|
|
71
82
|
|
|
72
|
-
export const SearchEmbed = componentFactory<
|
|
73
|
-
_SearchEmbed,
|
|
74
|
-
|
|
83
|
+
export const SearchEmbed = componentFactory<
|
|
84
|
+
typeof _SearchEmbed,
|
|
85
|
+
SearchProps,
|
|
86
|
+
SearchViewConfig
|
|
87
|
+
>(_SearchEmbed);
|
|
75
88
|
|
|
76
89
|
interface AppProps extends EmbedProps, AppViewConfig {}
|
|
77
90
|
|
|
78
|
-
export const AppEmbed = componentFactory<
|
|
91
|
+
export const AppEmbed = componentFactory<
|
|
92
|
+
typeof _AppEmbed,
|
|
93
|
+
AppProps,
|
|
94
|
+
AppViewConfig
|
|
95
|
+
>(_AppEmbed);
|
|
79
96
|
|
|
80
97
|
interface LiveboardProps extends EmbedProps, LiveboardViewConfig {}
|
|
81
98
|
|
|
@@ -99,4 +116,6 @@ export const SearchBarEmbed = componentFactory<
|
|
|
99
116
|
SearchBarViewConfig
|
|
100
117
|
>(_SearchBarEmbed);
|
|
101
118
|
|
|
102
|
-
export const useEmbedRef = (): React.MutableRefObject<TsEmbed> =>
|
|
119
|
+
export const useEmbedRef = (): React.MutableRefObject<TsEmbed> => {
|
|
120
|
+
return React.useRef<TsEmbed>(null);
|
|
121
|
+
};
|
package/src/react/util.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { EmbedEvent, MessageCallback, ViewConfig } from '../types';
|
|
2
2
|
|
|
3
|
+
// eslint-disable-next-line prettier/prettier
|
|
3
4
|
export type EmbedEventHandlers = { [key in keyof typeof EmbedEvent as `on${Capitalize<key>}`]?: MessageCallback };
|
|
4
5
|
|
|
6
|
+
|
|
5
7
|
export interface EmbedProps extends ViewConfig, EmbedEventHandlers {
|
|
6
8
|
className?: string;
|
|
7
9
|
}
|
|
@@ -11,13 +13,7 @@ export interface ViewConfigAndListeners<T extends ViewConfig> {
|
|
|
11
13
|
listeners: { [key in EmbedEvent]?: MessageCallback };
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @param props
|
|
17
|
-
*/
|
|
18
|
-
export function getViewPropsAndListeners<
|
|
19
|
-
T extends EmbedProps,
|
|
20
|
-
U extends ViewConfig>(props: T): ViewConfigAndListeners<U> {
|
|
16
|
+
export function getViewPropsAndListeners<T extends EmbedProps, U extends ViewConfig>(props: T): ViewConfigAndListeners<U> {
|
|
21
17
|
return Object.keys(props).reduce(
|
|
22
18
|
(accu, key) => {
|
|
23
19
|
if (key.startsWith('on')) {
|
|
@@ -33,4 +29,4 @@ export function getViewPropsAndListeners<
|
|
|
33
29
|
listeners: {},
|
|
34
30
|
},
|
|
35
31
|
);
|
|
36
|
-
}
|
|
32
|
+
}
|
package/src/test/test-utils.ts
CHANGED
|
@@ -3,15 +3,18 @@ import { Action, AuthType } from '../types';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
Initialises fetch to the global object
|
|
6
|
-
|
|
7
|
-
global.fetch = jest.fn(() =>
|
|
8
|
-
|
|
9
|
-
})
|
|
6
|
+
*/
|
|
7
|
+
global.fetch = jest.fn(() =>
|
|
8
|
+
Promise.resolve({
|
|
9
|
+
json: () => ({ mixpanelAccessToken: '' }),
|
|
10
|
+
}),
|
|
11
|
+
);
|
|
10
12
|
|
|
11
13
|
export const defaultParamsWithoutHiddenActions = `hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}&authType=${AuthType.None}`;
|
|
12
14
|
export const defaultParams = `&${defaultParamsWithoutHiddenActions}&hideAction=[%22${Action.ReportError}%22]`;
|
|
13
15
|
export const defaultParamsForPinboardEmbed = `hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}&authType=None&hideAction=[%22${Action.ReportError}%22]`;
|
|
14
|
-
export const getDocumentBody = () =>
|
|
16
|
+
export const getDocumentBody = () =>
|
|
17
|
+
'<div id="embed"></div><div id="embed-2"></div>';
|
|
15
18
|
|
|
16
19
|
type DOMElement = HTMLElement | Document;
|
|
17
20
|
|
|
@@ -19,33 +22,40 @@ export const getRootEl = () => document.getElementById('embed');
|
|
|
19
22
|
|
|
20
23
|
export const getRootEl2 = () => document.getElementById('embed-2');
|
|
21
24
|
|
|
22
|
-
export const getIFrameEl = (container: DOMElement = document) =>
|
|
25
|
+
export const getIFrameEl = (container: DOMElement = document) => {
|
|
26
|
+
return container.querySelector('iframe');
|
|
27
|
+
};
|
|
23
28
|
|
|
24
29
|
export const getAllIframeEl = () => document.querySelectorAll('iframe');
|
|
25
30
|
|
|
26
|
-
export const getIFrameSrc = (container: DOMElement = document) =>
|
|
31
|
+
export const getIFrameSrc = (container: DOMElement = document) =>
|
|
32
|
+
getIFrameEl(container).src;
|
|
27
33
|
|
|
28
|
-
export const waitFor = (fn: () => boolean): Promise<void> =>
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
34
|
+
export const waitFor = (fn: () => boolean): Promise<void> => {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
const interval = setInterval(() => {
|
|
37
|
+
const value = fn();
|
|
38
|
+
if (value) {
|
|
39
|
+
clearInterval(interval);
|
|
40
|
+
resolve();
|
|
41
|
+
}
|
|
42
|
+
}, 100);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
37
45
|
|
|
38
46
|
/**
|
|
39
47
|
* jsdom does not set event source, therefore we do it
|
|
40
48
|
* programmatically and use dispatchEvent instead of the
|
|
41
49
|
* postMessage API
|
|
42
50
|
* Reference: https://github.com/jsdom/jsdom/issues/2745
|
|
43
|
-
*
|
|
44
51
|
* @param window
|
|
45
52
|
* @param data
|
|
46
|
-
* @param port
|
|
47
53
|
*/
|
|
48
|
-
export const postMessageToParent = (
|
|
54
|
+
export const postMessageToParent = (
|
|
55
|
+
window: WindowProxy,
|
|
56
|
+
data: any,
|
|
57
|
+
port?: any,
|
|
58
|
+
) => {
|
|
49
59
|
const message = new MessageEvent('message', {
|
|
50
60
|
data,
|
|
51
61
|
source: window,
|
|
@@ -56,37 +66,33 @@ export const postMessageToParent = (window: WindowProxy, data: any, port?: any)
|
|
|
56
66
|
|
|
57
67
|
/**
|
|
58
68
|
* Execute a given function after a certain time has elapsed
|
|
59
|
-
*
|
|
60
69
|
* @param fn The function to be executed after the wait period
|
|
61
70
|
* @param waitTime The wait period in milliseconds
|
|
62
71
|
*/
|
|
63
72
|
export const executeAfterWait = (
|
|
64
73
|
fn: (...args: any[]) => void,
|
|
65
74
|
waitTime = 0,
|
|
66
|
-
) =>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
75
|
+
) => {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
const value = fn();
|
|
79
|
+
resolve(value);
|
|
80
|
+
}, waitTime);
|
|
81
|
+
});
|
|
82
|
+
};
|
|
72
83
|
|
|
73
84
|
/**
|
|
74
85
|
* Time (in milliseconds) to wait for async events to be triggered
|
|
75
86
|
*/
|
|
76
87
|
export const EVENT_WAIT_TIME = 1000;
|
|
77
88
|
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
* @param str
|
|
81
|
-
*/
|
|
82
89
|
export function fixedEncodeURI(str: string) {
|
|
83
90
|
return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
/**
|
|
87
|
-
* MessageChannel is available in Node > 15.0.0. Since the current node
|
|
88
|
-
*
|
|
89
|
-
* for the current unit tests.
|
|
94
|
+
* MessageChannel is available in Node > 15.0.0. Since the current node environment's
|
|
95
|
+
* used for github actions is not above 14, we are mocking this for the current unit tests.
|
|
90
96
|
*/
|
|
91
97
|
export const messageChannelMock: any = {
|
|
92
98
|
port1: {},
|
|
@@ -99,13 +105,3 @@ export const mockMessageChannel = () => {
|
|
|
99
105
|
return messageChannelMock;
|
|
100
106
|
} as any;
|
|
101
107
|
};
|
|
102
|
-
|
|
103
|
-
export const expectUrlMatchesWithParams = (source: string, target: string) => {
|
|
104
|
-
const sourceUrl = new URL(source);
|
|
105
|
-
const targetUrl = new URL(target);
|
|
106
|
-
expect(sourceUrl.origin).toBe(targetUrl.origin);
|
|
107
|
-
expect(sourceUrl.pathname).toBe(targetUrl.pathname);
|
|
108
|
-
const sourceParamsObj = Object.fromEntries(sourceUrl.searchParams);
|
|
109
|
-
const targetParamsObj = Object.fromEntries(targetUrl.searchParams);
|
|
110
|
-
expect(sourceParamsObj).toMatchObject(targetParamsObj);
|
|
111
|
-
};
|