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 |
abcd
| x |
a
b
\nc
d
xe
'; 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 |
abcd
| x |