utility.spec.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { processTextForEmoji, getAttrs } from 'src/services/html_converter/utility.service.js'
  2. describe('html_converter utility', () => {
  3. describe('processTextForEmoji', () => {
  4. it('processes all emoji in text', () => {
  5. const input = 'Hello from finland! :lol: We have best water! :lmao:'
  6. const emojis = [
  7. { shortcode: 'lol', src: 'LOL' },
  8. { shortcode: 'lmao', src: 'LMAO' }
  9. ]
  10. const processor = ({ shortcode, src }) => ({ shortcode, src })
  11. expect(processTextForEmoji(input, emojis, processor)).to.eql([
  12. 'Hello from finland! ',
  13. { shortcode: 'lol', src: 'LOL' },
  14. ' We have best water! ',
  15. { shortcode: 'lmao', src: 'LMAO' }
  16. ])
  17. })
  18. it('leaves text as is', () => {
  19. const input = 'Number one: that\'s terror'
  20. const emojis = []
  21. const processor = ({ shortcode, src }) => ({ shortcode, src })
  22. expect(processTextForEmoji(input, emojis, processor)).to.eql([
  23. 'Number one: that\'s terror'
  24. ])
  25. })
  26. })
  27. describe('getAttrs', () => {
  28. it('extracts arguments from tag', () => {
  29. const input = '<img src="boop" cool ebin=\'true\'>'
  30. const output = { src: 'boop', cool: true, ebin: 'true' }
  31. expect(getAttrs(input)).to.eql(output)
  32. })
  33. })
  34. })