import { convertHtmlToTree, processTextForEmoji, getAttrs } from 'src/services/html_converter/html_tree_converter.service.js'
describe('MiniHtmlConverter', () => {
describe('convertHtmlToTree', () => {
it('converts html into a tree structure', () => {
const input = '1
2
345'
expect(convertHtmlToTree(input)).to.eql([
'1 ',
[
'',
['2'],
'
'
],
' ',
[
'',
[
'3',
[''],
'4'
],
''
],
'5'
])
})
it('converts html to tree while preserving tag formatting', () => {
const input = '1 2
345'
expect(convertHtmlToTree(input)).to.eql([
'1 ',
[
'',
['2'],
'
'
],
[
'',
[
'3',
[''],
'4'
],
''
],
'5'
])
})
it('converts semi-broken html', () => {
const input = '1
2 42'
expect(convertHtmlToTree(input)).to.eql([
'1 ',
['
'],
' 2 ',
[
'
',
[' 42']
]
])
})
it('realistic case 1', () => {
const input = '
@benis @hj nice
'
expect(convertHtmlToTree(input)).to.eql([
[
'',
[
[
'',
[
[
'',
[
'@',
[
'',
[
'benis'
],
''
]
],
''
]
],
''
],
' ',
[
'',
[
[
'',
[
'@',
[
'',
[
'hj'
],
''
]
],
''
]
],
''
],
' nice'
],
'
'
]
])
})
it('realistic case 2', () => {
const inputOutput = 'Country improv: give me a city
Audience: Memphis
Improv troupe: come on, a better one
Audience: el paso'
expect(convertHtmlToTree(inputOutput)).to.eql([
'Country improv: give me a city',
[
'
'
],
'Audience: Memphis',
[
'
'
],
'Improv troupe: come on, a better one',
[
'
'
],
'Audience: el paso'
])
})
})
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 = ''
const output = { src: 'boop', cool: true, ebin: 'true' }
expect(getAttrs(input)).to.eql(output)
})
})
})