Skip to content

Commit 6c418c3

Browse files
committed
test: implement click handling and tracking for embedded messages
1 parent 40f496f commit 6c418c3

File tree

1 file changed

+227
-0
lines changed

1 file changed

+227
-0
lines changed
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
import { getActionPrefix } from './getActionPrefix';
2+
import { IterableCustomActionPrefix } from '../enums/IterableCustomActionPrefix';
3+
4+
/**
5+
* Tests for getActionPrefix utility function.
6+
*/
7+
describe('getActionPrefix', () => {
8+
describe('when string starts with action:// prefix', () => {
9+
it('should return Action prefix for exact action:// string', () => {
10+
// GIVEN a string that is exactly the action prefix
11+
const str = 'action://';
12+
13+
// WHEN getting the action prefix
14+
const result = getActionPrefix(str);
15+
16+
// THEN it should return the Action prefix
17+
expect(result).toBe(IterableCustomActionPrefix.Action);
18+
});
19+
20+
it('should return Action prefix for action:// with additional path', () => {
21+
// GIVEN a string starting with action:// and additional path
22+
const str = 'action://some/path';
23+
24+
// WHEN getting the action prefix
25+
const result = getActionPrefix(str);
26+
27+
// THEN it should return the Action prefix
28+
expect(result).toBe(IterableCustomActionPrefix.Action);
29+
});
30+
31+
it('should return Action prefix for action:// with query params', () => {
32+
// GIVEN a string starting with action:// and query parameters
33+
const str = 'action://deeplink?param1=value1&param2=value2';
34+
35+
// WHEN getting the action prefix
36+
const result = getActionPrefix(str);
37+
38+
// THEN it should return the Action prefix
39+
expect(result).toBe(IterableCustomActionPrefix.Action);
40+
});
41+
});
42+
43+
describe('when string starts with itbl:// prefix', () => {
44+
it('should return Itbl prefix for exact itbl:// string', () => {
45+
// GIVEN a string that is exactly the deprecated itbl prefix
46+
const str = 'itbl://';
47+
48+
// WHEN getting the action prefix
49+
const result = getActionPrefix(str);
50+
51+
// THEN it should return the Itbl prefix
52+
expect(result).toBe(IterableCustomActionPrefix.Itbl);
53+
});
54+
55+
it('should return Itbl prefix for itbl:// with additional path', () => {
56+
// GIVEN a string starting with itbl:// and additional path
57+
const str = 'itbl://some/path';
58+
59+
// WHEN getting the action prefix
60+
const result = getActionPrefix(str);
61+
62+
// THEN it should return the Itbl prefix
63+
expect(result).toBe(IterableCustomActionPrefix.Itbl);
64+
});
65+
66+
it('should return Itbl prefix for itbl:// with query params', () => {
67+
// GIVEN a string starting with itbl:// and query parameters
68+
const str = 'itbl://deeplink?param1=value1&param2=value2';
69+
70+
// WHEN getting the action prefix
71+
const result = getActionPrefix(str);
72+
73+
// THEN it should return the Itbl prefix
74+
expect(result).toBe(IterableCustomActionPrefix.Itbl);
75+
});
76+
});
77+
78+
describe('when string does not have a recognized prefix', () => {
79+
it('should return null for regular URL', () => {
80+
// GIVEN a regular https URL
81+
const str = 'https://example.com';
82+
83+
// WHEN getting the action prefix
84+
const result = getActionPrefix(str);
85+
86+
// THEN it should return null
87+
expect(result).toBeNull();
88+
});
89+
90+
it('should return null for http URL', () => {
91+
// GIVEN a regular http URL
92+
const str = 'http://example.com';
93+
94+
// WHEN getting the action prefix
95+
const result = getActionPrefix(str);
96+
97+
// THEN it should return null
98+
expect(result).toBeNull();
99+
});
100+
101+
it('should return null for custom scheme URL', () => {
102+
// GIVEN a custom scheme URL that is not action:// or itbl://
103+
const str = 'myapp://deeplink';
104+
105+
// WHEN getting the action prefix
106+
const result = getActionPrefix(str);
107+
108+
// THEN it should return null
109+
expect(result).toBeNull();
110+
});
111+
112+
it('should return null for plain text', () => {
113+
// GIVEN a plain text string
114+
const str = 'just some text';
115+
116+
// WHEN getting the action prefix
117+
const result = getActionPrefix(str);
118+
119+
// THEN it should return null
120+
expect(result).toBeNull();
121+
});
122+
123+
it('should return null for empty string', () => {
124+
// GIVEN an empty string
125+
const str = '';
126+
127+
// WHEN getting the action prefix
128+
const result = getActionPrefix(str);
129+
130+
// THEN it should return null
131+
expect(result).toBeNull();
132+
});
133+
});
134+
135+
describe('when string is null or undefined', () => {
136+
it('should return null for undefined string', () => {
137+
// GIVEN an undefined string
138+
const str = undefined;
139+
140+
// WHEN getting the action prefix
141+
const result = getActionPrefix(str);
142+
143+
// THEN it should return null
144+
expect(result).toBeNull();
145+
});
146+
147+
it('should return null for null string', () => {
148+
// GIVEN a null string
149+
const str = null;
150+
151+
// WHEN getting the action prefix
152+
const result = getActionPrefix(str);
153+
154+
// THEN it should return null
155+
expect(result).toBeNull();
156+
});
157+
});
158+
159+
describe('edge cases and case sensitivity', () => {
160+
it('should be case sensitive and not match ACTION://', () => {
161+
// GIVEN a string with uppercase ACTION://
162+
const str = 'ACTION://deeplink';
163+
164+
// WHEN getting the action prefix
165+
const result = getActionPrefix(str);
166+
167+
// THEN it should return null (case sensitive)
168+
expect(result).toBeNull();
169+
});
170+
171+
it('should be case sensitive and not match ITBL://', () => {
172+
// GIVEN a string with uppercase ITBL://
173+
const str = 'ITBL://deeplink';
174+
175+
// WHEN getting the action prefix
176+
const result = getActionPrefix(str);
177+
178+
// THEN it should return null (case sensitive)
179+
expect(result).toBeNull();
180+
});
181+
182+
it('should not match action:// in the middle of string', () => {
183+
// GIVEN a string with action:// not at the start
184+
const str = 'prefix action://deeplink';
185+
186+
// WHEN getting the action prefix
187+
const result = getActionPrefix(str);
188+
189+
// THEN it should return null
190+
expect(result).toBeNull();
191+
});
192+
193+
it('should not match itbl:// in the middle of string', () => {
194+
// GIVEN a string with itbl:// not at the start
195+
const str = 'prefix itbl://deeplink';
196+
197+
// WHEN getting the action prefix
198+
const result = getActionPrefix(str);
199+
200+
// THEN it should return null
201+
expect(result).toBeNull();
202+
});
203+
204+
it('should not match partial prefix action:', () => {
205+
// GIVEN a string with incomplete action prefix
206+
const str = 'action:deeplink';
207+
208+
// WHEN getting the action prefix
209+
const result = getActionPrefix(str);
210+
211+
// THEN it should return null
212+
expect(result).toBeNull();
213+
});
214+
215+
it('should not match partial prefix itbl:', () => {
216+
// GIVEN a string with incomplete itbl prefix
217+
const str = 'itbl:deeplink';
218+
219+
// WHEN getting the action prefix
220+
const result = getActionPrefix(str);
221+
222+
// THEN it should return null
223+
expect(result).toBeNull();
224+
});
225+
});
226+
});
227+

0 commit comments

Comments
 (0)