import { Assert, UnitTest } from '@ephox/bedrock-client'; import { Arr, Fun } from '@ephox/katamari'; import { Attribute, Html, Insert, InsertAll, Remove, SugarElement } from '@ephox/sugar'; import * as DomSearch from 'ephox/phoenix/api/dom/DomSearch'; import * as DomWrapping from 'ephox/phoenix/api/dom/DomWrapping'; UnitTest.test('DomSearchTest', () => { const body = SugarElement.fromDom(document.body); const container = SugarElement.fromTag('div'); Insert.append(body, container); const check = (expected: string, rawTexts: string[], words: string[]) => { const elements = Arr.map(rawTexts, (x) => { return SugarElement.fromText(x); }); Remove.empty(container); InsertAll.append(container, elements); const snapshots = DomSearch.safeWords(elements, words, Fun.never); Arr.each(snapshots, (x) => { DomWrapping.wrapper(x.elements, () => { const span = SugarElement.fromTag('span'); Attribute.set(span, 'data-word', x.word); return DomWrapping.nu(span); }); }); Assert.eq('', expected, Html.get(container)); }; check('Sed', [ 'Sed' ], [ 'Sed' ]); check('Sed ut perspiciatis unde' + ' omnis iste natus error sit voluptatem', [ 'Sed', ' ut per', 'spiciatis u', 'nde om', 'ni', 's iste', ' natus', ' error', ' sit voluptatem' ], [ 'Sed', 'iste', 'unde', 'sit' ]); check('Sed ut per', [ 'Sed', ' ut per' ], [ 'Sed', 'ut' ]); Remove.remove(container); });