import { Pipeline } from '@ephox/agar'; import { LegacyUnit, TinyLoader } from '@ephox/mcagar'; import HtmlUtils from '../module/test/HtmlUtils'; import Theme from 'tinymce/themes/modern/Theme'; import { UnitTest } from '@ephox/bedrock'; UnitTest.asynctest('browser.tinymce.core.ForceBlocksTest', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; const suite = LegacyUnit.createSuite(); Theme(); const pressArrowKey = function (editor) { const dom = editor.dom, target = editor.selection.getNode(); const evt = { keyCode: 37 }; dom.fire(target, 'keydown', evt); dom.fire(target, 'keypress', evt); dom.fire(target, 'keyup', evt); }; suite.test('Wrap single root text node in P', function (editor) { editor.focus(); editor.getBody().innerHTML = 'abcd'; LegacyUnit.setSelection(editor, 'body', 2); pressArrowKey(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '

abcd

'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'P'); }); suite.test('Wrap single root text node in P with attrs', function (editor) { editor.settings.forced_root_block_attrs = { class: 'class1' }; editor.getBody().innerHTML = 'abcd'; LegacyUnit.setSelection(editor, 'body', 2); pressArrowKey(editor); LegacyUnit.equal(editor.getContent(), '

abcd

'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'P'); delete editor.settings.forced_root_block_attrs; }); suite.test('Wrap single root text node in P but not table sibling', function (editor) { editor.getBody().innerHTML = 'abcd
x
'; LegacyUnit.setSelection(editor, 'body', 2); pressArrowKey(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '

abcd

x
'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'P'); }); suite.test('Textnodes with only whitespace should not be wrapped new paragraph', (editor) => { editor.getBody().innerHTML = '

a

b

\n

c

 

d

x

e

'; LegacyUnit.setSelection(editor, 'p', 0); pressArrowKey(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getContent()), '

a

b

c

d

x

e

'); }); suite.test('Do not wrap whitespace textnodes between inline elements', (editor) => { editor.getBody().innerHTML = 'a b c'; LegacyUnit.setSelection(editor, 'strong', 0); pressArrowKey(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getContent()), '

a b c

'); }); suite.test('Wrap root em in P but not table sibling', function (editor) { editor.getBody().innerHTML = 'abcd
x
'; LegacyUnit.setSelection(editor, 'em', 2); pressArrowKey(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '

abcd

x
'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'EM'); }); suite.test('Wrap single root text node in DIV', function (editor) { editor.settings.forced_root_block = 'div'; editor.getBody().innerHTML = 'abcd'; LegacyUnit.setSelection(editor, 'body', 2); pressArrowKey(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '
abcd
'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'DIV'); delete editor.settings.forced_root_block; }); suite.test('Remove empty root text nodes', function (editor) { const body = editor.getBody(); editor.settings.forced_root_block = 'div'; editor.getBody().innerHTML = 'abcd
abcd
'; body.insertBefore(editor.getDoc().createTextNode(''), body.firstChild); body.appendChild(editor.getDoc().createTextNode('')); const rng = editor.dom.createRng(); rng.setStart(editor.getBody().childNodes[1], 1); rng.setEnd(editor.getBody().childNodes[1], 1); editor.selection.setRng(rng); pressArrowKey(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(body.innerHTML), '
abcd
abcd
'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'DIV'); LegacyUnit.equal(body.childNodes.length, 2); }); suite.test('Wrap single root text node in P but not table sibling', function (editor) { editor.getBody().innerHTML = 'a'; LegacyUnit.setSelection(editor, 'body', 0); pressArrowKey(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), 'a'); }); TinyLoader.setup(function (editor, onSuccess, onFailure) { Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure); }, { entities: 'raw', indent: false, skin_url: '/project/js/tinymce/skins/lightgray' }, success, failure); });