You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
2.9 KiB

  1. import { expect } from 'chai';
  2. import emojify from '../../../app/javascript/mastodon/emoji';
  3. describe('emojify', () => {
  4. it('ignores unknown shortcodes', () => {
  5. expect(emojify(':foobarbazfake:')).to.equal(':foobarbazfake:');
  6. });
  7. it('ignores shortcodes inside of tags', () => {
  8. expect(emojify('<p data-foo=":smile:"></p>')).to.equal('<p data-foo=":smile:"></p>');
  9. });
  10. it('works with unclosed tags', () => {
  11. expect(emojify('hello>')).to.equal('hello>');
  12. expect(emojify('<hello')).to.equal('<hello');
  13. });
  14. it('works with unclosed shortcodes', () => {
  15. expect(emojify('smile:')).to.equal('smile:');
  16. expect(emojify(':smile')).to.equal(':smile');
  17. });
  18. it('does unicode', () => {
  19. expect(emojify('\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66')).to.equal(
  20. '<img draggable="false" class="emojione" alt="👩‍👩‍👦‍👦" title=":family_wwbb:" src="/emoji/1f469-1f469-1f466-1f466.svg" />');
  21. expect(emojify('\uD83D\uDC68\uD83D\uDC69\uD83D\uDC67\uD83D\uDC67')).to.equal(
  22. '<img draggable="false" class="emojione" alt="👨👩👧👧" title=":family_mwgg:" src="/emoji/1f468-1f469-1f467-1f467.svg" />');
  23. expect(emojify('\uD83D\uDC69\uD83D\uDC69\uD83D\uDC66')).to.equal('<img draggable="false" class="emojione" alt="👩👩👦" title=":family_wwb:" src="/emoji/1f469-1f469-1f466.svg" />');
  24. expect(emojify('\u2757')).to.equal(
  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')).to.equal(
  29. '<img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" /> <img draggable="false" class="emojione" alt="#️⃣" title=":hash:" src="/emoji/0023-20e3.svg" />');
  30. expect(emojify('\u2757#\uFE0F\u20E3')).to.equal(
  31. '<img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" /><img draggable="false" class="emojione" alt="#️⃣" title=":hash:" src="/emoji/0023-20e3.svg" />');
  32. expect(emojify('\u2757 #\uFE0F\u20E3 \u2757')).to.equal(
  33. '<img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" /> <img draggable="false" class="emojione" alt="#️⃣" title=":hash:" src="/emoji/0023-20e3.svg" /> <img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" />');
  34. expect(emojify('foo \u2757 #\uFE0F\u20E3 bar')).to.equal(
  35. 'foo <img draggable="false" class="emojione" alt="❗" title=":exclamation:" src="/emoji/2757.svg" /> <img draggable="false" class="emojione" alt="#️⃣" title=":hash:" src="/emoji/0023-20e3.svg" /> bar');
  36. });
  37. it('ignores unicode inside of tags', () => {
  38. expect(emojify('<p data-foo="\uD83D\uDC69\uD83D\uDC69\uD83D\uDC66"></p>')).to.equal('<p data-foo="\uD83D\uDC69\uD83D\uDC69\uD83D\uDC66"></p>');
  39. });
  40. });