import { GeneralSteps, Logger, Pipeline, Step, Assertions } from '@ephox/agar'; import { TinyApis, TinyLoader } from '@ephox/mcagar'; import Theme from 'tinymce/themes/modern/Theme'; import { UnitTest } from '@ephox/bedrock'; import * as EditorContent from 'tinymce/core/content/EditorContent'; import Serializer from 'tinymce/core/api/html/Serializer'; import Node from 'tinymce/core/api/html/Node'; UnitTest.asynctest('browser.tinymce.core.content.EditorGetContentTreeTest', (success, failure) => { const getFontTree = () => { const body = new Node('body', 1); const font = new Node('font', 1); const text = new Node('#text', 3); text.value = 'x'; font.attr('size', '7'); font.append(text); body.append(font); return body; }; Theme(); const toHtml = (node: Node) => { const htmlSerializer = Serializer({}); return htmlSerializer.serialize(node); }; TinyLoader.setup(function (editor, onSuccess, onFailure) { const tinyApis = TinyApis(editor); Pipeline.async({}, [ Logger.t('getContent html', GeneralSteps.sequence([ tinyApis.sSetContent('
html
'), Step.sync(() => { const html =html
', html); }) ])), Logger.t('getContent tree', GeneralSteps.sequence([ tinyApis.sSetContent('tree
'), Step.sync(() => { const tree = EditorContent.getContent(editor, { format: 'tree' }) as Node; Assertions.assertHtml('Should be expected tree html', 'tree
', toHtml(tree)); }) ])), Logger.t('getContent tree filtered', GeneralSteps.sequence([ Step.sync(() => { EditorContent.setContent(editor, 'x
', { format: 'raw' }); const tree = EditorContent.getContent(editor, { format: 'tree' }) as Node; Assertions.assertHtml('Should be expected tree filtered html', 'x
', toHtml(tree)); }) ])), Logger.t('getContent tree using public api', GeneralSteps.sequence([ tinyApis.sSetContent('html
'), Step.sync(() => { const tree = editor.getContent({ format: 'tree'}) as Node; Assertions.assertHtml('Should be expected filtered html', 'html
', toHtml(tree)); }) ])), Logger.t('setContent html', GeneralSteps.sequence([ tinyApis.sSetContent('html
'), Step.sync(function () { EditorContent.setContent(editor, 'new html
'); }), tinyApis.sAssertContent('new html
') ])), Logger.t('setContent tree', GeneralSteps.sequence([ tinyApis.sSetContent('tree
'), Step.sync(() => { const tree = EditorContent.getContent(editor, { format: 'tree' }) as Node; Assertions.assertHtml('Should be expected tree html', 'tree
', toHtml(tree)); EditorContent.setContent(editor, 'new html
'); Assertions.assertHtml('Should be expected html', 'new html
',tree
',tree
'), Step.sync(() => { EditorContent.setContent(editor, getFontTree()); Assertions.assertHtml('Should be expected filtered html', 'x',tree
'), Step.sync(() => { editor.setContent(getFontTree()); Assertions.assertHtml('Should be expected filtered html', 'x','), tinyApis.sSetRawContent('