aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs/services/html_converter/utility.spec.js
blob: cf6fd99b4a65d3c00d19856b52f1918011c756a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { processTextForEmoji, getAttrs } from 'src/services/html_converter/utility.service.js'

describe('html_converter utility', () => {
  describe('processTextForEmoji', () => {
    it('processes all emoji in text', () => {
      const input = 'Hello from finland! :lol: We have best water! :lmao:'
      const emojis = [
        { shortcode: 'lol', src: 'LOL' },
        { shortcode: 'lmao', src: 'LMAO' }
      ]
      const processor = ({ shortcode, src }) => ({ shortcode, src })
      expect(processTextForEmoji(input, emojis, processor)).to.eql([
        'Hello from finland! ',
        { shortcode: 'lol', src: 'LOL' },
        ' We have best water! ',
        { shortcode: 'lmao', src: 'LMAO' }
      ])
    })
    it('leaves text as is', () => {
      const input = 'Number one: that\'s terror'
      const emojis = []
      const processor = ({ shortcode, src }) => ({ shortcode, src })
      expect(processTextForEmoji(input, emojis, processor)).to.eql([
        'Number one: that\'s terror'
      ])
    })
  })

  describe('getAttrs', () => {
    it('extracts arguments from tag', () => {
      const input = '<img src="boop" cool ebin=\'true\'>'
      const output = { src: 'boop', cool: true, ebin: 'true' }

      expect(getAttrs(input)).to.eql(output)
    })
  })
})