mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {RichText} from '@atproto/api'
2
3import {parseEmbedPlayerFromUrl} from 'lib/strings/embed-player'
4import {
5 createStarterPackGooglePlayUri,
6 createStarterPackLinkFromAndroidReferrer,
7 parseStarterPackUri,
8} from 'lib/strings/starter-pack'
9import {cleanError} from '../../src/lib/strings/errors'
10import {createFullHandle, makeValidHandle} from '../../src/lib/strings/handles'
11import {enforceLen} from '../../src/lib/strings/helpers'
12import {detectLinkables} from '../../src/lib/strings/rich-text-detection'
13import {shortenLinks} from '../../src/lib/strings/rich-text-manip'
14import {
15 makeRecordUri,
16 toNiceDomain,
17 toShareUrl,
18 toShortUrl,
19} from '../../src/lib/strings/url-helpers'
20
21describe('detectLinkables', () => {
22 const inputs = [
23 'no linkable',
24 '@start middle end',
25 'start @middle end',
26 'start middle @end',
27 '@start @middle @end',
28 '@full123.test-of-chars',
29 'not@right',
30 '@bad!@#$chars',
31 '@newline1\n@newline2',
32 'parenthetical (@handle)',
33 'start https://middle.com end',
34 'start https://middle.com/foo/bar end',
35 'start https://middle.com/foo/bar?baz=bux end',
36 'start https://middle.com/foo/bar?baz=bux#hash end',
37 'https://start.com/foo/bar?baz=bux#hash middle end',
38 'start middle https://end.com/foo/bar?baz=bux#hash',
39 'https://newline1.com\nhttps://newline2.com',
40 'start middle.com end',
41 'start middle.com/foo/bar end',
42 'start middle.com/foo/bar?baz=bux end',
43 'start middle.com/foo/bar?baz=bux#hash end',
44 'start.com/foo/bar?baz=bux#hash middle end',
45 'start middle end.com/foo/bar?baz=bux#hash',
46 'newline1.com\nnewline2.com',
47 'not.. a..url ..here',
48 'e.g.',
49 'e.g. real.com fake.notreal',
50 'something-cool.jpg',
51 'website.com.jpg',
52 'e.g./foo',
53 'website.com.jpg/foo',
54 'Classic article https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/',
55 'Classic article https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/ ',
56 'https://foo.com https://bar.com/whatever https://baz.com',
57 'punctuation https://foo.com, https://bar.com/whatever; https://baz.com.',
58 'parenthetical (https://foo.com)',
59 'except for https://foo.com/thing_(cool)',
60 ]
61 const outputs = [
62 ['no linkable'],
63 [{link: '@start'}, ' middle end'],
64 ['start ', {link: '@middle'}, ' end'],
65 ['start middle ', {link: '@end'}],
66 [{link: '@start'}, ' ', {link: '@middle'}, ' ', {link: '@end'}],
67 [{link: '@full123.test-of-chars'}],
68 ['not@right'],
69 [{link: '@bad'}, '!@#$chars'],
70 [{link: '@newline1'}, '\n', {link: '@newline2'}],
71 ['parenthetical (', {link: '@handle'}, ')'],
72 ['start ', {link: 'https://middle.com'}, ' end'],
73 ['start ', {link: 'https://middle.com/foo/bar'}, ' end'],
74 ['start ', {link: 'https://middle.com/foo/bar?baz=bux'}, ' end'],
75 ['start ', {link: 'https://middle.com/foo/bar?baz=bux#hash'}, ' end'],
76 [{link: 'https://start.com/foo/bar?baz=bux#hash'}, ' middle end'],
77 ['start middle ', {link: 'https://end.com/foo/bar?baz=bux#hash'}],
78 [{link: 'https://newline1.com'}, '\n', {link: 'https://newline2.com'}],
79 ['start ', {link: 'middle.com'}, ' end'],
80 ['start ', {link: 'middle.com/foo/bar'}, ' end'],
81 ['start ', {link: 'middle.com/foo/bar?baz=bux'}, ' end'],
82 ['start ', {link: 'middle.com/foo/bar?baz=bux#hash'}, ' end'],
83 [{link: 'start.com/foo/bar?baz=bux#hash'}, ' middle end'],
84 ['start middle ', {link: 'end.com/foo/bar?baz=bux#hash'}],
85 [{link: 'newline1.com'}, '\n', {link: 'newline2.com'}],
86 ['not.. a..url ..here'],
87 ['e.g.'],
88 ['e.g. ', {link: 'real.com'}, ' fake.notreal'],
89 ['something-cool.jpg'],
90 ['website.com.jpg'],
91 ['e.g./foo'],
92 ['website.com.jpg/foo'],
93 [
94 'Classic article ',
95 {
96 link: 'https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/',
97 },
98 ],
99 [
100 'Classic article ',
101 {
102 link: 'https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/',
103 },
104 ' ',
105 ],
106 [
107 {link: 'https://foo.com'},
108 ' ',
109 {link: 'https://bar.com/whatever'},
110 ' ',
111 {link: 'https://baz.com'},
112 ],
113 [
114 'punctuation ',
115 {link: 'https://foo.com'},
116 ', ',
117 {link: 'https://bar.com/whatever'},
118 '; ',
119 {link: 'https://baz.com'},
120 '.',
121 ],
122 ['parenthetical (', {link: 'https://foo.com'}, ')'],
123 ['except for ', {link: 'https://foo.com/thing_(cool)'}],
124 ]
125 it('correctly handles a set of text inputs', () => {
126 for (let i = 0; i < inputs.length; i++) {
127 const input = inputs[i]
128 const output = detectLinkables(input)
129 expect(output).toEqual(outputs[i])
130 }
131 })
132})
133
134describe('makeRecordUri', () => {
135 const inputs: [string, string, string][] = [
136 ['alice.test', 'app.bsky.feed.post', '3jk7x4irgv52r'],
137 ]
138 const outputs = ['at://alice.test/app.bsky.feed.post/3jk7x4irgv52r']
139
140 it('correctly builds a record URI', () => {
141 for (let i = 0; i < inputs.length; i++) {
142 const input = inputs[i]
143 const result = makeRecordUri(...input)
144 expect(result).toEqual(outputs[i])
145 }
146 })
147})
148
149describe('makeValidHandle', () => {
150 const inputs = [
151 'test-handle-123',
152 'test!"#$%&/()=?_',
153 'this-handle-should-be-too-big',
154 ]
155 const outputs = ['test-handle-123', 'test', 'this-handle-should-b']
156
157 it('correctly parses and corrects handles', () => {
158 for (let i = 0; i < inputs.length; i++) {
159 const result = makeValidHandle(inputs[i])
160 expect(result).toEqual(outputs[i])
161 }
162 })
163})
164
165describe('createFullHandle', () => {
166 const inputs: [string, string][] = [
167 ['test-handle-123', 'test'],
168 ['.test.handle', 'test.test.'],
169 ['test.handle.', '.test.test'],
170 ]
171 const outputs = [
172 'test-handle-123.test',
173 '.test.handle.test.test.',
174 'test.handle.test.test',
175 ]
176
177 it('correctly parses and corrects handles', () => {
178 for (let i = 0; i < inputs.length; i++) {
179 const input = inputs[i]
180 const result = createFullHandle(...input)
181 expect(result).toEqual(outputs[i])
182 }
183 })
184})
185
186describe('enforceLen', () => {
187 const inputs: [string, number][] = [
188 ['Hello World!', 5],
189 ['Hello World!', 20],
190 ['', 5],
191 ]
192 const outputs = ['Hello', 'Hello World!', '']
193
194 it('correctly enforces defined length on a given string', () => {
195 for (let i = 0; i < inputs.length; i++) {
196 const input = inputs[i]
197 const result = enforceLen(...input)
198 expect(result).toEqual(outputs[i])
199 }
200 })
201})
202
203describe('cleanError', () => {
204 const inputs = [
205 'TypeError: Network request failed',
206 'Error: Aborted',
207 'Error: TypeError "x" is not a function',
208 'Error: SyntaxError unexpected token "export"',
209 'Some other error',
210 ]
211 const outputs = [
212 'Unable to connect. Please check your internet connection and try again.',
213 'Unable to connect. Please check your internet connection and try again.',
214 'TypeError "x" is not a function',
215 'SyntaxError unexpected token "export"',
216 'Some other error',
217 ]
218
219 it('removes extra content from error message', () => {
220 for (let i = 0; i < inputs.length; i++) {
221 const result = cleanError(inputs[i])
222 expect(result).toEqual(outputs[i])
223 }
224 })
225})
226
227describe('toNiceDomain', () => {
228 const inputs = [
229 'https://example.com/index.html',
230 'https://bsky.app',
231 'https://bsky.social',
232 '#123123123',
233 ]
234 const outputs = ['example.com', 'bsky.app', 'Bluesky Social', '#123123123']
235
236 it("displays the url's host in a easily readable manner", () => {
237 for (let i = 0; i < inputs.length; i++) {
238 const result = toNiceDomain(inputs[i])
239 expect(result).toEqual(outputs[i])
240 }
241 })
242})
243
244describe('toShortUrl', () => {
245 const inputs = [
246 'https://bsky.app',
247 'https://bsky.app/3jk7x4irgv52r',
248 'https://bsky.app/3jk7x4irgv52r2313y182h9',
249 'https://very-long-domain-name.com/foo',
250 'https://very-long-domain-name.com/foo?bar=baz#andsomemore',
251 ]
252 const outputs = [
253 'bsky.app',
254 'bsky.app/3jk7x4irgv52r',
255 'bsky.app/3jk7x4irgv52...',
256 'very-long-domain-name.com/foo',
257 'very-long-domain-name.com/foo?bar=baz#...',
258 ]
259
260 it('shortens the url', () => {
261 for (let i = 0; i < inputs.length; i++) {
262 const result = toShortUrl(inputs[i])
263 expect(result).toEqual(outputs[i])
264 }
265 })
266})
267
268describe('toShareUrl', () => {
269 const inputs = ['https://bsky.app', '/3jk7x4irgv52r', 'item/test/123']
270 const outputs = [
271 'https://bsky.app',
272 'https://bsky.app/3jk7x4irgv52r',
273 'https://bsky.app/item/test/123',
274 ]
275
276 it('appends https, when not present', () => {
277 for (let i = 0; i < inputs.length; i++) {
278 const result = toShareUrl(inputs[i])
279 expect(result).toEqual(outputs[i])
280 }
281 })
282})
283
284describe('shortenLinks', () => {
285 const inputs = [
286 'start https://middle.com/foo/bar?baz=bux#hash end',
287 'https://start.com/foo/bar?baz=bux#hash middle end',
288 'start middle https://end.com/foo/bar?baz=bux#hash',
289 'https://newline1.com/very/long/url/here\nhttps://newline2.com/very/long/url/here',
290 'Classic article https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/',
291 ]
292 const outputs = [
293 [
294 'start middle.com/foo/bar?baz=... end',
295 ['https://middle.com/foo/bar?baz=bux#hash'],
296 ],
297 [
298 'start.com/foo/bar?baz=... middle end',
299 ['https://start.com/foo/bar?baz=bux#hash'],
300 ],
301 [
302 'start middle end.com/foo/bar?baz=...',
303 ['https://end.com/foo/bar?baz=bux#hash'],
304 ],
305 [
306 'newline1.com/very/long/ur...\nnewline2.com/very/long/ur...',
307 [
308 'https://newline1.com/very/long/url/here',
309 'https://newline2.com/very/long/url/here',
310 ],
311 ],
312 [
313 'Classic article socket3.wordpress.com/2018/02/03/d...',
314 [
315 'https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/',
316 ],
317 ],
318 ]
319
320 it('correctly shortens rich text while preserving facet URIs', () => {
321 for (let i = 0; i < inputs.length; i++) {
322 const input = inputs[i]
323 const inputRT = new RichText({text: input})
324 inputRT.detectFacetsWithoutResolution()
325 const outputRT = shortenLinks(inputRT)
326 expect(outputRT.text).toEqual(outputs[i][0])
327 expect(outputRT.facets?.length).toEqual(outputs[i][1].length)
328 for (let j = 0; j < outputs[i][1].length; j++) {
329 expect(outputRT.facets![j].features[0].uri).toEqual(outputs[i][1][j])
330 }
331 }
332 })
333})
334
335describe('parseEmbedPlayerFromUrl', () => {
336 const inputs = [
337 'https://youtu.be/videoId',
338 'https://www.youtube.com/watch?v=videoId',
339 'https://www.youtube.com/watch?v=videoId&feature=share',
340 'https://youtube.com/watch?v=videoId',
341 'https://youtube.com/watch?v=videoId&feature=share',
342 'https://youtube.com/shorts/videoId',
343 'https://m.youtube.com/watch?v=videoId',
344 'https://music.youtube.com/watch?v=videoId',
345
346 'https://youtube.com/shorts/',
347 'https://youtube.com/',
348 'https://youtube.com/random',
349
350 'https://twitch.tv/channelName',
351 'https://www.twitch.tv/channelName',
352 'https://m.twitch.tv/channelName',
353
354 'https://twitch.tv/channelName/clip/clipId',
355 'https://twitch.tv/videos/videoId',
356
357 'https://open.spotify.com/playlist/playlistId',
358 'https://open.spotify.com/playlist/playlistId?param=value',
359 'https://open.spotify.com/locale/playlist/playlistId',
360
361 'https://open.spotify.com/track/songId',
362 'https://open.spotify.com/track/songId?param=value',
363 'https://open.spotify.com/locale/track/songId',
364
365 'https://open.spotify.com/album/albumId',
366 'https://open.spotify.com/album/albumId?param=value',
367 'https://open.spotify.com/locale/album/albumId',
368
369 'https://soundcloud.com/user/track',
370 'https://soundcloud.com/user/sets/set',
371 'https://soundcloud.com/user/',
372
373 'https://music.apple.com/us/playlist/playlistName/playlistId',
374 'https://music.apple.com/us/album/albumName/albumId',
375 'https://music.apple.com/us/album/albumName/albumId?i=songId',
376
377 'https://vimeo.com/videoId',
378 'https://vimeo.com/videoId?autoplay=0',
379
380 'https://giphy.com/gifs/some-random-gif-name-gifId',
381 'https://giphy.com/gif/some-random-gif-name-gifId',
382 'https://giphy.com/gifs/',
383
384 'https://giphy.com/gifs/39248209509382934029?hh=100&ww=100',
385
386 'https://media.giphy.com/media/gifId/giphy.webp',
387 'https://media0.giphy.com/media/gifId/giphy.webp',
388 'https://media1.giphy.com/media/gifId/giphy.gif',
389 'https://media2.giphy.com/media/gifId/giphy.webp',
390 'https://media3.giphy.com/media/gifId/giphy.mp4',
391 'https://media4.giphy.com/media/gifId/giphy.webp',
392 'https://media5.giphy.com/media/gifId/giphy.mp4',
393 'https://media0.giphy.com/media/gifId/giphy.mp3',
394 'https://media1.google.com/media/gifId/giphy.webp',
395
396 'https://media.giphy.com/media/trackingId/gifId/giphy.webp',
397
398 'https://i.giphy.com/media/gifId/giphy.webp',
399 'https://i.giphy.com/media/gifId/giphy.webp',
400 'https://i.giphy.com/gifId.gif',
401 'https://i.giphy.com/gifId.gif',
402
403 'https://tenor.com/view/gifId',
404 'https://tenor.com/notView/gifId',
405 'https://tenor.com/view',
406 'https://tenor.com/view/gifId.gif',
407 'https://tenor.com/intl/view/gifId.gif',
408
409 'https://media.tenor.com/someID_AAAAC/someName.gif?hh=100&ww=100',
410 'https://media.tenor.com/someID_AAAAC/someName.gif',
411 'https://media.tenor.com/someID/someName.gif',
412 'https://media.tenor.com/someID',
413 'https://media.tenor.com',
414
415 'https://www.flickr.com/photos/username/albums/72177720308493661',
416 'https://flickr.com/photos/username/albums/72177720308493661',
417 'https://flickr.com/photos/username/albums/72177720308493661/',
418 'https://flickr.com/photos/username/albums/72177720308493661//',
419 'https://flic.kr/s/aHBqjAES3i',
420
421 'https://flickr.com/foetoes/username/albums/3903',
422 'https://flickr.com/albums/3903',
423 'https://flic.kr/s/OolI',
424 'https://flic.kr/t/aHBqjAES3i',
425
426 'https://www.flickr.com/groups/898944@N23/pool',
427 'https://flickr.com/groups/898944@N23/pool',
428 'https://flickr.com/groups/898944@N23/pool/',
429 'https://flickr.com/groups/898944@N23/pool//',
430 'https://flic.kr/go/8WJtR',
431
432 'https://www.flickr.com/groups/898944@N23/',
433 'https://www.flickr.com/groups',
434 ]
435
436 const outputs = [
437 {
438 type: 'youtube_video',
439 source: 'youtube',
440 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0',
441 },
442 {
443 type: 'youtube_video',
444 source: 'youtube',
445 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0',
446 },
447 {
448 type: 'youtube_video',
449 source: 'youtube',
450 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0',
451 },
452 {
453 type: 'youtube_video',
454 source: 'youtube',
455 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0',
456 },
457 {
458 type: 'youtube_video',
459 source: 'youtube',
460 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0',
461 },
462 {
463 type: 'youtube_short',
464 source: 'youtubeShorts',
465 hideDetails: true,
466 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0',
467 },
468 {
469 type: 'youtube_video',
470 source: 'youtube',
471 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0',
472 },
473 {
474 type: 'youtube_video',
475 source: 'youtube',
476 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0',
477 },
478
479 undefined,
480 undefined,
481 undefined,
482
483 {
484 type: 'twitch_video',
485 source: 'twitch',
486 playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&channel=channelName&parent=localhost`,
487 },
488 {
489 type: 'twitch_video',
490 source: 'twitch',
491 playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&channel=channelName&parent=localhost`,
492 },
493 {
494 type: 'twitch_video',
495 source: 'twitch',
496 playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&channel=channelName&parent=localhost`,
497 },
498 {
499 type: 'twitch_video',
500 source: 'twitch',
501 playerUri: `https://clips.twitch.tv/embed?volume=0.5&autoplay=true&clip=clipId&parent=localhost`,
502 },
503 {
504 type: 'twitch_video',
505 source: 'twitch',
506 playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&video=videoId&parent=localhost`,
507 },
508
509 {
510 type: 'spotify_playlist',
511 source: 'spotify',
512 playerUri: `https://open.spotify.com/embed/playlist/playlistId`,
513 },
514 {
515 type: 'spotify_playlist',
516 source: 'spotify',
517 playerUri: `https://open.spotify.com/embed/playlist/playlistId`,
518 },
519 {
520 type: 'spotify_playlist',
521 source: 'spotify',
522 playerUri: `https://open.spotify.com/embed/playlist/playlistId`,
523 },
524
525 {
526 type: 'spotify_song',
527 source: 'spotify',
528 playerUri: `https://open.spotify.com/embed/track/songId`,
529 },
530 {
531 type: 'spotify_song',
532 source: 'spotify',
533 playerUri: `https://open.spotify.com/embed/track/songId`,
534 },
535 {
536 type: 'spotify_song',
537 source: 'spotify',
538 playerUri: `https://open.spotify.com/embed/track/songId`,
539 },
540
541 {
542 type: 'spotify_album',
543 source: 'spotify',
544 playerUri: `https://open.spotify.com/embed/album/albumId`,
545 },
546 {
547 type: 'spotify_album',
548 source: 'spotify',
549 playerUri: `https://open.spotify.com/embed/album/albumId`,
550 },
551 {
552 type: 'spotify_album',
553 source: 'spotify',
554 playerUri: `https://open.spotify.com/embed/album/albumId`,
555 },
556
557 {
558 type: 'soundcloud_track',
559 source: 'soundcloud',
560 playerUri: `https://w.soundcloud.com/player/?url=https://soundcloud.com/user/track&auto_play=true&visual=false&hide_related=true`,
561 },
562 {
563 type: 'soundcloud_set',
564 source: 'soundcloud',
565 playerUri: `https://w.soundcloud.com/player/?url=https://soundcloud.com/user/sets/set&auto_play=true&visual=false&hide_related=true`,
566 },
567 undefined,
568
569 {
570 type: 'apple_music_playlist',
571 source: 'appleMusic',
572 playerUri:
573 'https://embed.music.apple.com/us/playlist/playlistName/playlistId',
574 },
575 {
576 type: 'apple_music_album',
577 source: 'appleMusic',
578 playerUri: 'https://embed.music.apple.com/us/album/albumName/albumId',
579 },
580 {
581 type: 'apple_music_song',
582 source: 'appleMusic',
583 playerUri:
584 'https://embed.music.apple.com/us/album/albumName/albumId?i=songId',
585 },
586
587 {
588 type: 'vimeo_video',
589 source: 'vimeo',
590 playerUri: 'https://player.vimeo.com/video/videoId?autoplay=1',
591 },
592 {
593 type: 'vimeo_video',
594 source: 'vimeo',
595 playerUri: 'https://player.vimeo.com/video/videoId?autoplay=1',
596 },
597
598 {
599 type: 'giphy_gif',
600 source: 'giphy',
601 isGif: true,
602 hideDetails: true,
603 metaUri: 'https://giphy.com/gifs/gifId',
604 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
605 },
606 undefined,
607 undefined,
608 {
609 type: 'giphy_gif',
610 source: 'giphy',
611 isGif: true,
612 hideDetails: true,
613 metaUri: 'https://giphy.com/gifs/39248209509382934029',
614 playerUri: 'https://i.giphy.com/media/39248209509382934029/200.webp',
615 },
616 {
617 type: 'giphy_gif',
618 source: 'giphy',
619 isGif: true,
620 hideDetails: true,
621 metaUri: 'https://giphy.com/gifs/gifId',
622 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
623 },
624 {
625 type: 'giphy_gif',
626 source: 'giphy',
627 isGif: true,
628 hideDetails: true,
629 metaUri: 'https://giphy.com/gifs/gifId',
630 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
631 },
632 {
633 type: 'giphy_gif',
634 source: 'giphy',
635 isGif: true,
636 hideDetails: true,
637 metaUri: 'https://giphy.com/gifs/gifId',
638 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
639 },
640 {
641 type: 'giphy_gif',
642 source: 'giphy',
643 isGif: true,
644 hideDetails: true,
645 metaUri: 'https://giphy.com/gifs/gifId',
646 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
647 },
648 {
649 type: 'giphy_gif',
650 source: 'giphy',
651 isGif: true,
652 hideDetails: true,
653 metaUri: 'https://giphy.com/gifs/gifId',
654 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
655 },
656 {
657 type: 'giphy_gif',
658 source: 'giphy',
659 isGif: true,
660 hideDetails: true,
661 metaUri: 'https://giphy.com/gifs/gifId',
662 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
663 },
664 undefined,
665 undefined,
666 undefined,
667
668 {
669 type: 'giphy_gif',
670 source: 'giphy',
671 isGif: true,
672 hideDetails: true,
673 metaUri: 'https://giphy.com/gifs/gifId',
674 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
675 },
676
677 {
678 type: 'giphy_gif',
679 source: 'giphy',
680 isGif: true,
681 hideDetails: true,
682 metaUri: 'https://giphy.com/gifs/gifId',
683 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
684 },
685 {
686 type: 'giphy_gif',
687 source: 'giphy',
688 isGif: true,
689 hideDetails: true,
690 metaUri: 'https://giphy.com/gifs/gifId',
691 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
692 },
693 {
694 type: 'giphy_gif',
695 source: 'giphy',
696 isGif: true,
697 hideDetails: true,
698 metaUri: 'https://giphy.com/gifs/gifId',
699 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
700 },
701 {
702 type: 'giphy_gif',
703 source: 'giphy',
704 isGif: true,
705 hideDetails: true,
706 metaUri: 'https://giphy.com/gifs/gifId',
707 playerUri: 'https://i.giphy.com/media/gifId/200.webp',
708 },
709
710 undefined,
711 undefined,
712 undefined,
713 undefined,
714 undefined,
715
716 {
717 type: 'tenor_gif',
718 source: 'tenor',
719 isGif: true,
720 hideDetails: true,
721 playerUri: 'https://t.gifs.bsky.app/someID_AAAAM/someName.gif',
722 dimensions: {
723 width: 100,
724 height: 100,
725 },
726 },
727 undefined,
728 undefined,
729 undefined,
730 undefined,
731
732 {
733 type: 'flickr_album',
734 source: 'flickr',
735 playerUri: 'https://embedr.flickr.com/photosets/72177720308493661',
736 },
737 {
738 type: 'flickr_album',
739 source: 'flickr',
740 playerUri: 'https://embedr.flickr.com/photosets/72177720308493661',
741 },
742 {
743 type: 'flickr_album',
744 source: 'flickr',
745 playerUri: 'https://embedr.flickr.com/photosets/72177720308493661',
746 },
747 {
748 type: 'flickr_album',
749 source: 'flickr',
750 playerUri: 'https://embedr.flickr.com/photosets/72177720308493661',
751 },
752 {
753 type: 'flickr_album',
754 source: 'flickr',
755 playerUri: 'https://embedr.flickr.com/photosets/72177720308493661',
756 },
757
758 undefined,
759 undefined,
760 undefined,
761 undefined,
762
763 {
764 type: 'flickr_album',
765 source: 'flickr',
766 playerUri: 'https://embedr.flickr.com/groups/898944@N23',
767 },
768 {
769 type: 'flickr_album',
770 source: 'flickr',
771 playerUri: 'https://embedr.flickr.com/groups/898944@N23',
772 },
773 {
774 type: 'flickr_album',
775 source: 'flickr',
776 playerUri: 'https://embedr.flickr.com/groups/898944@N23',
777 },
778 {
779 type: 'flickr_album',
780 source: 'flickr',
781 playerUri: 'https://embedr.flickr.com/groups/898944@N23',
782 },
783 {
784 type: 'flickr_album',
785 source: 'flickr',
786 playerUri: 'https://embedr.flickr.com/groups/898944@N23',
787 },
788
789 undefined,
790 undefined,
791 ]
792
793 it('correctly grabs the correct id from uri', () => {
794 for (let i = 0; i < inputs.length; i++) {
795 const input = inputs[i]
796 const output = outputs[i]
797
798 const res = parseEmbedPlayerFromUrl(input)
799
800 expect(res).toEqual(output)
801 }
802 })
803})
804
805describe('createStarterPackLinkFromAndroidReferrer', () => {
806 const validOutput = 'at://haileyok.com/app.bsky.graph.starterpack/rkey'
807
808 it('returns a link when input contains utm_source and utm_content', () => {
809 expect(
810 createStarterPackLinkFromAndroidReferrer(
811 'utm_source=bluesky&utm_content=starterpack_haileyok.com_rkey',
812 ),
813 ).toEqual(validOutput)
814
815 expect(
816 createStarterPackLinkFromAndroidReferrer(
817 'utm_source=bluesky&utm_content=starterpack_test-lover-9000.com_rkey',
818 ),
819 ).toEqual('at://test-lover-9000.com/app.bsky.graph.starterpack/rkey')
820 })
821
822 it('returns a link when input contains utm_source and utm_content in different order', () => {
823 expect(
824 createStarterPackLinkFromAndroidReferrer(
825 'utm_content=starterpack_haileyok.com_rkey&utm_source=bluesky',
826 ),
827 ).toEqual(validOutput)
828 })
829
830 it('returns a link when input contains other parameters as well', () => {
831 expect(
832 createStarterPackLinkFromAndroidReferrer(
833 'utm_source=bluesky&utm_medium=starterpack&utm_content=starterpack_haileyok.com_rkey',
834 ),
835 ).toEqual(validOutput)
836 })
837
838 it('returns null when utm_source is not present', () => {
839 expect(
840 createStarterPackLinkFromAndroidReferrer(
841 'utm_content=starterpack_haileyok.com_rkey',
842 ),
843 ).toEqual(null)
844 })
845
846 it('returns null when utm_content is not present', () => {
847 expect(
848 createStarterPackLinkFromAndroidReferrer('utm_source=bluesky'),
849 ).toEqual(null)
850 })
851
852 it('returns null when utm_content is malformed', () => {
853 expect(
854 createStarterPackLinkFromAndroidReferrer(
855 'utm_content=starterpack_haileyok.com',
856 ),
857 ).toEqual(null)
858
859 expect(
860 createStarterPackLinkFromAndroidReferrer('utm_content=starterpack'),
861 ).toEqual(null)
862
863 expect(
864 createStarterPackLinkFromAndroidReferrer(
865 'utm_content=starterpack_haileyok.com_rkey_more',
866 ),
867 ).toEqual(null)
868
869 expect(
870 createStarterPackLinkFromAndroidReferrer(
871 'utm_content=notastarterpack_haileyok.com_rkey',
872 ),
873 ).toEqual(null)
874 })
875})
876
877describe('parseStarterPackHttpUri', () => {
878 const baseUri = 'https://bsky.app/start'
879
880 it('returns a valid at uri when http uri is valid', () => {
881 const validHttpUri = `${baseUri}/haileyok.com/rkey`
882 expect(parseStarterPackUri(validHttpUri)).toEqual({
883 name: 'haileyok.com',
884 rkey: 'rkey',
885 })
886
887 const validHttpUri2 = `${baseUri}/haileyok.com/ilovetesting`
888 expect(parseStarterPackUri(validHttpUri2)).toEqual({
889 name: 'haileyok.com',
890 rkey: 'ilovetesting',
891 })
892
893 const validHttpUri3 = `${baseUri}/testlover9000.com/rkey`
894 expect(parseStarterPackUri(validHttpUri3)).toEqual({
895 name: 'testlover9000.com',
896 rkey: 'rkey',
897 })
898 })
899
900 it('returns null when there is no rkey', () => {
901 const validHttpUri = `${baseUri}/haileyok.com`
902 expect(parseStarterPackUri(validHttpUri)).toEqual(null)
903 })
904
905 it('returns null when there is an extra path', () => {
906 const validHttpUri = `${baseUri}/haileyok.com/rkey/other`
907 expect(parseStarterPackUri(validHttpUri)).toEqual(null)
908 })
909
910 it('returns null when there is no handle or rkey', () => {
911 const validHttpUri = `${baseUri}`
912 expect(parseStarterPackUri(validHttpUri)).toEqual(null)
913 })
914
915 it('returns null when the route is not /start or /starter-pack', () => {
916 const validHttpUri = 'https://bsky.app/start/haileyok.com/rkey'
917 expect(parseStarterPackUri(validHttpUri)).toEqual({
918 name: 'haileyok.com',
919 rkey: 'rkey',
920 })
921
922 const validHttpUri2 = 'https://bsky.app/starter-pack/haileyok.com/rkey'
923 expect(parseStarterPackUri(validHttpUri2)).toEqual({
924 name: 'haileyok.com',
925 rkey: 'rkey',
926 })
927
928 const invalidHttpUri = 'https://bsky.app/profile/haileyok.com/rkey'
929 expect(parseStarterPackUri(invalidHttpUri)).toEqual(null)
930 })
931
932 it('returns the at uri when the input is a valid starterpack at uri', () => {
933 const validAtUri = 'at://did:123/app.bsky.graph.starterpack/rkey'
934 expect(parseStarterPackUri(validAtUri)).toEqual({
935 name: 'did:123',
936 rkey: 'rkey',
937 })
938 })
939
940 it('returns null when the at uri has no rkey', () => {
941 const validAtUri = 'at://did:123/app.bsky.graph.starterpack'
942 expect(parseStarterPackUri(validAtUri)).toEqual(null)
943 })
944
945 it('returns null when the collection is not app.bsky.graph.starterpack', () => {
946 const validAtUri = 'at://did:123/app.bsky.graph.list/rkey'
947 expect(parseStarterPackUri(validAtUri)).toEqual(null)
948 })
949
950 it('returns null when the input is undefined', () => {
951 expect(parseStarterPackUri(undefined)).toEqual(null)
952 })
953})
954
955describe('createStarterPackGooglePlayUri', () => {
956 const base =
957 'https://play.google.com/store/apps/details?id=xyz.blueskyweb.app&referrer=utm_source%3Dbluesky%26utm_medium%3Dstarterpack%26utm_content%3Dstarterpack_'
958
959 it('returns valid google play uri when input is valid', () => {
960 expect(createStarterPackGooglePlayUri('name', 'rkey')).toEqual(
961 `${base}name_rkey`,
962 )
963 })
964
965 it('returns null when no rkey is supplied', () => {
966 // @ts-expect-error test
967 expect(createStarterPackGooglePlayUri('name', undefined)).toEqual(null)
968 })
969
970 it('returns null when no name or rkey are supplied', () => {
971 // @ts-expect-error test
972 expect(createStarterPackGooglePlayUri(undefined, undefined)).toEqual(null)
973 })
974
975 it('returns null when rkey is supplied but no name', () => {
976 // @ts-expect-error test
977 expect(createStarterPackGooglePlayUri(undefined, 'rkey')).toEqual(null)
978 })
979})