import { describe, it } from '@ephox/bedrock-client'; import { assert } from 'chai'; import DOMUtils from 'tinymce/core/api/dom/DOMUtils'; import * as TrimNode from 'tinymce/core/dom/TrimNode'; describe('browser.tinymce.core.dom.TrimNodeTest', () => { const dom = DOMUtils(document, {}); const testTrim = (label: string, inputHtml: string, expectedTrimmedHtml: string) => { it(label, () => { const elm = document.createElement('div'); elm.innerHTML = inputHtml; TrimNode.trimNode(dom, elm.firstChild as Node); const actual = elm.innerHTML; assert.equal(actual, expectedTrimmedHtml, 'is correct trimmed html'); }); }; testTrim('Empty span should be removed', '
x
', 'x
'); testTrim('Non-empty span should not be removed', 'x
', 'x
'); testTrim('Nbsp between inline elements should not be removed', 'x x
', 'x x
'); testTrim('Bookmarks should not be removed 1', 'y
', 'y
'); testTrim('Bookmarks should not be removed 2', 'a b c
', 'a b c
'); testTrim('Trailing nbsp within inline element should not be removed', 'x
', 'x
'); testTrim('Anchor should not be removed', '', ''); testTrim('Bogus BR should not be removed', 'x y
', 'x y
'); testTrim('New line between inline elements should not be removed', 'x\ny', '
x\ny'); it('Fragmented text node', () => { const emptyTextNode = document.createTextNode(' '); const elm = document.createElement('div'); elm.innerHTML = 'abcabc'; elm.insertBefore(emptyTextNode, elm.lastChild); elm.insertBefore(emptyTextNode.cloneNode(), elm.firstChild); const actual = TrimNode.trimNode(dom, elm); assert.equal(actual.innerHTML, ' abc abc', 'Empty text node shouldn\'t be trimmed'); }); it('Document node', () => { const expected = document.implementation.createHTMLDocument('test'); const actual = TrimNode.trimNode(dom, expected); assert.strictEqual(actual, expected, 'Should return document as is'); }); });