import { Assertions } from '@ephox/agar'; import { Element } from '@ephox/sugar'; import Nodes from 'tinymce/plugins/visualchars/core/Nodes'; import { UnitTest } from '@ephox/bedrock'; import { document } from '@ephox/dom-globals'; UnitTest.test('atomic.tinymce.plugins.visualchars.NodesTest', function () { const nbsp = '\u00a0'; const shy = '\u00AD'; const testReplaceWithSpans = function () { Assertions.assertHtml( 'should return span around shy and nbsp', 'a\u00a0b\u00AD', Nodes.replaceWithSpans('a' + nbsp + 'b' + shy) ); }; const testFilterDescendants = function () { const div = document.createElement('div'); div.innerHTML = '

a

' + '

b' + nbsp + '

' + '

c

' + '

d' + shy + '

'; Assertions.assertEq( 'should return list with nodes with shy or nbsp in it', 2, Nodes.filterDescendants(Element.fromDom(div), Nodes.isMatch).length ); }; const testFilterDescendants2 = function () { const div = document.createElement('div'); div.innerHTML = '

a' + nbsp + '

' + '

b' + nbsp + '

' + '

c' + nbsp + '

' + '

d' + shy + '

'; Assertions.assertEq( 'should return list with nodes with shy or nbsp in it', 4, Nodes.filterDescendants(Element.fromDom(div), Nodes.isMatch).length ); }; testReplaceWithSpans(); testFilterDescendants(); testFilterDescendants2(); });