logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

emoji-test.js (5664B)


  1. import emojify from '../emoji';
  2. describe('emoji', () => {
  3. describe('.emojify', () => {
  4. it('ignores unknown shortcodes', () => {
  5. expect(emojify(':foobarbazfake:')).toEqual(':foobarbazfake:');
  6. });
  7. it('ignores shortcodes inside of tags', () => {
  8. expect(emojify('<p data-foo=":smile:"></p>')).toEqual('<p data-foo=":smile:"></p>');
  9. });
  10. it('works with unclosed tags', () => {
  11. expect(emojify('hello>')).toEqual('hello>');
  12. expect(emojify('<hello')).toEqual('<hello');
  13. });
  14. it('works with unclosed shortcodes', () => {
  15. expect(emojify('smile:')).toEqual('smile:');
  16. expect(emojify(':smile')).toEqual(':smile');
  17. });
  18. it('does unicode', () => {
  19. expect(emojify('\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66')).toEqual(
  20. '<img draggable="false" class="emojione" alt="πŸ‘©β€πŸ‘©β€πŸ‘¦β€πŸ‘¦" title=":woman-woman-boy-boy:" src="/emoji/1f469-200d-1f469-200d-1f466-200d-1f466.svg" />');
  21. expect(emojify('πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘§')).toEqual(
  22. '<img draggable="false" class="emojione" alt="πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘§" title=":man-woman-girl-girl:" src="/emoji/1f468-200d-1f469-200d-1f467-200d-1f467.svg" />');
  23. expect(emojify('πŸ‘©β€πŸ‘©β€πŸ‘¦')).toEqual('<img draggable="false" class="emojione" alt="πŸ‘©β€πŸ‘©β€πŸ‘¦" title=":woman-woman-boy:" src="/emoji/1f469-200d-1f469-200d-1f466.svg" />');
  24. expect(emojify('\u2757')).toEqual(
  25. '<img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" />');
  26. });
  27. it('does multiple unicode', () => {
  28. expect(emojify('\u2757 #\uFE0F\u20E3')).toEqual(
  29. '<img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" /> <img draggable="false" class="emojione" alt="#️⃣" title=":hash:" src="/emoji/23-20e3.svg" />');
  30. expect(emojify('\u2757#\uFE0F\u20E3')).toEqual(
  31. '<img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" /><img draggable="false" class="emojione" alt="#️⃣" title=":hash:" src="/emoji/23-20e3.svg" />');
  32. expect(emojify('\u2757 #\uFE0F\u20E3 \u2757')).toEqual(
  33. '<img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" /> <img draggable="false" class="emojione" alt="#️⃣" title=":hash:" src="/emoji/23-20e3.svg" /> <img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" />');
  34. expect(emojify('foo \u2757 #\uFE0F\u20E3 bar')).toEqual(
  35. 'foo <img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" /> <img draggable="false" class="emojione" alt="#️⃣" title=":hash:" src="/emoji/23-20e3.svg" /> bar');
  36. });
  37. it('ignores unicode inside of tags', () => {
  38. expect(emojify('<p data-foo="\uD83D\uDC69\uD83D\uDC69\uD83D\uDC66"></p>')).toEqual('<p data-foo="\uD83D\uDC69\uD83D\uDC69\uD83D\uDC66"></p>');
  39. });
  40. it('does multiple emoji properly (issue 5188)', () => {
  41. expect(emojify('πŸ‘ŒπŸŒˆπŸ’•')).toEqual('<img draggable="false" class="emojione" alt="πŸ‘Œ" title=":ok_hand:" src="/emoji/1f44c.svg" /><img draggable="false" class="emojione" alt="🌈" title=":rainbow:" src="/emoji/1f308.svg" /><img draggable="false" class="emojione" alt="πŸ’•" title=":two_hearts:" src="/emoji/1f495.svg" />');
  42. expect(emojify('πŸ‘Œ 🌈 πŸ’•')).toEqual('<img draggable="false" class="emojione" alt="πŸ‘Œ" title=":ok_hand:" src="/emoji/1f44c.svg" /> <img draggable="false" class="emojione" alt="🌈" title=":rainbow:" src="/emoji/1f308.svg" /> <img draggable="false" class="emojione" alt="πŸ’•" title=":two_hearts:" src="/emoji/1f495.svg" />');
  43. });
  44. it('does an emoji that has no shortcode', () => {
  45. expect(emojify('πŸ•‰οΈ')).toEqual('<img draggable="false" class="emojione" alt="πŸ•‰οΈ" title="" src="/emoji/1f549.svg" />');
  46. });
  47. it('does an emoji whose filename is irregular', () => {
  48. expect(emojify('↙️')).toEqual('<img draggable="false" class="emojione" alt="↙️" title=":arrow_lower_left:" src="/emoji/2199.svg" />');
  49. });
  50. it('avoid emojifying on invisible text', () => {
  51. expect(emojify('<a href="http://example.com/test%F0%9F%98%84"><span class="invisible">http://</span><span class="ellipsis">example.com/te</span><span class="invisible">stπŸ˜„</span></a>'))
  52. .toEqual('<a href="http://example.com/test%F0%9F%98%84"><span class="invisible">http://</span><span class="ellipsis">example.com/te</span><span class="invisible">stπŸ˜„</span></a>');
  53. expect(emojify('<span class="invisible">:luigi:</span>', { ':luigi:': { static_url: 'luigi.exe' } }))
  54. .toEqual('<span class="invisible">:luigi:</span>');
  55. });
  56. it('avoid emojifying on invisible text with nested tags', () => {
  57. expect(emojify('<span class="invisible">πŸ˜„<span class="foo">bar</span>😴</span>πŸ˜‡'))
  58. .toEqual('<span class="invisible">πŸ˜„<span class="foo">bar</span>😴</span><img draggable="false" class="emojione" alt="πŸ˜‡" title=":innocent:" src="/emoji/1f607.svg" />');
  59. expect(emojify('<span class="invisible">πŸ˜„<span class="invisible">πŸ˜•</span>😴</span>πŸ˜‡'))
  60. .toEqual('<span class="invisible">πŸ˜„<span class="invisible">πŸ˜•</span>😴</span><img draggable="false" class="emojione" alt="πŸ˜‡" title=":innocent:" src="/emoji/1f607.svg" />');
  61. expect(emojify('<span class="invisible">πŸ˜„<br/>😴</span>πŸ˜‡'))
  62. .toEqual('<span class="invisible">πŸ˜„<br/>😴</span><img draggable="false" class="emojione" alt="πŸ˜‡" title=":innocent:" src="/emoji/1f607.svg" />');
  63. });
  64. });
  65. });