import { convertHtmlToLines } from 'src/services/html_converter/html_line_converter.service.js' const greentextHandle = new Set(['p', 'div']) const mapOnlyText = (processor) => (input) => { if (input.text && input.level.every(l => greentextHandle.has(l))) { return processor(input.text) } else if (input.text) { return input.text } else { return input } } describe('html_line_converter', () => { 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
' const result = convertHtmlToLines(inputOutput) const comparableResult = result.map(mapOnlyText(processorKeep)).join('') expect(comparableResult).to.eql(inputOutput) }) it('fed with possibly broken HTML with invalid tags/composition', () => { const inputOutput = ' ayylmao ' const result = convertHtmlToLines(inputOutput) const comparableResult = result.map(mapOnlyText(processorKeep)).join('') expect(comparableResult).to.eql(inputOutput) }) it('fed with very broken HTML with broken composition', () => { const inputOutput = '

lmao what whats going on
wha

' const result = convertHtmlToLines(inputOutput) const comparableResult = result.map(mapOnlyText(processorKeep)).join('') expect(comparableResult).to.eql(inputOutput) }) it('fed with sorta valid HTML but tags aren\'t closed', () => { const inputOutput = 'just leaving a

hanging' const result = convertHtmlToLines(inputOutput) const comparableResult = result.map(mapOnlyText(processorKeep)).join('') expect(comparableResult).to.eql(inputOutput) }) it('fed with not really HTML at this point... tags that aren\'t finished', () => { const inputOutput = 'do you expect me to finish this
{ const inputOutput = 'look ma

p \nwithin

p!

and a
div!

' const result = convertHtmlToLines(inputOutput) const comparableResult = result.map(mapOnlyText(processorKeep)).join('') expect(comparableResult).to.eql(inputOutput) }) it('fed with maybe valid HTML? self-closing divs and ps', () => { const inputOutput = 'a
what now

?' const result = convertHtmlToLines(inputOutput) const comparableResult = result.map(mapOnlyText(processorKeep)).join('') expect(comparableResult).to.eql(inputOutput) }) it('fed with valid XHTML containing a CDATA', () => { const inputOutput = 'Yes, it is me, ' const result = convertHtmlToLines(inputOutput) const comparableResult = result.map(mapOnlyText(processorKeep)).join('') expect(comparableResult).to.eql(inputOutput) }) it('fed with some recognized but not handled elements', () => { const inputOutput = 'testing images\n\n' const result = convertHtmlToLines(inputOutput) const comparableResult = result.map(mapOnlyText(processorKeep)).join('') expect(comparableResult).to.eql(inputOutput) }) }) describe('with processor that replaces lines with word "_" should match expected line when', () => { const processorReplace = (line) => '_' it('fed with regular HTML with newlines', () => { const input = '1
2

3 4

5 \n 6

7
8


\n
' const output = '_
_

_

_\n_

_
_


\n
' const result = convertHtmlToLines(input) const comparableResult = result.map(mapOnlyText(processorReplace)).join('') expect(comparableResult).to.eql(output) }) it('fed with possibly broken HTML with invalid tags/composition', () => { const input = ' ayylmao ' const output = '_' const result = convertHtmlToLines(input) const comparableResult = result.map(mapOnlyText(processorReplace)).join('') expect(comparableResult).to.eql(output) }) it('fed with very broken HTML with broken composition', () => { const input = '

lmao what
whats going on
wha

' const output = '_

_

' const result = convertHtmlToLines(input) const comparableResult = result.map(mapOnlyText(processorReplace)).join('') expect(comparableResult).to.eql(output) }) it('fed with sorta valid HTML but tags aren\'t closed', () => { const input = 'just leaving a

hanging' const output = '_
_' 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? (XHTML) 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) }) it('Testing handling ignored blocks', () => { const input = `

> rei = "0"
      '0'
      > rei == 0
      true
      > rei == null
      false
That, christian-like JS diagram but it’s evangelion instead.
` const result = convertHtmlToLines(input) const comparableResult = result.map(mapOnlyText(processorReplace)).join('') expect(comparableResult).to.eql(input) }) it('Testing handling ignored blocks 2', () => { const input = `
An SSL error has happened.

Shakespeare

` const output = `
An SSL error has happened.

_

` const result = convertHtmlToLines(input) const comparableResult = result.map(mapOnlyText(processorReplace)).join('') expect(comparableResult).to.eql(output) }) }) })