_'
+ const result = convertHtmlToLines(input)
+ const comparableResult = result.map(mapOnlyText(processorReplace)).join('')
+ expect(comparableResult).to.eql(output)
+ })
+
+ it('fed with not really HTML at this point... tags that aren\'t finished', () => {
+ const input = 'do you expect me to finish this
{
+ const input = 'look ma
p \nwithin
p!
and a
div!
'
+ const output = '_
_\n_
_
_
_
'
+ const result = convertHtmlToLines(input)
+ const comparableResult = result.map(mapOnlyText(processorReplace)).join('')
+ expect(comparableResult).to.eql(output)
+ })
+
+ it('fed with maybe valid HTML? self-closing divs and ps', () => {
+ const input = 'a
what now
?'
+ const output = '_
_
_'
+ const result = convertHtmlToLines(input)
+ const comparableResult = result.map(mapOnlyText(processorReplace)).join('')
+ expect(comparableResult).to.eql(output)
+ })
+
+ it('fed with valid XHTML containing a CDATA', () => {
+ const input = 'Yes, it is me, '
+ const output = '_'
+ const result = convertHtmlToLines(input)
+ const comparableResult = result.map(mapOnlyText(processorReplace)).join('')
+ expect(comparableResult).to.eql(output)
+ })
+ })
+})
diff --git a/test/unit/specs/services/html_converter/html_tree_converter.spec.js b/test/unit/specs/services/html_converter/html_tree_converter.spec.js
new file mode 100644
index 00000000..a54745c3
--- /dev/null
+++ b/test/unit/specs/services/html_converter/html_tree_converter.spec.js
@@ -0,0 +1,166 @@
+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
3
45'
+ expect(convertHtmlToTree(input)).to.eql([
+ '1 ',
+ [
+ '
',
+ ['2'],
+ '
'
+ ],
+ ' ',
+ [
+ '
',
+ [
+ '3',
+ ['
'],
+ '4'
+ ],
+ ''
+ ],
+ '5'
+ ])
+ })
+ it('converts html to tree while preserving tag formatting', () => {
+ const input = '1
2
3
45'
+ 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)
+ })
+ })
+})
diff --git a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js
deleted file mode 100644
index 8df2fbc3..00000000
--- a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js
+++ /dev/null
@@ -1,166 +0,0 @@
-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 input = '1
2
3
45'
- expect(convertHtml(input)).to.eql([
- '1 ',
- [
- '
',
- ['2'],
- '
'
- ],
- ' ',
- [
- '
',
- [
- '3',
- ['
'],
- '4'
- ],
- ''
- ],
- '5'
- ])
- })
- it('converts html to tree while preserving tag formatting', () => {
- const input = '1
2
3
45'
- expect(convertHtml(input)).to.eql([
- '1 ',
- [
- '
',
- ['2'],
- '
'
- ],
- [
- '
',
- [
- '3',
- ['
'],
- '4'
- ],
- ''
- ],
- '5'
- ])
- })
- it('converts semi-broken html', () => {
- const input = '1
2
42'
- expect(convertHtml(input)).to.eql([
- '1 ',
- ['
'],
- ' 2 ',
- [
- '
',
- [' 42']
- ]
- ])
- })
- it('realistic case 1', () => {
- const input = '
@benis @hj nice
'
- expect(convertHtml(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(convertHtml(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)
- })
- })
-})
diff --git a/test/unit/specs/services/tiny_post_html_processor/tiny_post_html_processor.spec.js b/test/unit/specs/services/tiny_post_html_processor/tiny_post_html_processor.spec.js
deleted file mode 100644
index f301429d..00000000
--- a/test/unit/specs/services/tiny_post_html_processor/tiny_post_html_processor.spec.js
+++ /dev/null
@@ -1,96 +0,0 @@
-import { processHtml } from 'src/services/tiny_post_html_processor/tiny_post_html_processor.service.js'
-
-describe('TinyPostHTMLProcessor', () => {
- describe('with processor that keeps original line should not make any changes to HTML when', () => {
- const processorKeep = (line) => line
- it('fed with regular HTML with newlines', () => {
- const inputOutput = '1
2
3 4
5 \n 6
7
8
\n
'
- expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
- })
-
- it('fed with possibly broken HTML with invalid tags/composition', () => {
- const inputOutput = '
ayylmao '
- expect(processHtml(inputOutput, processorKeep)).to.eql(inputOutput)
- })
-
- it('fed with very broken HTML with broken composition', () => {
- const inputOutput = ' lmao what