mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {RichText} from '@atproto/api' 2import { 3 makeRecordUri, 4 toNiceDomain, 5 toShortUrl, 6 toShareUrl, 7} from '../../src/lib/strings/url-helpers' 8import {pluralize, enforceLen} from '../../src/lib/strings/helpers' 9import {ago} from '../../src/lib/strings/time' 10import {detectLinkables} from '../../src/lib/strings/rich-text-detection' 11import {shortenLinks} from '../../src/lib/strings/rich-text-manip' 12import {makeValidHandle, createFullHandle} from '../../src/lib/strings/handles' 13import {cleanError} from '../../src/lib/strings/errors' 14import {parseEmbedPlayerFromUrl} from 'lib/strings/embed-player' 15 16describe('detectLinkables', () => { 17 const inputs = [ 18 'no linkable', 19 '@start middle end', 20 'start @middle end', 21 'start middle @end', 22 '@start @middle @end', 23 '@full123.test-of-chars', 24 'not@right', 25 '@bad!@#$chars', 26 '@newline1\n@newline2', 27 'parenthetical (@handle)', 28 'start https://middle.com end', 29 'start https://middle.com/foo/bar end', 30 'start https://middle.com/foo/bar?baz=bux end', 31 'start https://middle.com/foo/bar?baz=bux#hash end', 32 'https://start.com/foo/bar?baz=bux#hash middle end', 33 'start middle https://end.com/foo/bar?baz=bux#hash', 34 'https://newline1.com\nhttps://newline2.com', 35 'start middle.com end', 36 'start middle.com/foo/bar end', 37 'start middle.com/foo/bar?baz=bux end', 38 'start middle.com/foo/bar?baz=bux#hash end', 39 'start.com/foo/bar?baz=bux#hash middle end', 40 'start middle end.com/foo/bar?baz=bux#hash', 41 'newline1.com\nnewline2.com', 42 'not.. a..url ..here', 43 'e.g.', 44 'e.g. real.com fake.notreal', 45 'something-cool.jpg', 46 'website.com.jpg', 47 'e.g./foo', 48 'website.com.jpg/foo', 49 'Classic article https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/', 50 'Classic article https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/ ', 51 'https://foo.com https://bar.com/whatever https://baz.com', 52 'punctuation https://foo.com, https://bar.com/whatever; https://baz.com.', 53 'parenthetical (https://foo.com)', 54 'except for https://foo.com/thing_(cool)', 55 ] 56 const outputs = [ 57 ['no linkable'], 58 [{link: '@start'}, ' middle end'], 59 ['start ', {link: '@middle'}, ' end'], 60 ['start middle ', {link: '@end'}], 61 [{link: '@start'}, ' ', {link: '@middle'}, ' ', {link: '@end'}], 62 [{link: '@full123.test-of-chars'}], 63 ['not@right'], 64 [{link: '@bad'}, '!@#$chars'], 65 [{link: '@newline1'}, '\n', {link: '@newline2'}], 66 ['parenthetical (', {link: '@handle'}, ')'], 67 ['start ', {link: 'https://middle.com'}, ' end'], 68 ['start ', {link: 'https://middle.com/foo/bar'}, ' end'], 69 ['start ', {link: 'https://middle.com/foo/bar?baz=bux'}, ' end'], 70 ['start ', {link: 'https://middle.com/foo/bar?baz=bux#hash'}, ' end'], 71 [{link: 'https://start.com/foo/bar?baz=bux#hash'}, ' middle end'], 72 ['start middle ', {link: 'https://end.com/foo/bar?baz=bux#hash'}], 73 [{link: 'https://newline1.com'}, '\n', {link: 'https://newline2.com'}], 74 ['start ', {link: 'middle.com'}, ' end'], 75 ['start ', {link: 'middle.com/foo/bar'}, ' end'], 76 ['start ', {link: 'middle.com/foo/bar?baz=bux'}, ' end'], 77 ['start ', {link: 'middle.com/foo/bar?baz=bux#hash'}, ' end'], 78 [{link: 'start.com/foo/bar?baz=bux#hash'}, ' middle end'], 79 ['start middle ', {link: 'end.com/foo/bar?baz=bux#hash'}], 80 [{link: 'newline1.com'}, '\n', {link: 'newline2.com'}], 81 ['not.. a..url ..here'], 82 ['e.g.'], 83 ['e.g. ', {link: 'real.com'}, ' fake.notreal'], 84 ['something-cool.jpg'], 85 ['website.com.jpg'], 86 ['e.g./foo'], 87 ['website.com.jpg/foo'], 88 [ 89 'Classic article ', 90 { 91 link: 'https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/', 92 }, 93 ], 94 [ 95 'Classic article ', 96 { 97 link: 'https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/', 98 }, 99 ' ', 100 ], 101 [ 102 {link: 'https://foo.com'}, 103 ' ', 104 {link: 'https://bar.com/whatever'}, 105 ' ', 106 {link: 'https://baz.com'}, 107 ], 108 [ 109 'punctuation ', 110 {link: 'https://foo.com'}, 111 ', ', 112 {link: 'https://bar.com/whatever'}, 113 '; ', 114 {link: 'https://baz.com'}, 115 '.', 116 ], 117 ['parenthetical (', {link: 'https://foo.com'}, ')'], 118 ['except for ', {link: 'https://foo.com/thing_(cool)'}], 119 ] 120 it('correctly handles a set of text inputs', () => { 121 for (let i = 0; i < inputs.length; i++) { 122 const input = inputs[i] 123 const output = detectLinkables(input) 124 expect(output).toEqual(outputs[i]) 125 } 126 }) 127}) 128 129describe('pluralize', () => { 130 const inputs: [number, string, string?][] = [ 131 [1, 'follower'], 132 [1, 'member'], 133 [100, 'post'], 134 [1000, 'repost'], 135 [10000, 'upvote'], 136 [100000, 'other'], 137 [2, 'man', 'men'], 138 ] 139 const outputs = [ 140 'follower', 141 'member', 142 'posts', 143 'reposts', 144 'upvotes', 145 'others', 146 'men', 147 ] 148 149 it('correctly pluralizes a set of words', () => { 150 for (let i = 0; i < inputs.length; i++) { 151 const input = inputs[i] 152 const output = pluralize(...input) 153 expect(output).toEqual(outputs[i]) 154 } 155 }) 156}) 157 158describe('makeRecordUri', () => { 159 const inputs: [string, string, string][] = [ 160 ['alice.test', 'app.bsky.feed.post', '3jk7x4irgv52r'], 161 ] 162 const outputs = ['at://alice.test/app.bsky.feed.post/3jk7x4irgv52r'] 163 164 it('correctly builds a record URI', () => { 165 for (let i = 0; i < inputs.length; i++) { 166 const input = inputs[i] 167 const result = makeRecordUri(...input) 168 expect(result).toEqual(outputs[i]) 169 } 170 }) 171}) 172 173describe('ago', () => { 174 const inputs = [ 175 1671461038, 176 '04 Dec 1995 00:12:00 GMT', 177 new Date(), 178 new Date().setSeconds(new Date().getSeconds() - 10), 179 new Date().setMinutes(new Date().getMinutes() - 10), 180 new Date().setHours(new Date().getHours() - 1), 181 new Date().setDate(new Date().getDate() - 1), 182 new Date().setMonth(new Date().getMonth() - 1), 183 ] 184 const outputs = [ 185 new Date(1671461038).toLocaleDateString(), 186 new Date('04 Dec 1995 00:12:00 GMT').toLocaleDateString(), 187 'now', 188 '10s', 189 '10m', 190 '1h', 191 '1d', 192 '1mo', 193 ] 194 195 it('correctly calculates how much time passed, in a string', () => { 196 for (let i = 0; i < inputs.length; i++) { 197 const result = ago(inputs[i]) 198 expect(result).toEqual(outputs[i]) 199 } 200 }) 201}) 202 203describe('makeValidHandle', () => { 204 const inputs = [ 205 'test-handle-123', 206 'test!"#$%&/()=?_', 207 'this-handle-should-be-too-big', 208 ] 209 const outputs = ['test-handle-123', 'test', 'this-handle-should-b'] 210 211 it('correctly parses and corrects handles', () => { 212 for (let i = 0; i < inputs.length; i++) { 213 const result = makeValidHandle(inputs[i]) 214 expect(result).toEqual(outputs[i]) 215 } 216 }) 217}) 218 219describe('createFullHandle', () => { 220 const inputs: [string, string][] = [ 221 ['test-handle-123', 'test'], 222 ['.test.handle', 'test.test.'], 223 ['test.handle.', '.test.test'], 224 ] 225 const outputs = [ 226 'test-handle-123.test', 227 '.test.handle.test.test.', 228 'test.handle.test.test', 229 ] 230 231 it('correctly parses and corrects handles', () => { 232 for (let i = 0; i < inputs.length; i++) { 233 const input = inputs[i] 234 const result = createFullHandle(...input) 235 expect(result).toEqual(outputs[i]) 236 } 237 }) 238}) 239 240describe('enforceLen', () => { 241 const inputs: [string, number][] = [ 242 ['Hello World!', 5], 243 ['Hello World!', 20], 244 ['', 5], 245 ] 246 const outputs = ['Hello', 'Hello World!', ''] 247 248 it('correctly enforces defined length on a given string', () => { 249 for (let i = 0; i < inputs.length; i++) { 250 const input = inputs[i] 251 const result = enforceLen(...input) 252 expect(result).toEqual(outputs[i]) 253 } 254 }) 255}) 256 257describe('cleanError', () => { 258 const inputs = [ 259 'TypeError: Network request failed', 260 'Error: Aborted', 261 'Error: TypeError "x" is not a function', 262 'Error: SyntaxError unexpected token "export"', 263 'Some other error', 264 ] 265 const outputs = [ 266 'Unable to connect. Please check your internet connection and try again.', 267 'Unable to connect. Please check your internet connection and try again.', 268 'TypeError "x" is not a function', 269 'SyntaxError unexpected token "export"', 270 'Some other error', 271 ] 272 273 it('removes extra content from error message', () => { 274 for (let i = 0; i < inputs.length; i++) { 275 const result = cleanError(inputs[i]) 276 expect(result).toEqual(outputs[i]) 277 } 278 }) 279}) 280 281describe('toNiceDomain', () => { 282 const inputs = [ 283 'https://example.com/index.html', 284 'https://bsky.app', 285 'https://bsky.social', 286 '#123123123', 287 ] 288 const outputs = ['example.com', 'bsky.app', 'Bluesky Social', '#123123123'] 289 290 it("displays the url's host in a easily readable manner", () => { 291 for (let i = 0; i < inputs.length; i++) { 292 const result = toNiceDomain(inputs[i]) 293 expect(result).toEqual(outputs[i]) 294 } 295 }) 296}) 297 298describe('toShortUrl', () => { 299 const inputs = [ 300 'https://bsky.app', 301 'https://bsky.app/3jk7x4irgv52r', 302 'https://bsky.app/3jk7x4irgv52r2313y182h9', 303 'https://very-long-domain-name.com/foo', 304 'https://very-long-domain-name.com/foo?bar=baz#andsomemore', 305 ] 306 const outputs = [ 307 'bsky.app', 308 'bsky.app/3jk7x4irgv52r', 309 'bsky.app/3jk7x4irgv52...', 310 'very-long-domain-name.com/foo', 311 'very-long-domain-name.com/foo?bar=baz#...', 312 ] 313 314 it('shortens the url', () => { 315 for (let i = 0; i < inputs.length; i++) { 316 const result = toShortUrl(inputs[i]) 317 expect(result).toEqual(outputs[i]) 318 } 319 }) 320}) 321 322describe('toShareUrl', () => { 323 const inputs = ['https://bsky.app', '/3jk7x4irgv52r', 'item/test/123'] 324 const outputs = [ 325 'https://bsky.app', 326 'https://bsky.app/3jk7x4irgv52r', 327 'https://bsky.app/item/test/123', 328 ] 329 330 it('appends https, when not present', () => { 331 for (let i = 0; i < inputs.length; i++) { 332 const result = toShareUrl(inputs[i]) 333 expect(result).toEqual(outputs[i]) 334 } 335 }) 336}) 337 338describe('shortenLinks', () => { 339 const inputs = [ 340 'start https://middle.com/foo/bar?baz=bux#hash end', 341 'https://start.com/foo/bar?baz=bux#hash middle end', 342 'start middle https://end.com/foo/bar?baz=bux#hash', 343 'https://newline1.com/very/long/url/here\nhttps://newline2.com/very/long/url/here', 344 'Classic article https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/', 345 ] 346 const outputs = [ 347 [ 348 'start middle.com/foo/bar?baz=... end', 349 ['https://middle.com/foo/bar?baz=bux#hash'], 350 ], 351 [ 352 'start.com/foo/bar?baz=... middle end', 353 ['https://start.com/foo/bar?baz=bux#hash'], 354 ], 355 [ 356 'start middle end.com/foo/bar?baz=...', 357 ['https://end.com/foo/bar?baz=bux#hash'], 358 ], 359 [ 360 'newline1.com/very/long/ur...\nnewline2.com/very/long/ur...', 361 [ 362 'https://newline1.com/very/long/url/here', 363 'https://newline2.com/very/long/url/here', 364 ], 365 ], 366 [ 367 'Classic article socket3.wordpress.com/2018/02/03/d...', 368 [ 369 'https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/', 370 ], 371 ], 372 ] 373 374 it('correctly shortens rich text while preserving facet URIs', () => { 375 for (let i = 0; i < inputs.length; i++) { 376 const input = inputs[i] 377 const inputRT = new RichText({text: input}) 378 inputRT.detectFacetsWithoutResolution() 379 const outputRT = shortenLinks(inputRT) 380 expect(outputRT.text).toEqual(outputs[i][0]) 381 expect(outputRT.facets?.length).toEqual(outputs[i][1].length) 382 for (let j = 0; j < outputs[i][1].length; j++) { 383 expect(outputRT.facets![j].features[0].uri).toEqual(outputs[i][1][j]) 384 } 385 } 386 }) 387}) 388 389describe('parseEmbedPlayerFromUrl', () => { 390 const inputs = [ 391 'https://youtu.be/videoId', 392 'https://www.youtube.com/watch?v=videoId', 393 'https://www.youtube.com/watch?v=videoId&feature=share', 394 'https://youtube.com/watch?v=videoId', 395 'https://youtube.com/watch?v=videoId&feature=share', 396 'https://youtube.com/shorts/videoId', 397 'https://m.youtube.com/watch?v=videoId', 398 399 'https://youtube.com/shorts/', 400 'https://youtube.com/', 401 'https://youtube.com/random', 402 403 'https://twitch.tv/channelName', 404 'https://www.twitch.tv/channelName', 405 'https://m.twitch.tv/channelName', 406 407 'https://twitch.tv/channelName/clip/clipId', 408 'https://twitch.tv/videos/videoId', 409 410 'https://open.spotify.com/playlist/playlistId', 411 'https://open.spotify.com/playlist/playlistId?param=value', 412 'https://open.spotify.com/locale/playlist/playlistId', 413 414 'https://open.spotify.com/track/songId', 415 'https://open.spotify.com/track/songId?param=value', 416 'https://open.spotify.com/locale/track/songId', 417 418 'https://open.spotify.com/album/albumId', 419 'https://open.spotify.com/album/albumId?param=value', 420 'https://open.spotify.com/locale/album/albumId', 421 422 'https://soundcloud.com/user/track', 423 'https://soundcloud.com/user/sets/set', 424 'https://soundcloud.com/user/', 425 426 'https://music.apple.com/us/playlist/playlistName/playlistId', 427 'https://music.apple.com/us/album/albumName/albumId', 428 'https://music.apple.com/us/album/albumName/albumId?i=songId', 429 430 'https://vimeo.com/videoId', 431 'https://vimeo.com/videoId?autoplay=0', 432 433 'https://giphy.com/gifs/some-random-gif-name-gifId', 434 'https://giphy.com/gif/some-random-gif-name-gifId', 435 'https://giphy.com/gifs/', 436 437 'https://media.giphy.com/media/gifId/giphy.webp', 438 'https://media0.giphy.com/media/gifId/giphy.webp', 439 'https://media1.giphy.com/media/gifId/giphy.gif', 440 'https://media2.giphy.com/media/gifId/giphy.webp', 441 'https://media3.giphy.com/media/gifId/giphy.mp4', 442 'https://media4.giphy.com/media/gifId/giphy.webp', 443 'https://media5.giphy.com/media/gifId/giphy.mp4', 444 'https://media0.giphy.com/media/gifId/giphy.mp3', 445 'https://media1.google.com/media/gifId/giphy.webp', 446 447 'https://media.giphy.com/media/trackingId/gifId/giphy.webp', 448 449 'https://i.giphy.com/media/gifId/giphy.webp', 450 'https://i.giphy.com/media/gifId/giphy.webp', 451 'https://i.giphy.com/gifId.gif', 452 'https://i.giphy.com/gifId.gif', 453 454 'https://tenor.com/view/gifId', 455 'https://tenor.com/notView/gifId', 456 'https://tenor.com/view', 457 'https://tenor.com/view/gifId.gif', 458 'https://tenor.com/intl/view/gifId.gif', 459 ] 460 461 const outputs = [ 462 { 463 type: 'youtube_video', 464 source: 'youtube', 465 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0', 466 }, 467 { 468 type: 'youtube_video', 469 source: 'youtube', 470 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0', 471 }, 472 { 473 type: 'youtube_video', 474 source: 'youtube', 475 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0', 476 }, 477 { 478 type: 'youtube_video', 479 source: 'youtube', 480 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0', 481 }, 482 { 483 type: 'youtube_video', 484 source: 'youtube', 485 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0', 486 }, 487 { 488 type: 'youtube_short', 489 source: 'youtubeShorts', 490 hideDetails: true, 491 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0', 492 }, 493 { 494 type: 'youtube_video', 495 source: 'youtube', 496 playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0', 497 }, 498 499 undefined, 500 undefined, 501 undefined, 502 503 { 504 type: 'twitch_video', 505 source: 'twitch', 506 playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&channel=channelName&parent=localhost`, 507 }, 508 { 509 type: 'twitch_video', 510 source: 'twitch', 511 playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&channel=channelName&parent=localhost`, 512 }, 513 { 514 type: 'twitch_video', 515 source: 'twitch', 516 playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&channel=channelName&parent=localhost`, 517 }, 518 { 519 type: 'twitch_video', 520 source: 'twitch', 521 playerUri: `https://clips.twitch.tv/embed?volume=0.5&autoplay=true&clip=clipId&parent=localhost`, 522 }, 523 { 524 type: 'twitch_video', 525 source: 'twitch', 526 playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&video=videoId&parent=localhost`, 527 }, 528 529 { 530 type: 'spotify_playlist', 531 source: 'spotify', 532 playerUri: `https://open.spotify.com/embed/playlist/playlistId`, 533 }, 534 { 535 type: 'spotify_playlist', 536 source: 'spotify', 537 playerUri: `https://open.spotify.com/embed/playlist/playlistId`, 538 }, 539 { 540 type: 'spotify_playlist', 541 source: 'spotify', 542 playerUri: `https://open.spotify.com/embed/playlist/playlistId`, 543 }, 544 545 { 546 type: 'spotify_song', 547 source: 'spotify', 548 playerUri: `https://open.spotify.com/embed/track/songId`, 549 }, 550 { 551 type: 'spotify_song', 552 source: 'spotify', 553 playerUri: `https://open.spotify.com/embed/track/songId`, 554 }, 555 { 556 type: 'spotify_song', 557 source: 'spotify', 558 playerUri: `https://open.spotify.com/embed/track/songId`, 559 }, 560 561 { 562 type: 'spotify_album', 563 source: 'spotify', 564 playerUri: `https://open.spotify.com/embed/album/albumId`, 565 }, 566 { 567 type: 'spotify_album', 568 source: 'spotify', 569 playerUri: `https://open.spotify.com/embed/album/albumId`, 570 }, 571 { 572 type: 'spotify_album', 573 source: 'spotify', 574 playerUri: `https://open.spotify.com/embed/album/albumId`, 575 }, 576 577 { 578 type: 'soundcloud_track', 579 source: 'soundcloud', 580 playerUri: `https://w.soundcloud.com/player/?url=https://soundcloud.com/user/track&auto_play=true&visual=false&hide_related=true`, 581 }, 582 { 583 type: 'soundcloud_set', 584 source: 'soundcloud', 585 playerUri: `https://w.soundcloud.com/player/?url=https://soundcloud.com/user/sets/set&auto_play=true&visual=false&hide_related=true`, 586 }, 587 undefined, 588 589 { 590 type: 'apple_music_playlist', 591 source: 'appleMusic', 592 playerUri: 593 'https://embed.music.apple.com/us/playlist/playlistName/playlistId', 594 }, 595 { 596 type: 'apple_music_album', 597 source: 'appleMusic', 598 playerUri: 'https://embed.music.apple.com/us/album/albumName/albumId', 599 }, 600 { 601 type: 'apple_music_song', 602 source: 'appleMusic', 603 playerUri: 604 'https://embed.music.apple.com/us/album/albumName/albumId?i=songId', 605 }, 606 607 { 608 type: 'vimeo_video', 609 source: 'vimeo', 610 playerUri: 'https://player.vimeo.com/video/videoId?autoplay=1', 611 }, 612 { 613 type: 'vimeo_video', 614 source: 'vimeo', 615 playerUri: 'https://player.vimeo.com/video/videoId?autoplay=1', 616 }, 617 618 { 619 type: 'giphy_gif', 620 source: 'giphy', 621 isGif: true, 622 hideDetails: true, 623 metaUri: 'https://giphy.com/gifs/gifId', 624 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 625 }, 626 undefined, 627 undefined, 628 629 { 630 type: 'giphy_gif', 631 source: 'giphy', 632 isGif: true, 633 hideDetails: true, 634 metaUri: 'https://giphy.com/gifs/gifId', 635 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 636 }, 637 { 638 type: 'giphy_gif', 639 source: 'giphy', 640 isGif: true, 641 hideDetails: true, 642 metaUri: 'https://giphy.com/gifs/gifId', 643 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 644 }, 645 { 646 type: 'giphy_gif', 647 source: 'giphy', 648 isGif: true, 649 hideDetails: true, 650 metaUri: 'https://giphy.com/gifs/gifId', 651 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 652 }, 653 { 654 type: 'giphy_gif', 655 source: 'giphy', 656 isGif: true, 657 hideDetails: true, 658 metaUri: 'https://giphy.com/gifs/gifId', 659 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 660 }, 661 { 662 type: 'giphy_gif', 663 source: 'giphy', 664 isGif: true, 665 hideDetails: true, 666 metaUri: 'https://giphy.com/gifs/gifId', 667 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 668 }, 669 { 670 type: 'giphy_gif', 671 source: 'giphy', 672 isGif: true, 673 hideDetails: true, 674 metaUri: 'https://giphy.com/gifs/gifId', 675 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 676 }, 677 undefined, 678 undefined, 679 undefined, 680 681 { 682 type: 'giphy_gif', 683 source: 'giphy', 684 isGif: true, 685 hideDetails: true, 686 metaUri: 'https://giphy.com/gifs/gifId', 687 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 688 }, 689 690 { 691 type: 'giphy_gif', 692 source: 'giphy', 693 isGif: true, 694 hideDetails: true, 695 metaUri: 'https://giphy.com/gifs/gifId', 696 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 697 }, 698 { 699 type: 'giphy_gif', 700 source: 'giphy', 701 isGif: true, 702 hideDetails: true, 703 metaUri: 'https://giphy.com/gifs/gifId', 704 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 705 }, 706 { 707 type: 'giphy_gif', 708 source: 'giphy', 709 isGif: true, 710 hideDetails: true, 711 metaUri: 'https://giphy.com/gifs/gifId', 712 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 713 }, 714 { 715 type: 'giphy_gif', 716 source: 'giphy', 717 isGif: true, 718 hideDetails: true, 719 metaUri: 'https://giphy.com/gifs/gifId', 720 playerUri: 'https://i.giphy.com/media/gifId/giphy.webp', 721 }, 722 723 { 724 type: 'tenor_gif', 725 source: 'tenor', 726 isGif: true, 727 hideDetails: true, 728 playerUri: 'https://tenor.com/view/gifId.gif', 729 }, 730 undefined, 731 undefined, 732 { 733 type: 'tenor_gif', 734 source: 'tenor', 735 isGif: true, 736 hideDetails: true, 737 playerUri: 'https://tenor.com/view/gifId.gif', 738 }, 739 { 740 type: 'tenor_gif', 741 source: 'tenor', 742 isGif: true, 743 hideDetails: true, 744 playerUri: 'https://tenor.com/intl/view/gifId.gif', 745 }, 746 ] 747 748 it('correctly grabs the correct id from uri', () => { 749 for (let i = 0; i < inputs.length; i++) { 750 const input = inputs[i] 751 const output = outputs[i] 752 753 const res = parseEmbedPlayerFromUrl(input) 754 755 expect(res).toEqual(output) 756 } 757 }) 758})