forked from AkkomaGang/akkoma-fe
more tests
This commit is contained in:
parent
a2459c2187
commit
1923ed84d4
1 changed files with 22 additions and 13 deletions
|
@ -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('MiniHtmlConverter', () => {
|
||||||
describe('convertHtml', () => {
|
describe('convertHtml', () => {
|
||||||
it('converts html into a tree structure', () => {
|
it('converts html into a tree structure', () => {
|
||||||
const inputOutput = '1 <p>2</p> <b>3<img src="a">4</b>5'
|
const input = '1 <p>2</p> <b>3<img src="a">4</b>5'
|
||||||
expect(convertHtml(inputOutput)).to.eql([
|
expect(convertHtml(input)).to.eql([
|
||||||
'1 ',
|
'1 ',
|
||||||
[
|
[
|
||||||
'<p>',
|
'<p>',
|
||||||
|
@ -25,8 +25,8 @@ describe('MiniHtmlConverter', () => {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
it('converts html to tree while preserving tag formatting', () => {
|
it('converts html to tree while preserving tag formatting', () => {
|
||||||
const inputOutput = '1 <p >2</p><b >3<img src="a">4</b>5'
|
const input = '1 <p >2</p><b >3<img src="a">4</b>5'
|
||||||
expect(convertHtml(inputOutput)).to.eql([
|
expect(convertHtml(input)).to.eql([
|
||||||
'1 ',
|
'1 ',
|
||||||
[
|
[
|
||||||
'<p >',
|
'<p >',
|
||||||
|
@ -46,8 +46,8 @@ describe('MiniHtmlConverter', () => {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
it('converts semi-broken html', () => {
|
it('converts semi-broken html', () => {
|
||||||
const inputOutput = '1 <br> 2 <p> 42'
|
const input = '1 <br> 2 <p> 42'
|
||||||
expect(convertHtml(inputOutput)).to.eql([
|
expect(convertHtml(input)).to.eql([
|
||||||
'1 ',
|
'1 ',
|
||||||
['<br>'],
|
['<br>'],
|
||||||
' 2 ',
|
' 2 ',
|
||||||
|
@ -58,8 +58,8 @@ describe('MiniHtmlConverter', () => {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
it('realistic case 1', () => {
|
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>'
|
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(inputOutput)).to.eql([
|
expect(convertHtml(input)).to.eql([
|
||||||
[
|
[
|
||||||
'<p>',
|
'<p>',
|
||||||
[
|
[
|
||||||
|
@ -129,15 +129,16 @@ describe('MiniHtmlConverter', () => {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('processTextForEmoji', () => {
|
describe('processTextForEmoji', () => {
|
||||||
it('processes all emoji in text', () => {
|
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 = [
|
const emojis = [
|
||||||
{ shortcode: 'lol', src: 'LOL' },
|
{ shortcode: 'lol', src: 'LOL' },
|
||||||
{ shortcode: 'lmao', src: 'LMAO' }
|
{ shortcode: 'lmao', src: 'LMAO' }
|
||||||
]
|
]
|
||||||
const processor = ({ shortcode, src }) => ({ shortcode, src })
|
const processor = ({ shortcode, src }) => ({ shortcode, src })
|
||||||
expect(processTextForEmoji(inputOutput, emojis, processor)).to.eql([
|
expect(processTextForEmoji(input, emojis, processor)).to.eql([
|
||||||
'Hello from finland! ',
|
'Hello from finland! ',
|
||||||
{ shortcode: 'lol', src: 'LOL' },
|
{ shortcode: 'lol', src: 'LOL' },
|
||||||
' We have best water! ',
|
' We have best water! ',
|
||||||
|
@ -145,13 +146,21 @@ describe('MiniHtmlConverter', () => {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
it('leaves text as is', () => {
|
it('leaves text as is', () => {
|
||||||
const inputOutput = 'Number one: that\'s terror'
|
const input = 'Number one: that\'s terror'
|
||||||
const emojis = []
|
const emojis = []
|
||||||
const processor = ({ shortcode, src }) => ({ shortcode, src })
|
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'
|
'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 a new issue