@maxzima/wa-communicator 0.0.14 → 0.0.15
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/dist/engine/utils.js +1 -1
- package/dist/enums/CommunicatorActionEnum.d.ts +1 -0
- package/dist/enums/CommunicatorActionEnum.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/engine/utils.ts +1 -1
- package/src/enums/CommunicatorActionEnum.ts +2 -1
- package/src/types/index.ts +1 -0
- package/test/testUnits/queue.ts +160 -51
- package/test/testUnits/scenario.ts +31 -0
- package/test/utiles.spec.ts +30 -5
package/dist/engine/utils.js
CHANGED
|
@@ -10,7 +10,7 @@ export function modifyOrigin(address) {
|
|
|
10
10
|
catch (_) {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
|
-
return url.origin;
|
|
13
|
+
return url.origin !== 'null' ? url.origin : null;
|
|
14
14
|
}
|
|
15
15
|
export function isValidMessage(message) {
|
|
16
16
|
const isValidTarget = message.target && CommunicatorTargetEnum_isCorrect(message.target);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare type TCommunicatorActionGotoParams = {
|
|
|
23
23
|
isTargetBlank?: boolean;
|
|
24
24
|
};
|
|
25
25
|
export declare type TCommunicatorSenderActionMap = {
|
|
26
|
+
[CommunicatorActionEnum.LOADED]?: true;
|
|
26
27
|
[CommunicatorActionEnum.TOKEN]?: TCommunicatorActionTokenParams;
|
|
27
28
|
[CommunicatorActionEnum.RESIZE]?: TCommunicatorActionResizeParams;
|
|
28
29
|
[CommunicatorActionEnum.GOTO]?: TCommunicatorActionGotoParams;
|
package/package.json
CHANGED
package/src/engine/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export enum CommunicatorActionEnum {
|
|
2
|
+
LOADED = 'loaded',
|
|
2
3
|
TOKEN = 'token',
|
|
3
4
|
RESIZE = 'resize',
|
|
4
5
|
CLOSE = 'close',
|
|
@@ -11,5 +12,5 @@ export function CommunicatorActionEnum_isCorrect(item: string): boolean {
|
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export function CommunicatorActionEnum_scenario(): CommunicatorActionEnum[] {
|
|
14
|
-
return Object.values(CommunicatorActionEnum);
|
|
15
|
+
return Object.values(CommunicatorActionEnum) as CommunicatorActionEnum[];
|
|
15
16
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export type TCommunicatorActionGotoParams = {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export type TCommunicatorSenderActionMap = {
|
|
33
|
+
[CommunicatorActionEnum.LOADED]?: true,
|
|
33
34
|
[CommunicatorActionEnum.TOKEN]?: TCommunicatorActionTokenParams,
|
|
34
35
|
[CommunicatorActionEnum.RESIZE]?: TCommunicatorActionResizeParams,
|
|
35
36
|
[CommunicatorActionEnum.GOTO]?: TCommunicatorActionGotoParams,
|
package/test/testUnits/queue.ts
CHANGED
|
@@ -1,56 +1,165 @@
|
|
|
1
1
|
import {TReceiverMessageQueue} from '../../src/types';
|
|
2
2
|
import {CommunicatorActionEnum, CommunicatorTargetEnum} from '../../src';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
4
|
+
const queueWithoutSorting: TReceiverMessageQueue = [
|
|
5
|
+
{
|
|
6
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
7
|
+
action: CommunicatorActionEnum.OPEN,
|
|
8
|
+
params: {
|
|
9
|
+
callback: () => {}
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
14
|
+
action: CommunicatorActionEnum.CLOSE,
|
|
15
|
+
params: {
|
|
16
|
+
callback: () => {}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
21
|
+
action: CommunicatorActionEnum.GOTO,
|
|
22
|
+
params: {
|
|
23
|
+
callback: () => {}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
28
|
+
action: CommunicatorActionEnum.TOKEN,
|
|
29
|
+
params: {
|
|
30
|
+
callback: () => {}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
];
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
const queueWithDefaultScenario: TReceiverMessageQueue = [
|
|
36
|
+
{
|
|
37
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
38
|
+
action: CommunicatorActionEnum.TOKEN,
|
|
39
|
+
params: {
|
|
40
|
+
callback: () => {}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
45
|
+
action: CommunicatorActionEnum.CLOSE,
|
|
46
|
+
params: {
|
|
47
|
+
callback: () => {}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
52
|
+
action: CommunicatorActionEnum.OPEN,
|
|
53
|
+
params: {
|
|
54
|
+
callback: () => {}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
59
|
+
action: CommunicatorActionEnum.GOTO,
|
|
60
|
+
params: {
|
|
61
|
+
callback: () => {}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
];
|
|
55
65
|
|
|
56
|
-
|
|
66
|
+
const queueWithCustomScenario: TReceiverMessageQueue = [
|
|
67
|
+
{
|
|
68
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
69
|
+
action: CommunicatorActionEnum.OPEN,
|
|
70
|
+
params: {
|
|
71
|
+
callback: () => {}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
76
|
+
action: CommunicatorActionEnum.CLOSE,
|
|
77
|
+
params: {
|
|
78
|
+
callback: () => {}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
83
|
+
action: CommunicatorActionEnum.TOKEN,
|
|
84
|
+
params: {
|
|
85
|
+
callback: () => {}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
90
|
+
action: CommunicatorActionEnum.GOTO,
|
|
91
|
+
params: {
|
|
92
|
+
callback: () => {}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
const queueWithCustomV2Scenario: TReceiverMessageQueue = [
|
|
98
|
+
{
|
|
99
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
100
|
+
action: CommunicatorActionEnum.CLOSE,
|
|
101
|
+
params: {
|
|
102
|
+
callback: () => {}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
107
|
+
action: CommunicatorActionEnum.TOKEN,
|
|
108
|
+
params: {
|
|
109
|
+
callback: () => {}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
114
|
+
action: CommunicatorActionEnum.OPEN,
|
|
115
|
+
params: {
|
|
116
|
+
callback: () => {}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
121
|
+
action: CommunicatorActionEnum.GOTO,
|
|
122
|
+
params: {
|
|
123
|
+
callback: () => {}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
const queueWithCustomV3Scenario: TReceiverMessageQueue = [
|
|
129
|
+
{
|
|
130
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
131
|
+
action: CommunicatorActionEnum.OPEN,
|
|
132
|
+
params: {
|
|
133
|
+
callback: () => {}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
138
|
+
action: CommunicatorActionEnum.CLOSE,
|
|
139
|
+
params: {
|
|
140
|
+
callback: () => {}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
145
|
+
action: CommunicatorActionEnum.TOKEN,
|
|
146
|
+
params: {
|
|
147
|
+
callback: () => {}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
target: CommunicatorTargetEnum.SIGN_IN,
|
|
152
|
+
action: CommunicatorActionEnum.GOTO,
|
|
153
|
+
params: {
|
|
154
|
+
callback: () => {}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
export {
|
|
160
|
+
queueWithoutSorting,
|
|
161
|
+
queueWithDefaultScenario,
|
|
162
|
+
queueWithCustomScenario,
|
|
163
|
+
queueWithCustomV2Scenario,
|
|
164
|
+
queueWithCustomV3Scenario,
|
|
165
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {CommunicatorActionEnum, CommunicatorActionEnum_scenario} from '../../src/enums/CommunicatorActionEnum';
|
|
2
|
+
|
|
3
|
+
const defaultScenario = CommunicatorActionEnum_scenario();
|
|
4
|
+
|
|
5
|
+
const scenarioCustom = [
|
|
6
|
+
CommunicatorActionEnum.CLOSE,
|
|
7
|
+
CommunicatorActionEnum.TOKEN,
|
|
8
|
+
CommunicatorActionEnum.GOTO,
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const scenarioCustomV2 = [
|
|
12
|
+
CommunicatorActionEnum.CLOSE,
|
|
13
|
+
CommunicatorActionEnum.TOKEN,
|
|
14
|
+
CommunicatorActionEnum.OPEN,
|
|
15
|
+
CommunicatorActionEnum.GOTO,
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const scenarioCustomV3 = [
|
|
19
|
+
CommunicatorActionEnum.OPEN,
|
|
20
|
+
CommunicatorActionEnum.CLOSE,
|
|
21
|
+
CommunicatorActionEnum.TOKEN,
|
|
22
|
+
CommunicatorActionEnum.OPEN,
|
|
23
|
+
CommunicatorActionEnum.GOTO,
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
defaultScenario,
|
|
28
|
+
scenarioCustom,
|
|
29
|
+
scenarioCustomV2,
|
|
30
|
+
scenarioCustomV3
|
|
31
|
+
};
|
package/test/utiles.spec.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import {isValidMessage, modifyOrigin, sortMessageQueue} from '../src/engine/utils';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
queueWithCustomScenario,
|
|
4
|
+
queueWithCustomV2Scenario, queueWithCustomV3Scenario,
|
|
5
|
+
queueWithDefaultScenario,
|
|
6
|
+
queueWithoutSorting
|
|
7
|
+
} from './testUnits/queue';
|
|
4
8
|
import {messageWithInvalidAction, messageWithInvalidTarget, normalMessage} from './testUnits/message';
|
|
9
|
+
import {scenarioCustom, defaultScenario, scenarioCustomV2, scenarioCustomV3} from './testUnits/scenario';
|
|
5
10
|
|
|
6
11
|
test('modifyOrigin', () => {
|
|
7
12
|
expect(modifyOrigin('google.com')).toBe('https://google.com');
|
|
8
13
|
expect(modifyOrigin('google.com/test')).toBe('https://google.com');
|
|
9
14
|
expect(modifyOrigin('https://google.com/')).toBe('https://google.com');
|
|
15
|
+
expect(modifyOrigin(' https://google.com/')).toBe('https://google.com');
|
|
16
|
+
expect(modifyOrigin('htts://google.com')).toBe(null);
|
|
10
17
|
});
|
|
11
18
|
|
|
12
19
|
describe('isValidMessage', () => {
|
|
@@ -35,10 +42,28 @@ describe('isValidMessage', () => {
|
|
|
35
42
|
});
|
|
36
43
|
|
|
37
44
|
describe('sortMessageQueue', () => {
|
|
38
|
-
it('Default Sorting', () => {
|
|
45
|
+
it('Default Sorting (Default scenario)', () => {
|
|
39
46
|
expect(
|
|
40
|
-
JSON.stringify(sortMessageQueue(
|
|
41
|
-
).toBe(JSON.stringify(
|
|
47
|
+
JSON.stringify(sortMessageQueue(queueWithoutSorting, defaultScenario))
|
|
48
|
+
).toBe(JSON.stringify(queueWithDefaultScenario));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('Custom Sorting (Not full scenario)', () => {
|
|
52
|
+
expect(
|
|
53
|
+
JSON.stringify(sortMessageQueue(queueWithoutSorting, scenarioCustom))
|
|
54
|
+
).toBe(JSON.stringify(queueWithCustomScenario));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('Custom Sorting (Full scenario)', () => {
|
|
58
|
+
expect(
|
|
59
|
+
JSON.stringify(sortMessageQueue(queueWithoutSorting, scenarioCustomV2))
|
|
60
|
+
).toBe(JSON.stringify(queueWithCustomV2Scenario));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('Custom Sorting (Full scenario with Doubling)', () => {
|
|
64
|
+
expect(
|
|
65
|
+
JSON.stringify(sortMessageQueue(queueWithoutSorting, scenarioCustomV3))
|
|
66
|
+
).toBe(JSON.stringify(queueWithCustomV3Scenario));
|
|
42
67
|
});
|
|
43
68
|
});
|
|
44
69
|
|