From bebafa1a2c38972245d37de70f4aec4bfb2083fd Mon Sep 17 00:00:00 2001
From: Henry Jameson
Date: Sun, 13 Jun 2021 13:29:26 +0300
Subject: refactored line converter, untied its logic from greentexting, better
handling of broken cases
---
.../html_converter/html_line_converter.spec.js | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/unit/specs/services/html_converter/html_line_converter.spec.js b/test/unit/specs/services/html_converter/html_line_converter.spec.js
index 9485233f..c8c89700 100644
--- a/test/unit/specs/services/html_converter/html_line_converter.spec.js
+++ b/test/unit/specs/services/html_converter/html_line_converter.spec.js
@@ -1,8 +1,17 @@
import { convertHtmlToLines } from 'src/services/html_converter/html_line_converter.service.js'
-const mapOnlyText = (processor) => (input) => input.text ? processor(input.text) : input
-
-describe('html_line_converter', () => {
+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.only('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', () => {
@@ -81,7 +90,7 @@ describe('html_line_converter', () => {
it('fed with very broken HTML with broken composition', () => {
const input = '
lmao what whats going on wha
'
- const output = '
_
__
'
+ const output = '_
_
'
const result = convertHtmlToLines(input)
const comparableResult = result.map(mapOnlyText(processorReplace)).join('')
expect(comparableResult).to.eql(output)
@@ -111,7 +120,7 @@ describe('html_line_converter', () => {
expect(comparableResult).to.eql(output)
})
- it('fed with maybe valid HTML? self-closing divs and ps', () => {
+ it('fed with maybe valid HTML? (XHTML) self-closing divs and ps', () => {
const input = 'a
what now
?'
const output = '_
_
_'
const result = convertHtmlToLines(input)
--
cgit v1.2.3-70-g09d2