more tests
This commit is contained in:
parent
a2459c2187
commit
1923ed84d4
|
@ -1,10 +1,10 @@
|
|||
import { convertHtml, processTextForEmoji } from 'src/services/mini_html_converter/mini_html_converter.service.js'
|
||||
import { convertHtml, processTextForEmoji, getAttrs } from 'src/services/mini_html_converter/mini_html_converter.service.js'
|
||||
|
||||
describe('MiniHtmlConverter', () => {
|
||||
describe('convertHtml', () => {
|
||||
it('converts html into a tree structure', () => {
|
||||
const inputOutput = '1 <p>2</p> <b>3<img src="a">4</b>5'
|
||||
expect(convertHtml(inputOutput)).to.eql([
|
||||
const input = '1 <p>2</p> <b>3<img src="a">4</b>5'
|
||||
expect(convertHtml(input)).to.eql([
|
||||
'1 ',
|
||||
[
|
||||
'<p>',
|
||||
|
@ -25,8 +25,8 @@ describe('MiniHtmlConverter', () => {
|
|||
])
|
||||
})
|
||||
it('converts html to tree while preserving tag formatting', () => {
|
||||
const inputOutput = '1 <p >2</p><b >3<img src="a">4</b>5'
|
||||
expect(convertHtml(inputOutput)).to.eql([
|
||||
const input = '1 <p >2</p><b >3<img src="a">4</b>5'
|
||||
expect(convertHtml(input)).to.eql([
|
||||
'1 ',
|
||||
[
|
||||
'<p >',
|
||||
|
@ -46,8 +46,8 @@ describe('MiniHtmlConverter', () => {
|
|||
])
|
||||
})
|
||||
it('converts semi-broken html', () => {
|
||||
const inputOutput = '1 <br> 2 <p> 42'
|
||||
expect(convertHtml(inputOutput)).to.eql([
|
||||
const input = '1 <br> 2 <p> 42'
|
||||
expect(convertHtml(input)).to.eql([
|
||||
'1 ',
|
||||
['<br>'],
|
||||
' 2 ',
|
||||
|
@ -58,8 +58,8 @@ describe('MiniHtmlConverter', () => {
|
|||
])
|
||||
})
|
||||
it('realistic case 1', () => {
|
||||
const inputOutput = '<p><span class="h-card"><a class="u-url mention" data-user="9wRC6T2ZZiKWJ0vUi8" href="https://cawfee.club/users/benis" rel="ugc">@<span>benis</span></a></span> <span class="h-card"><a class="u-url mention" data-user="194" href="https://shigusegubu.club/users/hj" rel="ugc">@<span>hj</span></a></span> nice</p>'
|
||||
expect(convertHtml(inputOutput)).to.eql([
|
||||
const input = '<p><span class="h-card"><a class="u-url mention" data-user="9wRC6T2ZZiKWJ0vUi8" href="https://cawfee.club/users/benis" rel="ugc">@<span>benis</span></a></span> <span class="h-card"><a class="u-url mention" data-user="194" href="https://shigusegubu.club/users/hj" rel="ugc">@<span>hj</span></a></span> nice</p>'
|
||||
expect(convertHtml(input)).to.eql([
|
||||
[
|
||||
'<p>',
|
||||
[
|
||||
|
@ -129,15 +129,16 @@ describe('MiniHtmlConverter', () => {
|
|||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('processTextForEmoji', () => {
|
||||
it('processes all emoji in text', () => {
|
||||
const inputOutput = 'Hello from finland! :lol: We have best water! :lmao:'
|
||||
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(inputOutput, emojis, processor)).to.eql([
|
||||
expect(processTextForEmoji(input, emojis, processor)).to.eql([
|
||||
'Hello from finland! ',
|
||||
{ shortcode: 'lol', src: 'LOL' },
|
||||
' We have best water! ',
|
||||
|
@ -145,13 +146,21 @@ describe('MiniHtmlConverter', () => {
|
|||
])
|
||||
})
|
||||
it('leaves text as is', () => {
|
||||
const inputOutput = 'Number one: that\'s terror'
|
||||
const input = 'Number one: that\'s terror'
|
||||
const emojis = []
|
||||
const processor = ({ shortcode, src }) => ({ shortcode, src })
|
||||
expect(processTextForEmoji(inputOutput, emojis, processor)).to.eql([
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue