import { Assertions } from '@ephox/agar'; import { context, describe, it } from '@ephox/bedrock-client'; import { Arr, Unicode } from '@ephox/katamari'; import { Html, SugarElement, SugarNode } from '@ephox/sugar'; import { assert } from 'chai'; import * as Nodes from 'tinymce/plugins/visualchars/core/Nodes'; describe('atomic.tinymce.plugins.visualchars.NodesTest', () => { context('replaceWithSpans', () => { it('replace with spans', () => { Assertions.assertHtml( 'should return span around shy and nbsp', 'a\u00a0b\u00AD', Nodes.replaceWithSpans('a' + Unicode.nbsp + 'b' + Unicode.softHyphen) ); }); }); context('filterDescendants', () => { it('should return list with nodes with shy or nbsp in it', () => { const div = document.createElement('div'); // 2 matches div.innerHTML = ( '
a
' + 'b' + Unicode.nbsp + '
' + 'c
' + 'd' + Unicode.softHyphen + '
' ); assert.equal(Nodes.filterEditableDescendants(SugarElement.fromDom(div), Nodes.isMatch, true).length, 2); // 4 matches div.innerHTML = ( 'a' + Unicode.nbsp + '
' + 'b' + Unicode.nbsp + '
' + 'c' + Unicode.nbsp + '
' + 'd' + Unicode.softHyphen + '
' ); assert.equal(Nodes.filterEditableDescendants(SugarElement.fromDom(div), Nodes.isMatch, true).length, 4); }); it('should only return editable nodes for initial editable state', () => { const innerHtml = ` editable 1 noneditable editable 2 editable 3 noneditable editable 4 editable 5 `; const div = SugarElement.fromHtml(`