import { context, describe, it } from '@ephox/bedrock-client'; import { LegacyUnit, TinyAssertions, TinyHooks } from '@ephox/wrap-mcagar'; import { assert } from 'chai'; import Editor from 'tinymce/core/api/Editor'; describe('browser.tinymce.core.FormattingCommandsTest', () => { const hook = TinyHooks.bddSetupLight({ 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' }, base_url: '/project/tinymce/js/tinymce' }, []); it('Justify - multiple block elements selected - queryCommandState', () => { const editor = hook.editor(); editor.setContent( '
' + 'one
two
' ); LegacyUnit.setSelection(editor, '#a', 0, '#b', 3); assert.isFalse(editor.queryCommandState('JustifyLeft')); assert.ok(editor.queryCommandState('JustifyRight')); }); it('Formatting commands (xhtmlTextStyles)', () => { const editor = hook.editor(); editor.focus(); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Bold'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Italic'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Underline'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Strikethrough'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('FontName', false, 'Arial'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('FontName', false, 'Bauhaus 93'); TinyAssertions.assertContent(editor, `

test 123

`); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('FontSize', false, '7'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('FontSize', false, '7pt'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('ForeColor', false, '#FF0000'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('HiliteColor', false, '#FF0000'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('BackColor', false, '#FF0000'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('testtest'); TinyAssertions.assertContent( editor, '

testtest

' ); editor.setContent('

test 123

'); TinyAssertions.assertContent(editor, '

test 123

'); }); context('Formatting commands (alignInline)', () => { it('TBA - p, JustifyLeft', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('JustifyLeft'); TinyAssertions.assertContent(editor, '

test 123

'); assert.isTrue(editor.queryCommandState('JustifyLeft'), 'should have JustifyLeft state true'); }); it('TBA - p, JustifyCenter', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('JustifyCenter'); TinyAssertions.assertContent(editor, '

test 123

'); assert.isTrue(editor.queryCommandState('JustifyCenter'), 'should have JustifyCenter state true'); }); it('TBA - p, JustifyRight', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('JustifyRight'); TinyAssertions.assertContent(editor, '

test 123

'); assert.isTrue(editor.queryCommandState('JustifyRight'), 'should have JustifyRight state true'); }); it('TBA - p, JustifyFull', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('JustifyFull'); TinyAssertions.assertContent(editor, '

test 123

'); assert.isTrue(editor.queryCommandState('JustifyFull'), 'should have JustifyFull state true'); }); it('TINY-7715 - pre, JustifyLeft', () => { const editor = hook.editor(); editor.setContent('
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('JustifyLeft'); TinyAssertions.assertContent(editor, '
test 123
'); assert.isTrue(editor.queryCommandState('JustifyLeft'), 'should have JustifyLeft state true'); }); it('TINY-7715 - pre, JustifyCenter', () => { const editor = hook.editor(); editor.setContent('
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('JustifyCenter'); TinyAssertions.assertContent(editor, '
test 123
'); assert.isTrue(editor.queryCommandState('JustifyCenter'), 'should have JustifyCenter state true'); }); it('TINY-7715 - pre, JustifyRight', () => { const editor = hook.editor(); editor.setContent('
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('JustifyRight'); TinyAssertions.assertContent(editor, '
test 123
'); assert.isTrue(editor.queryCommandState('JustifyRight'), 'should have JustifyRight state true'); }); it('TINY-7715 - pre, JustifyFull', () => { const editor = hook.editor(); editor.setContent('
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('JustifyFull'); TinyAssertions.assertContent(editor, '
test 123
'); assert.isTrue(editor.queryCommandState('JustifyFull'), 'should have JustifyFull state true'); }); it('TBA - img, JustifyLeft', () => { const editor = hook.editor(); editor.setContent(''); editor.selection.select(editor.dom.select('img')[0]); editor.execCommand('JustifyLeft'); TinyAssertions.assertContent(editor, '

'); }); it('TBA - img, JustifyCenter', () => { const editor = hook.editor(); editor.setContent(''); editor.selection.select(editor.dom.select('img')[0]); editor.execCommand('JustifyCenter'); TinyAssertions.assertContent( editor, '

' ); }); it('TBA - img, JustifyRight', () => { const editor = hook.editor(); editor.setContent(''); editor.selection.select(editor.dom.select('img')[0]); editor.execCommand('JustifyRight'); TinyAssertions.assertContent(editor, '

'); }); }); it('mceBlockQuote', () => { const editor = hook.editor(); editor.focus(); editor.setContent('

test 123

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

test123

'); editor.setContent('

test 123

test 123

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

test123

test123

'); }); it('FormatBlock', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h1'); TinyAssertions.assertContent(editor, '

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h2'); TinyAssertions.assertContent(editor, '

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h3'); TinyAssertions.assertContent(editor, '

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h4'); TinyAssertions.assertContent(editor, '

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h5'); TinyAssertions.assertContent(editor, '
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h6'); TinyAssertions.assertContent(editor, '
test 123
'); editor.execCommand('SelectAll'); try { editor.execCommand('FormatBlock', false, 'div'); } catch (ex) { // t.log('Failed: ' + ex.message); } TinyAssertions.assertContent(editor, '
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'address'); TinyAssertions.assertContent(editor, '
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'pre'); TinyAssertions.assertContent(editor, '
test 123
'); }); it('createLink', () => { const editor = hook.editor(); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('createLink', false, 'http://www.site.com'); TinyAssertions.assertContent(editor, '

test 123

'); }); it('mceInsertLink (relative)', () => { const editor = hook.editor(); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'test'); TinyAssertions.assertContent(editor, '

test 123

'); }); it('mceInsertLink (link absolute)', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'http://www.site.com'); TinyAssertions.assertContent(editor, '

test 123

'); }); it('mceInsertLink (link encoded)', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, '"&<>'); TinyAssertions.assertContent(editor, '

test 123

'); }); it('mceInsertLink (link encoded and with class)', () => { const editor = hook.editor(); editor.setContent('

test 123

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

test 123

'); }); it('mceInsertLink (link with space)', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, { href: 'foo bar' }); TinyAssertions.assertContent(editor, '

test 123

'); }); it('mceInsertLink (link floated img)', () => { const editor = hook.editor(); editor.setContent('

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); TinyAssertions.assertContent(editor, '

'); }); it('mceInsertLink (link adjacent text)', () => { const editor = hook.editor(); editor.setContent('

ab

'); const rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild?.lastChild as Text, 0); rng.setEnd(editor.getBody().firstChild?.lastChild as Text, 1); editor.selection.setRng(rng); editor.execCommand('mceInsertLink', false, 'link'); TinyAssertions.assertContent(editor, '

ab

'); }); it('mceInsertLink (link text inside text)', () => { const editor = hook.editor(); editor.setContent('

abc

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

abc

'); }); it('mceInsertLink (link around existing links)', () => { const editor = hook.editor(); editor.setContent('

12

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); TinyAssertions.assertContent(editor, '

12

'); }); it('mceInsertLink (link around existing links with different attrs)', () => { const editor = hook.editor(); editor.setContent('

12

'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); TinyAssertions.assertContent(editor, '

12

'); }); it('mceInsertLink (link around existing complex contents with links)', () => { const editor = hook.editor(); editor.setContent( '

1' + '2

' ); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); TinyAssertions.assertContent( editor, '

1' + '2

' ); }); it('mceInsertLink (link text inside link)', () => { const editor = hook.editor(); editor.setContent('

test

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

test

'); }); it('mceInsertLink bug #7331', () => { const editor = hook.editor(); editor.setContent('
A
B
'); const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('td')[1].firstChild as Text, 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.execCommand('mceInsertLink', false, { href: 'x' }); TinyAssertions.assertContent(editor, '
A
B
'); }); it('unlink', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('unlink'); TinyAssertions.assertContent(editor, '

test 123

'); }); it('unlink - unselected a[href] with childNodes', () => { const editor = hook.editor(); editor.setContent('

test

'); LegacyUnit.setSelection(editor, 'em', 0); editor.execCommand('unlink'); TinyAssertions.assertContent(editor, '

test

'); }); it('TINY-9172: unlink block links', () => { const editor = hook.editor(); editor.setContent('test

test

'); editor.execCommand('SelectAll'); editor.execCommand('unlink'); TinyAssertions.assertContent(editor, '

test

test

'); }); it('subscript/superscript', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('subscript'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('superscript'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('subscript'); editor.execCommand('subscript'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('superscript'); editor.execCommand('superscript'); TinyAssertions.assertContent(editor, '

test 123

'); }); it('indent/outdent', () => { const editor = hook.editor(); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); editor.execCommand('Outdent'); TinyAssertions.assertContent(editor, '

test 123

'); editor.setContent('

test 123

'); editor.execCommand('SelectAll'); editor.execCommand('Outdent'); TinyAssertions.assertContent(editor, '

test 123

'); }); it('indent/outdent table always uses margin', () => { const editor = hook.editor(); editor.setContent('
test
'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
test
'); editor.setContent('
test
'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); TinyAssertions.assertContent(editor, '
test
'); editor.setContent('
test
'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); editor.execCommand('Outdent'); TinyAssertions.assertContent(editor, '
test
'); editor.setContent('
test
'); editor.execCommand('SelectAll'); editor.execCommand('Outdent'); TinyAssertions.assertContent(editor, '
test
'); }); it('RemoveFormat', () => { const editor = hook.editor(); editor.setContent('

test 123 123 123

'); editor.execCommand('SelectAll'); editor.execCommand('RemoveFormat'); TinyAssertions.assertContent(editor, '

test 123 123 123

'); editor.setContent('

test 123 123 123

'); editor.execCommand('SelectAll'); editor.execCommand('RemoveFormat'); TinyAssertions.assertContent(editor, '

test 123 123 123

'); editor.setContent('

testtest 123123 123

'); editor.selection.select(editor.dom.get('x') as HTMLSpanElement); editor.execCommand('RemoveFormat'); TinyAssertions.assertContent(editor, '

testtest 123123 123

'); editor.setContent( '

dfn tag code tag samp tag ' + ' kbd tag var tag cite tag mark tag q tag ' + 'strike tag s tag small tag

' ); editor.execCommand('SelectAll'); editor.execCommand('RemoveFormat'); TinyAssertions.assertContent(editor, '

dfn tag code tag samp tag kbd tag var tag cite tag mark tag q tag strike tag s tag small tag

'); }); });