import { Pipeline } from '@ephox/agar'; import { LegacyUnit, TinyLoader } from '@ephox/mcagar'; import Theme from 'tinymce/themes/modern/Theme'; import { UnitTest } from '@ephox/bedrock'; UnitTest.asynctest('browser.tinymce.core.FormattingCommandsTest', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; const suite = LegacyUnit.createSuite(); Theme(); const ok = function (value, label?) { return LegacyUnit.equal(value, true, label); }; suite.test('Justify - multiple block elements selected - queryCommandState', function (editor) { editor.setContent( '
' + 'one
two
' ); LegacyUnit.setSelection(editor, '#a', 0, '#b', 3); LegacyUnit.equal(editor.queryCommandState('JustifyLeft'), false); ok(editor.queryCommandState('JustifyRight')); }); suite.test('Formatting commands (xhtmlTextStyles)', function (editor) { editor.focus(); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Bold'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Italic'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Underline'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Strikethrough'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('FontName', false, 'Arial'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('FontSize', false, '7'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('ForeColor', false, '#FF0000'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('HiliteColor', false, '#FF0000'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('testtest'); LegacyUnit.equal( editor.getContent(), '

testtest

' ); editor.setContent('

test 123

'); LegacyUnit.equal(editor.getContent(), '

test 123

'); }); suite.test('Formatting commands (alignInline)', function (editor) { editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('JustifyLeft'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('JustifyCenter'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('JustifyRight'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('JustifyFull'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent(''); editor.selection.select(editor.dom.select('img')[0]); editor.execCommand('JustifyLeft'); LegacyUnit.equal(editor.getContent(), '

'); editor.setContent(''); editor.selection.select(editor.dom.select('img')[0]); editor.execCommand('JustifyCenter'); LegacyUnit.equal( editor.getContent(), '

' ); editor.setContent(''); editor.selection.select(editor.dom.select('img')[0]); editor.execCommand('JustifyRight'); LegacyUnit.equal(editor.getContent(), '

'); }); suite.test('mceBlockQuote', function (editor) { editor.focus(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('mceBlockQuote'); LegacyUnit.equal(editor.getContent().replace(/\s+/g, ''), '

test123

'); editor.setContent('

test 123

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('mceBlockQuote'); LegacyUnit.equal(editor.getContent().replace(/\s+/g, ''), '

test123

test123

'); }); suite.test('FormatBlock', function (editor) { editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h1'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h2'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h3'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h4'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h5'); LegacyUnit.equal(editor.getContent(), '
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h6'); LegacyUnit.equal(editor.getContent(), '
test 123
'); editor.execCommand('SelectAll'); try { editor.execCommand('FormatBlock', false, 'div'); } catch (ex) { // t.log('Failed: ' + ex.message); } LegacyUnit.equal(editor.getContent(), '
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'address'); LegacyUnit.equal(editor.getContent(), '
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'pre'); LegacyUnit.equal(editor.getContent(), '
test 123
'); }); suite.test('mceInsertLink (relative)', function (editor) { editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'test'); LegacyUnit.equal(editor.getContent(), '

test 123

'); }); suite.test('mceInsertLink (link absolute)', function (editor) { editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'http://www.site.com'); LegacyUnit.equal(editor.getContent(), '

test 123

'); }); suite.test('mceInsertLink (link encoded)', function (editor) { editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, '"&<>'); LegacyUnit.equal(editor.getContent(), '

test 123

'); }); suite.test('mceInsertLink (link encoded and with class)', function (editor) { editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, { href: '"&<>', class: 'test' }); LegacyUnit.equal(editor.getContent(), '

test 123

'); }); suite.test('mceInsertLink (link with space)', function (editor) { editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, { href: 'foo bar' }); LegacyUnit.equal(editor.getContent(), '

test 123

'); }); suite.test('mceInsertLink (link floated img)', function (editor) { editor.setContent('

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); LegacyUnit.equal(editor.getContent(), '

'); }); suite.test('mceInsertLink (link adjacent text)', function (editor) { let rng; editor.setContent('

ab

'); rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild.lastChild, 0); rng.setEnd(editor.getBody().firstChild.lastChild, 1); editor.selection.setRng(rng); editor.execCommand('mceInsertLink', false, 'link'); LegacyUnit.equal(editor.getContent(), '

ab

'); }); suite.test('mceInsertLink (link text inside text)', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'em', 1, 'em', 2); editor.execCommand('mceInsertLink', false, 'link'); LegacyUnit.equal(editor.getContent(), '

abc

'); }); suite.test('mceInsertLink (link around existing links)', function (editor) { editor.setContent('

12

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); LegacyUnit.equal(editor.getContent(), '

12

'); }); suite.test('mceInsertLink (link around existing links with different attrs)', function (editor) { editor.setContent('

12

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); LegacyUnit.equal(editor.getContent(), '

12

'); }); suite.test('mceInsertLink (link around existing complex contents with links)', function (editor) { editor.setContent( '

1' + '2

' ); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); LegacyUnit.equal( editor.getContent(), '

1' + '2

' ); }); suite.test('mceInsertLink (link text inside link)', function (editor) { editor.setContent('

test

'); LegacyUnit.setSelection(editor, 'p', 0, 'p', 1); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); LegacyUnit.equal(editor.getContent(), '

test

'); }); suite.test('mceInsertLink bug #7331', function (editor) { editor.setContent('
A
B
'); const rng = editor.dom.createRng(); rng.setStart(editor.$('td')[1].firstChild, 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.execCommand('mceInsertLink', false, { href: 'x' }); LegacyUnit.equal(editor.getContent(), '
A
B
'); }); suite.test('unlink', function (editor) { editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('unlink'); LegacyUnit.equal(editor.getContent(), '

test 123

'); }); suite.test('unlink - unselected a[href] with childNodes', function (editor) { editor.setContent('

test

'); LegacyUnit.setSelection(editor, 'em', 0); editor.execCommand('unlink'); LegacyUnit.equal(editor.getContent(), '

test

'); }); suite.test('subscript/superscript', function (editor) { editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('subscript'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('superscript'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('subscript'); editor.execCommand('subscript'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('superscript'); editor.execCommand('superscript'); LegacyUnit.equal(editor.getContent(), '

test 123

'); }); suite.test('indent/outdent', function (editor) { editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); editor.execCommand('Outdent'); LegacyUnit.equal(editor.getContent(), '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('Outdent'); LegacyUnit.equal(editor.getContent(), '

test 123

'); }); suite.test('indent/outdent table always uses margin', function (editor) { editor.setContent('
test
'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); LegacyUnit.equal(editor.getContent(), '
test
'); editor.setContent('
test
'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); LegacyUnit.equal(editor.getContent(), '
test
'); editor.setContent('
test
'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); editor.execCommand('Outdent'); LegacyUnit.equal(editor.getContent(), '
test
'); editor.setContent('
test
'); editor.execCommand('SelectAll'); editor.execCommand('Outdent'); LegacyUnit.equal(editor.getContent(), '
test
'); }); suite.test('RemoveFormat', function (editor) { editor.setContent('

test 123 123 123

'); editor.execCommand('SelectAll'); editor.execCommand('RemoveFormat'); LegacyUnit.equal(editor.getContent(), '

test 123 123 123

'); editor.setContent('

test 123 123 123

'); editor.execCommand('SelectAll'); editor.execCommand('RemoveFormat'); LegacyUnit.equal(editor.getContent(), '

test 123 123 123

'); editor.setContent('

testtest 123123 123

'); editor.selection.select(editor.dom.get('x')); editor.execCommand('RemoveFormat'); LegacyUnit.equal(editor.getContent(), '

testtest 123123 123

'); editor.setContent( '

dfn tag code tag samp tag ' + ' kbd tag var tag cite tag mark tag q tag

' ); editor.execCommand('SelectAll'); editor.execCommand('RemoveFormat'); LegacyUnit.equal(editor.getContent(), '

dfn tag code tag samp tag kbd tag var tag cite tag mark tag q tag

'); }); TinyLoader.setup(function (editor, onSuccess, onFailure) { Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure); }, { add_unload_trigger: false, disable_nodechange: true, indent: false, entities: 'raw', convert_urls: false, valid_styles: { '*': 'color,font-size,font-family,background-color,font-weight,font-style,text-decoration,' + 'float,margin,margin-top,margin-right,margin-bottom,margin-left,padding-left,text-align,display' }, skin_url: '/project/js/tinymce/skins/lightgray' }, success, failure); });