diff --git a/tests/backend/specs/api/importexport.js b/tests/backend/specs/api/importexport.js
index 7490f2160..bfafc6b31 100644
--- a/tests/backend/specs/api/importexport.js
+++ b/tests/backend/specs/api/importexport.js
@@ -67,7 +67,163 @@ const testImports = {
input: '
',
expectedHTML: '
',
expectedText: '\tindent\n\tindent\n\n'
- }
+ },
+ lineWithMultipleSpaces: {
+ description: 'Multiple spaces should be collapsed',
+ input: 'Text with more than one space.
',
+ expectedHTML: 'Text with more than one space.
',
+ expectedText: 'Text with more than one space.\n\n'
+ },
+ lineWithMultipleNonBreakingAndNormalSpaces: {
+ // XXX the HTML between "than" and "one" looks strange
+ description: 'non-breaking space should be preserved, but can be replaced when it',
+ input: 'Text with more than one space.
',
+ expectedHTML: 'Text with more than one space.
',
+ expectedText: 'Text with more than one space.\n\n'
+ },
+ multiplenbsp: {
+ description: 'Multiple non-breaking space should be preserved',
+ input: '
',
+ expectedHTML: '
',
+ expectedText: ' \n\n'
+ },
+ multipleNonBreakingSpaceBetweenWords: {
+ description: 'A normal space is always inserted before a word',
+ input: ' word1 word2 word3
',
+ expectedHTML: ' word1 word2 word3
',
+ expectedText: ' word1 word2 word3\n\n'
+ },
+ nonBreakingSpacePreceededBySpaceBetweenWords: {
+ description: 'A non-breaking space preceeded by a normal space',
+ input: ' word1 word2 word3
',
+ expectedHTML: ' word1 word2 word3
',
+ expectedText: ' word1 word2 word3\n\n'
+ },
+ nonBreakingSpaceFollowededBySpaceBetweenWords: {
+ description: 'A non-breaking space followed by a normal space',
+ input: ' word1 word2 word3
',
+ expectedHTML: ' word1 word2 word3
',
+ expectedText: ' word1 word2 word3\n\n'
+ },
+ spacesAfterNewline: {
+ description: 'Collapse spaces that follow a newline',
+ input:'something
something
',
+ expectedHTML: 'something
something
',
+ expectedText: 'something\nsomething\n\n'
+ },
+ spacesAfterNewlineP: {
+ description: 'Collapse spaces that follow a paragraph',
+ input:'something something
',
+ expectedHTML: 'something
something
',
+ expectedText: 'something\n\nsomething\n\n'
+ },
+ spacesAtEndOfLine: {
+ description: 'Collapse spaces that preceed/follow a newline',
+ input:'something
something
',
+ expectedHTML: 'something
something
',
+ expectedText: 'something\nsomething\n\n'
+ },
+ spacesAtEndOfLineP: {
+ description: 'Collapse spaces that preceed/follow a paragraph',
+ input:'something something
',
+ expectedHTML: 'something
something
',
+ expectedText: 'something\n\nsomething\n\n'
+ },
+ nonBreakingSpacesAfterNewlines: {
+ description: 'Don\'t collapse non-breaking spaces that follow a newline',
+ input:'something
something
',
+ expectedHTML: 'something
something
',
+ expectedText: 'something\n something\n\n'
+ },
+ nonBreakingSpacesAfterNewlinesP: {
+ description: 'Don\'t collapse non-breaking spaces that follow a paragraph',
+ input:'something something
',
+ expectedHTML: 'something
something
',
+ expectedText: 'something\n\n something\n\n'
+ },
+ collapseSpacesInsideElements: {
+ description: 'Preserve only one space when multiple are present',
+ input: 'Need more space s !
',
+ expectedHTML: 'Need more space s !
',
+ expectedText: 'Need more space s !\n\n'
+ },
+ collapseSpacesAcrossNewlines: {
+ description: 'Newlines and multiple spaces across newlines should be collapsed',
+ input: `
+ Need
+ more
+ space
+ s
+ !
`,
+ expectedHTML: 'Need more space s !
',
+ expectedText: 'Need more space s !\n\n'
+ },
+ multipleNewLinesAtBeginning: {
+ description: 'Multiple new lines and paragraphs at the beginning should be preserved',
+ input: '
first line
second line
',
+ expectedHTML: '
first line
second line
',
+ expectedText: '\n\n\n\nfirst line\n\nsecond line\n\n'
+ },
+ multiLineParagraph:{
+ description: "A paragraph with multiple lines should not loose spaces when lines are combined",
+ input:`
+
+ а б в г ґ д е є ж з и і ї й к л м н о
+ п р с т у ф х ц ч ш щ ю я ь
+
+`,
+ expectedHTML: 'а б в г ґ д е є ж з и і ї й к л м н о п р с т у ф х ц ч ш щ ю я ь
',
+ expectedText: 'а б в г ґ д е є ж з и і ї й к л м н о п р с т у ф х ц ч ш щ ю я ь\n\n'
+ },
+ multiLineParagraphWithPre:{
+ //XXX why is there before "in"?
+ description: "lines in preformatted text should be kept intact",
+ input:`
+
+ а б в г ґ д е є ж з и і ї й к л м н о
multiple
+ lines
+ in
+ pre
+
п р с т у ф х ц ч ш щ ю я
+ь
+`,
+ expectedHTML: 'а б в г ґ д е є ж з и і ї й к л м н о
multiple
lines
in
pre
п р с т у ф х ц ч ш щ ю я ь
',
+ expectedText: 'а б в г ґ д е є ж з и і ї й к л м н о\nmultiple\n lines\n in\n pre\n\nп р с т у ф х ц ч ш щ ю я ь\n\n'
+ },
+ preIntroducesASpace: {
+ description: "pre should be on a new line not preceeded by a space",
+ input:`
+ 1
+
preline
+
`,
+ expectedHTML: '1
preline
',
+ expectedText: '1\npreline\n\n\n'
+ },
+ dontDeleteSpaceInsideElements: {
+ description: 'Preserve spaces inside elements',
+ input: 'Need more space s !
',
+ expectedHTML: 'Need more space s !
',
+ expectedText: 'Need more space s !\n\n'
+ },
+ dontDeleteSpaceOutsideElements: {
+ description: 'Preserve spaces outside elements',
+ input: 'Need more space s !
',
+ expectedHTML: 'Need more space s !
',
+ expectedText: 'Need more space s !\n\n'
+ },
+ dontDeleteSpaceAtEndOfElement: {
+ description: 'Preserve spaces at the end of an element',
+ input: 'Need more space s !
',
+ expectedHTML: 'Need more space s !
',
+ expectedText: 'Need more space s !\n\n'
+ },
+ dontDeleteSpaceAtBeginOfElements: {
+ description: 'Preserve spaces at the start of an element',
+ input: 'Need more space s !
',
+ expectedHTML: 'Need more space s !
',
+ expectedText: 'Need more space s !\n\n'
+ },
+>>>>>>> 5a47aff2... tests for spaces
};
describe(__filename, function () {
diff --git a/tests/backend/specs/contentcollector.js b/tests/backend/specs/contentcollector.js
index 3608faed6..c85904917 100644
--- a/tests/backend/specs/contentcollector.js
+++ b/tests/backend/specs/contentcollector.js
@@ -1,6 +1,14 @@
'use strict';
/* eslint-disable max-len */
+/*
+ * While importexport tests target the `setHTML` API endpoint, which is nearly identical to what happens
+ * when a user manually imports a document via the UI, the contentcollector tests here don't use rehype to process
+ * the document. Rehype removes spaces and newĺines were applicable, so the expected results here can
+ * differ from importexport.js.
+ *
+ * If you add tests here, please also add them to importexport.js
+ */
const contentcollector = require('../../../src/static/js/contentcollector');
const AttributePool = require('../../../src/static/js/AttributePool');
@@ -113,6 +121,156 @@ const tests = {
expectedLineAttribs: ['+5'],
expectedText: ['empty'],
},
+ lineWithMultipleSpaces: {
+ description: 'Multiple spaces should be preserved',
+ html: 'Text with more than one space.
',
+ expectedLineAttribs: [ '+10' ],
+ expectedText: ['Text with more than one space.']
+ },
+ lineWithMultipleNonBreakingAndNormalSpaces: {
+ description: 'non-breaking and normal space should be preserved',
+ html: 'Text with more than one space.
',
+ expectedLineAttribs: [ '+10' ],
+ expectedText: ['Text with more than one space.']
+ },
+ multiplenbsp: {
+ description: 'Multiple nbsp should be preserved',
+ html: '
',
+ expectedLineAttribs: [ '+2' ],
+ expectedText: [' ']
+ },
+ multipleNonBreakingSpaceBetweenWords: {
+ description: 'Multiple nbsp between words ',
+ html: ' word1 word2 word3
',
+ expectedLineAttribs: [ '+m' ],
+ expectedText: [' word1 word2 word3']
+ },
+ nonBreakingSpacePreceededBySpaceBetweenWords: {
+ description: 'A non-breaking space preceeded by a normal space',
+ html: ' word1 word2 word3
',
+ expectedLineAttribs: [ '+l' ],
+ expectedText: [' word1 word2 word3']
+ },
+ nonBreakingSpaceFollowededBySpaceBetweenWords: {
+ description: 'A non-breaking space followed by a normal space',
+ html: ' word1 word2 word3
',
+ expectedLineAttribs: [ '+l' ],
+ expectedText: [' word1 word2 word3']
+ },
+ spacesAfterNewline: {
+ description: 'Don\'t collapse spaces that follow a newline',
+ html:'something
something
',
+ expectedLineAttribs: ['+9', '+m'],
+ expectedText: ['something', ' something']
+ },
+ spacesAfterNewlineP: {
+ description: 'Don\'t collapse spaces that follow a empty paragraph',
+ html:'something something
',
+ expectedLineAttribs: ['+9', '', '+m'],
+ expectedText: ['something', '', ' something']
+ },
+ spacesAtEndOfLine: {
+ description: 'Don\'t collapse spaces that preceed/follow a newline',
+ html:'something
something
',
+ expectedLineAttribs: ['+l', '+m'],
+ expectedText: ['something ', ' something']
+ },
+ spacesAtEndOfLineP: {
+ description: 'Don\'t collapse spaces that preceed/follow a empty paragraph',
+ html:'something something
',
+ expectedLineAttribs: ['+l', '', '+m'],
+ expectedText: ['something ', '', ' something']
+ },
+ nonBreakingSpacesAfterNewlines: {
+ description: 'Don\'t collapse non-breaking spaces that follow a newline',
+ html:'something
something
',
+ expectedLineAttribs: ['+9', '+c'],
+ expectedText: ['something', ' something']
+ },
+ nonBreakingSpacesAfterNewlinesP: {
+ description: 'Don\'t collapse non-breaking spaces that follow a paragraph',
+ html:'something something
',
+ expectedLineAttribs: ['+9', '', '+c'],
+ expectedText: ['something', '', ' something']
+ },
+ preserveSpacesInsideElements: {
+ description: 'Preserve all spaces when multiple are present',
+ html: 'Need more space s !
',
+ expectedLineAttribs: ['+h*0+4+2'],
+ expectedText: ['Need more space s !'],
+ },
+ preserveSpacesAcrossNewlines: {
+ description: 'Newlines and multiple spaces across newlines should be preserved',
+ html: `
+ Need
+ more
+ space
+ s
+ !
`,
+ expectedLineAttribs: [ '+19*0+4+b' ],
+ expectedText: [ 'Need more space s !' ]
+ },
+ multipleNewLinesAtBeginning: {
+ description: 'Multiple new lines at the beginning should be preserved',
+ html: '
first line
second line
',
+ expectedLineAttribs: ['', '', '', '', '+a', '', '+b'],
+ expectedText: [ '', '', '', '', 'first line', '', 'second line']
+ },
+ multiLineParagraph:{
+ description: "A paragraph with multiple lines should not loose spaces when lines are combined",
+ html:`
+а б в г ґ д е є ж з и і ї й к л м н о
+п р с т у ф х ц ч ш щ ю я ь
+`,
+ expectedLineAttribs: [ '+1t' ],
+ expectedText: ["а б в г ґ д е є ж з и і ї й к л м н о п р с т у ф х ц ч ш щ ю я ь"]
+ },
+ multiLineParagraphWithPre:{
+ description: "lines in preformatted text should be kept intact",
+ html:`
+а б в г ґ д е є ж з и і ї й к л м н о
multiple
+lines
+in
+pre
+
п р с т у ф х ц ч ш щ ю я
+ь
+`,
+ expectedLineAttribs: [ '+11', '+8', '+5', '+2', '+3', '+r' ],
+ expectedText: ['а б в г ґ д е є ж з и і ї й к л м н о', 'multiple', 'lines', 'in', 'pre', 'п р с т у ф х ц ч ш щ ю я ь']
+ },
+ preIntroducesASpace: {
+ description: "pre should be on a new line not preceeded by a space",
+ html:`
+ 1
+
preline
+
`,
+ expectedLineAttribs: [ '+6', '+7' ],
+ expectedText: [' 1 ', 'preline']
+ },
+ dontDeleteSpaceInsideElements: {
+ description: 'Preserve spaces on the beginning and end of a element',
+ html: 'Need more space s !
',
+ expectedLineAttribs: ['+f*0+3+1'],
+ expectedText: ['Need more space s !']
+ },
+ dontDeleteSpaceOutsideElements: {
+ description: 'Preserve spaces outside elements',
+ html: 'Need more space s !
',
+ expectedLineAttribs: ['+g*0+1+2'],
+ expectedText: ['Need more space s !']
+ },
+ dontDeleteSpaceAtEndOfElement: {
+ description: 'Preserve spaces at the end of an element',
+ html: 'Need more space s !
',
+ expectedLineAttribs: ['+g*0+2+1'],
+ expectedText: ['Need more space s !']
+ },
+ dontDeleteSpaceAtBeginOfElements: {
+ description: 'Preserve spaces at the start of an element',
+ html: 'Need more space s !
',
+ expectedLineAttribs: ['+f*0+2+2'],
+ expectedText: ['Need more space s !']
+ },
};
describe(__filename, function () {