import { GeneralSteps, Logger, Pipeline, Step } 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/EditorContent'; import Assertions from '@ephox/agar/lib/main/ts/ephox/agar/api/Assertions'; import Serializer from 'tinymce/core/api/html/Serializer'; import Node from 'tinymce/core/api/html/Node'; UnitTest.asynctest('browser.tinymce.core.EditorGetContentTreeTest', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; 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 = EditorContent.getContent(editor); Assertions.assertHtml('Should be expected 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

', EditorContent.getContent(editor)); EditorContent.setContent(editor, tree); Assertions.assertHtml('Should be expected tree html', '

tree

', EditorContent.getContent(editor)); }) ])), Logger.t('setContent tree filtered', GeneralSteps.sequence([ tinyApis.sSetContent('

tree

'), Step.sync(() => { EditorContent.setContent(editor, getFontTree()); Assertions.assertHtml('Should be expected filtered html', 'x', EditorContent.getContent(editor)); }) ])), Logger.t('setContent tree using public api', GeneralSteps.sequence([ tinyApis.sSetContent('

tree

'), Step.sync(() => { editor.setContent(getFontTree()); Assertions.assertHtml('Should be expected filtered html', 'x', EditorContent.getContent(editor)); }) ])), Logger.t('getContent empty editor depending on forced_root_block setting', GeneralSteps.sequence([ tinyApis.sSetSetting('forced_root_block', 'div'), tinyApis.sSetRawContent('


'), tinyApis.sAssertContent('

 

'), tinyApis.sSetRawContent('

'), tinyApis.sAssertContent(''), tinyApis.sSetSetting('forced_root_block', 'p') ])) ], onSuccess, onFailure); }, { skin_url: '/project/js/tinymce/skins/lightgray', inline: true }, success, failure); });