import { Assertions, Pipeline } from '@ephox/agar'; import { Obj } from '@ephox/katamari'; import { LegacyUnit, TinyLoader } from '@ephox/mcagar'; import HtmlUtils from '../module/test/HtmlUtils'; import KeyUtils from '../module/test/KeyUtils'; import Theme from 'tinymce/themes/modern/Theme'; import { UnitTest } from '@ephox/bedrock'; UnitTest.asynctest('browser.tinymce.core.FormatterApplyTest', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; const suite = LegacyUnit.createSuite(); Theme(); const getContent = function (editor) { return editor.getContent().toLowerCase().replace(/[\r]+/g, ''); }; suite.test('apply inline to a list', function (editor) { editor.focus(); editor.formatter.register('format', { inline: 'b', toggle: false }); editor.getBody().innerHTML = '
1234
5678
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[1].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '1234
5678
', 'selection of a list' ); }); suite.test('Toggle OFF - Inline element on selected text', function (editor) { // Toggle OFF - Inline element on selected text editor.formatter.register('format', { inline: 'b', toggle: false }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('b')[0].firstChild, 0); rng.setEnd(editor.dom.select('b')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.toggle('format'); LegacyUnit.equal(getContent(editor), '1234
'); }); suite.test('Toggle OFF - Inline element on partially selected text', function (editor) { // Toggle OFF - Inline element on partially selected text editor.formatter.register('format', { inline: 'b', toggle: 0 }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('b')[0].firstChild, 0); rng.setEnd(editor.dom.select('b')[0].firstChild, 2); editor.selection.setRng(rng); editor.formatter.toggle('format'); LegacyUnit.equal(getContent(editor), '1234
'); }); suite.test('Toggle OFF - Inline element on partially selected text in start/end elements', function (editor) { // Toggle OFF - Inline element on partially selected text in start/end elements editor.formatter.register('format', { inline: 'b', toggle: false }); editor.getBody().innerHTML = '1234
1234
'; // '1234
1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('b')[0].firstChild, 0); rng.setEnd(editor.dom.select('b')[1].firstChild, 3); editor.selection.setRng(rng); editor.formatter.toggle('format'); LegacyUnit.equal(getContent(editor), '1234
1234
'); }); suite.test('Toggle OFF - Inline element with data attribute', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '1
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('b')[0].firstChild, 0); rng.setEnd(editor.dom.select('b')[0].firstChild, 1); editor.selection.setRng(rng); editor.formatter.toggle('format'); LegacyUnit.equal(getContent(editor), '1
'); }); suite.test('Toggle ON - NO inline element on selected text', function (editor) { // Inline element on selected text editor.formatter.register('format', { inline: 'b', toggle: true }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element on selected text'); editor.formatter.toggle('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Toggle ON - NO inline element on selected text'); }); suite.test('Selection spanning from within format to outside format with toggle off', function (editor) { editor.formatter.register('format', { inline: 'b', toggle: false }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('b')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].lastChild, 2); editor.selection.setRng(rng); editor.formatter.toggle('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Extend formating if start of selection is already formatted'); }); suite.test('Inline element on partially selected text', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 1); rng.setEnd(editor.dom.select('p')[0].firstChild, 3); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element on partially selected text'); editor.formatter.toggle('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Toggle ON - NO inline element on partially selected text'); }); suite.test('Inline element on partially selected text in start/end elements', function (editor) { // Inline element on partially selected text in start/end elements editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '1234
1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 1); rng.setEnd(editor.dom.select('p')[1].firstChild, 3); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
1234
'); }); suite.test('Inline element on selected element', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element on selected element'); }); suite.test('Inline element on multiple selected elements', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '1234
1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 2); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
1234
', 'Inline element on multiple selected elements'); }); suite.test('Inline element on multiple selected elements with various childnodes', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '123456789
123456789
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 2); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '123456789
123456789
', 'Inline element on multiple selected elements with various childnodes' ); }); suite.test('Inline element with attributes', function (editor) { editor.formatter.register('format', { inline: 'b', attributes: { title: 'value1', id: 'value2' } }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element with attributes'); }); suite.test('Inline element with styles', function (editor) { editor.formatter.register('format', { inline: 'b', styles: { color: '#ff0000', fontSize: '10px' } }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element with styles'); }); suite.test('Inline element with attributes and styles', function (editor) { editor.formatter.register('format', { inline: 'b', attributes: { title: 'value1', id: 'value2' }, styles: { color: '#ff0000', fontSize: '10px' } }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '1234
', 'Inline element with attributes and styles' ); }); suite.test('Inline element with wrapable parents', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = 'x1234y
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('span')[0].firstChild, 0); rng.setEnd(editor.dom.select('span')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'x1234y
', 'Inline element with wrapable parents'); }); suite.test('Inline element with redundant child', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0], 0); rng.setEnd(editor.dom.select('p')[0], 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element with redundant child'); }); suite.test('Inline element with redundant parent', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = 'a1234b
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('em')[0].firstChild, 0); rng.setEnd(editor.dom.select('em')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a1234b
', 'Inline element with redundant parent'); }); suite.test('Inline element with redundant child of similar type 1', function (editor) { editor.formatter.register('format', [{ inline: 'b' }, { inline: 'strong' }]); editor.getBody().innerHTML = 'a1234b
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0], 0); rng.setEnd(editor.dom.select('p')[0], 3); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a1234b
', 'Inline element with redundant child of similar type 1'); }); suite.test('Inline element with redundant child of similar type 2', function (editor) { editor.formatter.register('format', [{ inline: 'b' }, { inline: 'span', styles: { fontWeight: 'bold' } }]); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0], 0); rng.setEnd(editor.dom.select('p')[0], 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element with redundant child of similar type 2'); }); suite.test('Inline element with redundant children of similar types', function (editor) { editor.formatter.register('format', [{ inline: 'b' }, { inline: 'strong' }, { inline: 'span', styles: { fontWeight: 'bold' } }]); editor.getBody().innerHTML = 'a12345678b
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0], 0); rng.setEnd(editor.dom.select('p')[0], 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a12345678b
', 'Inline element with redundant children of similar types'); }); suite.test('Inline element with redundant parent 1', function (editor) { editor.formatter.register('format', [{ inline: 'b' }, { inline: 'strong' }]); editor.getBody().innerHTML = 'a1234b
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('em')[0].firstChild, 0); rng.setEnd(editor.dom.select('em')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a1234b
', 'Inline element with redundant parent 1'); }); suite.test('Inline element with redundant parent 2', function (editor) { editor.formatter.register('format', [{ inline: 'b' }, { inline: 'span', styles: { fontWeight: 'bold' } }]); editor.getBody().innerHTML = 'a1234b
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('em')[0].firstChild, 0); rng.setEnd(editor.dom.select('em')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a1234b
', 'Inline element with redundant parent 2'); }); suite.test('Inline element with redundant parents of similar types', function (editor) { editor.formatter.register('format', [{ inline: 'b' }, { inline: 'strong' }, { inline: 'span', styles: { fontWeight: 'bold' } }]); editor.getBody().innerHTML = 'a1234b
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('em')[0].firstChild, 0); rng.setEnd(editor.dom.select('em')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), 'a1234b
', 'Inline element with redundant parents of similar types' ); }); suite.test('Inline element merged with parent and child', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = 'a123456b
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('b')[0].firstChild, 1); rng.setEnd(editor.dom.select('b')[0].lastChild, 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a123456b
', 'Inline element merged with parent and child'); }); suite.test('Inline element merged with child 1', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { fontWeight: 'bold' } }); editor.getBody().innerHTML = 'a1234b
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a1234b
', 'Inline element merged with child 1'); }); suite.test('Inline element merged with child 2', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { fontWeight: 'bold' } }); editor.getBody().innerHTML = 'a1234b
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), 'a1234b
', 'Inline element merged with child 2' ); }); suite.test('Inline element merged with child 3', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { fontWeight: 'bold' } }); editor.getBody().innerHTML = 'a1234b
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), 'a1234b
', 'Inline element merged with child 3' ); }); suite.test('Inline element merged with child 3', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { fontWeight: 'bold' }, merge: true }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element merged with child 3'); }); suite.test('Inline element merged with child 4', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { color: '#00ff00' } }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element merged with child 4'); }); suite.test('Inline element with attributes merged with child 1', function (editor) { editor.formatter.register('format', { inline: 'font', attributes: { face: 'arial' }, merge: true }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element with attributes merged with child 1'); }); suite.test('Inline element with attributes merged with child 2', function (editor) { editor.formatter.register('format', { inline: 'font', attributes: { size: '7' } }); editor.getBody().innerHTML = 'a1234b
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a1234b
', 'Inline element with attributes merged with child 2'); }); suite.test('Inline element merged with left sibling', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '12345678
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].lastChild, 0); rng.setEnd(editor.dom.select('p')[0].lastChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '12345678
', 'Inline element merged with left sibling'); }); suite.test('Inline element merged with right sibling', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '12345678
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '12345678
', 'Inline element merged with right sibling'); }); suite.test('Inline element merged with left and right siblings', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '123456
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].childNodes[1], 0); rng.setEnd(editor.dom.select('p')[0].childNodes[1], 2); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '123456
', 'Inline element merged with left and right siblings'); }); suite.test('Inline element merged with data attributed left sibling', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '12345678
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].lastChild, 0); rng.setEnd(editor.dom.select('p')[0].lastChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '12345678
', 'Inline element merged with left sibling'); }); suite.test('Don\'t merge siblings with whitespace between 1', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = 'a b
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].lastChild, 1); rng.setEnd(editor.dom.select('p')[0].lastChild, 2); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a b
', 'Don\'t merge siblings with whitespace between 1'); }); suite.test('Don\'t merge siblings with whitespace between 1', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = 'a b
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a b
', 'Don\'t merge siblings with whitespace between 2'); }); suite.test('Inline element not merged in exact mode', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { color: '#00ff00' }, exact: true }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '1234
', 'Inline element not merged in exact mode' ); }); suite.test('Inline element merged in exact mode', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { color: '#ff0000' }, exact: true }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element merged in exact mode'); }); suite.test('Deep left branch', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '1234text1text2
5678
9012
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('ins')[0].firstChild, 1); rng.setEnd(editor.dom.select('p')[2].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '1234text1text2
5678
9012
', 'Deep left branch' ); }); suite.test('Deep right branch', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '9012
5678
1234text1text2
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('em')[3].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '9012
5678
1234text1text2
', 'Deep right branch' ); }); suite.test('Full element text selection on two elements with a table in the middle', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.getBody().innerHTML = '1234
| 123 |
5678
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[1].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '1234
| 123 |
5678
', 'Full element text selection on two elements with a table in the middle' ); }); suite.test('Inline element on selected text with variables', function (editor) { editor.formatter.register('format', { inline: 'b', styles: { color: '%color' }, attributes: { title: '%title' } }, { color: '#ff0000', title: 'title' }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format', { color: '#ff0000', title: 'title' }); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element on selected text'); }); suite.test('Remove redundant children', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { fontFamily: 'arial' } }); editor.getBody().innerHTML = ( '1234
' ); const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0], 0); rng.setEnd(editor.dom.select('p')[0], 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
', 'Remove redundant children'); }); suite.test('Inline element on selected text with function values', function (editor) { editor.formatter.register('format', { inline: 'b', styles: { color (vars) { return vars.color + '00ff'; } }, attributes: { title (vars) { return vars.title + '2'; } } }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format', { color: '#ff', title: 'title' }); LegacyUnit.equal(getContent(editor), '1234
', 'Inline element on selected text with function values'); }); suite.test('Block element on selected text', function (editor) { editor.formatter.register('format', { block: 'div' }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 1); rng.setEnd(editor.dom.select('p')[0].firstChild, 3); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
5678
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 2); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
5678
'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 2); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '1234
5678
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('h1')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '', 'Block element wrapper 1'); }); suite.test('Block element wrapper 2', function (editor) { editor.formatter.register('format', { block: 'blockquote', wrapper: 1 }); editor.getBody().innerHTML = '1234
5678
', 'Block element wrapper 2'); }); suite.test('Block element wrapper 3', function (editor) { editor.formatter.register('format', { block: 'blockquote', wrapper: 1 }); editor.getBody().innerHTML = '1234
', 'Block element wrapper 3'); }); suite.test('Apply format on single element that matches a selector 1', function (editor) { editor.formatter.register('format', { selector: 'p', attributes: { title: 'test' }, styles: { color: '#ff0000' }, classes: 'a b c' }); editor.getBody().innerHTML = '1234
1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '1234
', 'Apply format on single element that matches a selector' ); }); suite.test('Apply format on single element parent that matches a selector 2', function (editor) { editor.formatter.register('format', { selector: 'div', attributes: { title: 'test' }, styles: { color: '#ff0000' }, classes: 'a b c' }); editor.getBody().innerHTML = '1234
test
1234
1234
test
1234
1234
1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[1].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '1234
1234
', 'Apply format on multiple elements that matches a selector' ); }); suite.test('Apply format on top of existing selector element', function (editor) { editor.formatter.register('format', { selector: 'p', attributes: { title: 'test2' }, styles: { color: '#00ff00' }, classes: 'a b c' }); editor.getBody().innerHTML = '1234
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), '1234
', 'Apply format on top of existing selector element' ); }); suite.test('Format on single li that matches a selector', function (editor) { editor.formatter.register('format', { inline: 'span', selector: 'li', attributes: { title: 'test' }, styles: { color: '#ff0000' }, classes: 'a b c' }); editor.getBody().innerHTML = 'test1 test2 test3 test4 test5 test6
'); rng.setStart(editor.dom.select('strong')[0].firstChild, 6); rng.setEnd(editor.dom.select('strong')[0].firstChild, 11); editor.focus(); editor.selection.setRng(rng); editor.execCommand('Italic'); LegacyUnit.equal( editor.getContent(editor), 'test1 test2 test3 test4 test5 test6
', 'Selected text should be bold.' ); }); suite.test('Apply color format to links as well', function (editor) { editor.setContent('123abc456
'); const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].lastChild, 3); editor.selection.setRng(rng); editor.formatter.register('format', { inline: 'span', styles: { color: '#FF0000' }, links: true }); editor.formatter.apply('format'); LegacyUnit.equal( editor.getContent(editor), '123abc456
', 'Link should have it\'s own color.' ); }); suite.test('Color on link element', function (editor) { editor.setContent('123abc456
'); const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('span')[0].firstChild, 0); rng.setEnd(editor.dom.select('span')[0].lastChild, 3); editor.selection.setRng(rng); editor.formatter.register('format', { inline: 'span', styles: { color: '#FF0000' }, links: true }); editor.formatter.apply('format'); LegacyUnit.equal( editor.getContent(editor), '123abc456
', 'Link should have it\'s own color.' ); }); suite.test('Applying formats in lists', function (editor) { editor.setContent('test
'); editor.execCommand('SelectAll'); editor.formatter.apply('format'); LegacyUnit.equal( editor.getContent(editor), 'test
', 'Coloring an underlined text should result in a colored underline' ); }); suite.test('Underline colors 2', function (editor) { editor.formatter.register('format', { inline: 'span', exact: true, styles: { textDecoration: 'underline' } }); editor.setContent('test
'); editor.execCommand('SelectAll'); editor.formatter.apply('format'); LegacyUnit.equal( editor.getContent(editor), 'test
', 'Underlining colored text should result in a colored underline' ); }); suite.test('Underline colors 3', function (editor) { editor.formatter.register('format', { inline: 'span', exact: true, styles: { textDecoration: 'underline' } }); editor.setContent( 'This is some ' + 'example text
' ); editor.execCommand('SelectAll'); editor.formatter.apply('format'); LegacyUnit.equal( editor.getContent(editor), '' + 'This is some example' + ' text
', 'Underlining colored and underlined text should result in a colored underline' ); }); suite.test('Underline colors 4', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { color: '#ff0000' } }); editor.setContent( 'yellowredyellow
' ); const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('span')[1].firstChild, 6); rng.setEnd(editor.dom.select('span')[1].firstChild, 9); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'yellowredyellow
', 'Coloring an colored underdlined text should result in newly colored underline' ); }); suite.test('Underline colors 5', function (editor) { editor.formatter.register('format', { inline: 'span', exact: true, styles: { textDecoration: 'underline' } }); editor.setContent( 'This is some example text
This is some example' + ' text
This is' + ' some example text
' ); const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('strong')[0].firstChild, 0); rng.setEnd(editor.dom.select('span')[4].lastChild, 5); editor.selection.setRng(rng); editor.formatter.apply('format'); LegacyUnit.equal( editor.getContent(editor), 'This is some example text
This is some example text
This is some example text
', 'Colored elements should be underlined when selection is across multiple paragraphs' ); }); suite.test('Underline colors 6', function (editor) { editor.formatter.register('format', { inline: 'span', exact: true, styles: { color: '#ff0000' } }); editor.setContent('This is some text.
'); const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('span')[0].firstChild, 8); rng.setEnd(editor.dom.select('span')[0].firstChild, 12); editor.selection.setRng(rng); editor.formatter.apply('format'); editor.formatter.remove('format'); LegacyUnit.equal( editor.getContent(editor), 'This is some text.
', 'Children nodes that are underlined should be removed if their parent nodes are underlined' ); }); suite.test('Underline colors 7', function (editor) { editor.formatter.register('format', { inline: 'span', exact: true, styles: { color: '#ff0000' } }); editor.setContent( 'This is some text.
' ); const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('span')[1].firstChild, 0); rng.setEnd(editor.dom.select('span')[1].firstChild, 4); editor.selection.setRng(rng); editor.formatter.remove('format'); LegacyUnit.equal( editor.getContent(editor), 'This is ' + 'some text.
', 'Children nodes that are underlined should be removed if their parent nodes are underlined' ); }); suite.test('Caret format inside single block word', function (editor) { editor.setContent('abc
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 2, 'p', 2); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc
'); }); suite.test('Caret format inside non-ascii single block word', function (editor) { editor.setContent('noël
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 2, 'p', 2); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'noël
'); }); suite.test('Caret format inside first block word', function (editor) { editor.setContent('abc 123
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 2, 'p', 2); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc 123
'); }); suite.test('Caret format inside last block word', function (editor) { editor.setContent('abc 123
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 5, 'p', 5); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc 123
'); }); suite.test('Caret format inside middle block word', function (editor) { editor.setContent('abc 123 456
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 5, 'p', 5); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc 123 456
'); }); suite.test('Caret format on word separated by non breaking space', function (editor) { editor.setContent('one two
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 1, 'p', 1); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'one\u00a0two
'); }); suite.test('Caret format inside single inline wrapped word', function (editor) { editor.setContent('abc 123 456
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'em', 1, 'em', 1); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc 123 456
'); }); suite.test('Caret format inside word before similar format', function (editor) { editor.setContent('abc 123 456
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 1, 'p', 1); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc 123 456
'); }); suite.test('Caret format inside last inline wrapped word', function (editor) { editor.setContent('abc abc 123 456
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'em', 5, 'em', 5); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc abc 123 456
'); }); suite.test('Caret format before text', function (editor) { editor.setContent('a
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 0, 'p', 0); editor.formatter.apply('format'); KeyUtils.type(editor, 'b'); LegacyUnit.equal(editor.getContent(editor), 'ba
'); }); suite.test('Caret format after text', function (editor) { editor.setContent('a
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 1, 'p', 1); editor.formatter.apply('format'); KeyUtils.type(editor, 'b'); LegacyUnit.equal(editor.getContent(editor), 'ab
'); }); suite.test('Caret format and no key press', function (editor) { editor.setContent('a
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 0, 'p', 0); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'a
'); }); suite.test('Caret format and arrow left', function (editor) { editor.setContent('a
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 0, 'p', 0); editor.formatter.apply('format'); KeyUtils.type(editor, { keyCode: 37 }); LegacyUnit.equal(editor.getContent(editor), 'a
'); }); suite.test('Caret format and arrow right', function (editor) { editor.setContent('a
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 0, 'p', 0); editor.formatter.apply('format'); KeyUtils.type(editor, { keyCode: 39 }); LegacyUnit.equal(editor.getContent(editor), 'a
'); }); suite.test('Caret format and backspace', function (editor) { let rng; editor.formatter.register('format', { inline: 'b' }); editor.setContent('abc
'); rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 3); rng.setEnd(editor.dom.select('p')[0].firstChild, 3); editor.selection.setRng(rng); editor.formatter.apply('format'); KeyUtils.type(editor, '\b'); LegacyUnit.equal(editor.getContent(editor), 'ab
'); }); suite.test('Caret format on word in li with word in parent li before it', function (editor) { editor.setContent('a
'); editor.formatter.register('format', { inline: 'span', selector: '*', classes: 'test' }); LegacyUnit.setSelection(editor, 'p', 0, 'p', 1); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'a
'); }); suite.test('format inline on contentEditable: false block', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.setContent('abc
def
'); LegacyUnit.setSelection(editor, 'p:nth-child(2)', 0, 'p:nth-child(2)', 3); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc
def
', 'Text is not bold'); }); suite.test('format block on contentEditable: false block', function (editor) { editor.formatter.register('format', { block: 'h1' }); editor.setContent('abc
def
'); LegacyUnit.setSelection(editor, 'p:nth-child(2)', 0, 'p:nth-child(2)', 3); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc
def
', 'P is not h1'); }); suite.test('contentEditable: false on start and contentEditable: true on end', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.setContent('abc
def
ghi
'); LegacyUnit.setSelection(editor, 'p:nth-child(2)', 0, 'p:nth-child(3)', 3); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc
def
ghi
', 'Text in last paragraph is bold'); }); suite.test('contentEditable: true on start and contentEditable: false on end', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.setContent('abc
def
'); LegacyUnit.setSelection(editor, 'p:nth-child(1)', 0, 'p:nth-child(2)', 3); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc
def
', 'Text in first paragraph is bold'); }); suite.test('contentEditable: true inside contentEditable: false', function (editor) { editor.formatter.register('format', { inline: 'b' }); editor.setContent('abc
def
'); LegacyUnit.setSelection(editor, 'span', 0, 'span', 3); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc
def
', 'Text is bold'); }); suite.test('Del element wrapping blocks', function (editor) { editor.setContent('a
'); LegacyUnit.setSelection(editor, 'p', 0, 'p', 1); editor.formatter.register('format', { block: 'del', wrapper: true }); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a
a
'); LegacyUnit.setSelection(editor, 'p', 0, 'p', 1); editor.formatter.register('format', { block: 'del' }); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a
'); LegacyUnit.setSelection(editor, 'p', 0, 'p', 1); editor.formatter.register('format', { inline: 'del' }); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a
| a |
| a |
a' +
'
| ' +
'
a' +
'
| ' +
'
ab
'; const rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].lastChild, 1); editor.selection.setRng(rng); editor.formatter.register('format', { inline: 'span', attributes: { id: 'id' } }); editor.formatter.apply('format'); LegacyUnit.equal(HtmlUtils.normalizeHtml(editor.getBody().innerHTML), 'ab
'); }); suite.test('Bug #5134 - TinyMCE removes formatting tags in the getContent', function (editor) { editor.setContent(''); editor.formatter.register('format', { inline: 'strong', toggle: false }); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '', 'empty TinyMCE'); editor.selection.setContent('a'); LegacyUnit.equal(getContent(editor), 'a', 'bold text inside TinyMCE'); }); suite.test('Bug #5134 - TinyMCE removes formatting tags in the getContent - typing', function (editor) { editor.setContent(''); editor.formatter.register('format', { inline: 'strong', toggle: false }); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), '', 'empty TinyMCE'); KeyUtils.type(editor, 'a'); LegacyUnit.equal(getContent(editor), 'a', 'bold text inside TinyMCE'); }); suite.test('Bug #5453 - TD contents with BR gets wrapped in block format', function (editor) { editor.setContent('| abc 123 |
abc123 |
abc
'); LegacyUnit.setSelection(editor, 'p', 2, 'p', 3); editor.formatter.apply('format'); LegacyUnit.setSelection(editor, 'p', 1, 'p', 2); editor.formatter.apply('format'); LegacyUnit.setSelection(editor, 'p', 0, 'p', 1); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'abc
'); }); suite.test('merge_with_parents', function (editor) { editor.formatter.register('format', { inline: 'span', styles: { fontWeight: 'bold' }, merge_with_parents: true }); editor.setContent('a
'); LegacyUnit.setSelection(editor, 'span', 0, 'span', 1); editor.formatter.apply('format'); LegacyUnit.equal(editor.getContent(editor), 'a
'); }); suite.test('Format selection from with end at beginning of block', function (editor) { editor.setContent('abcd
'); LegacyUnit.setSelection(editor, 'strong', 1, 'em', 0); editor.formatter.apply('underline'); LegacyUnit.equal(getContent(editor), 'abcd
'); }); suite.test('Child wrapper having the same format as the immediate parent, shouldn\'t be removed if it also has other formats merged', function (editor) { editor.getBody().innerHTML = 'a bc
'; LegacyUnit.setSelection(editor, 'span span', 0, 'span span', 1); editor.formatter.apply('fontname', { value: 'verdana' }); LegacyUnit.equal(getContent(editor), 'a bc
'); }); suite.test('FontName should not toggle', function (editor) { editor.getBody().innerHTML = 'abc
'; LegacyUnit.setSelection(editor, 'p', 0, 'p', 3); editor.formatter.toggle('fontname', { value: 'arial' }); LegacyUnit.equal(getContent(editor), 'abc
'); LegacyUnit.setSelection(editor, 'span', 0, 'span', 3); editor.formatter.toggle('fontname', { value: 'arial' }); LegacyUnit.equal(getContent(editor), 'abc
'); }); suite.test('FontSize should not toggle', function (editor) { editor.getBody().innerHTML = 'abc
'; LegacyUnit.setSelection(editor, 'p', 0, 'p', 3); editor.formatter.toggle('fontsize', { value: '14pt' }); LegacyUnit.equal(getContent(editor), 'abc
'); LegacyUnit.setSelection(editor, 'span', 0, 'span', 3); editor.formatter.toggle('fontsize', { value: '14pt' }); LegacyUnit.equal(getContent(editor), 'abc
'); }); suite.test('All the nested childNodes having fontSize should receive backgroundColor as well', function (editor) { editor.getBody().innerHTML = 'a b c
'; editor.selection.select(editor.dom.select('p')[0]); editor.formatter.apply('hilitecolor', { value: '#ff0000' }); LegacyUnit.equal( getContent(editor), 'a b c
' ); editor.formatter.remove('hilitecolor', { value: '#ff0000' }); LegacyUnit.equal(getContent(editor), 'a b c
'); }); suite.test('Formatter should wrap elements that have data-mce-bogus attribute, rather then attempt to inject styles into it', function (editor) { // add a class to retain bogus element editor.getBody().innerHTML = 'That is a misespelled text
'; editor.selection.select(editor.dom.select('span')[0]); editor.formatter.apply('fontname', { value: 'verdana' }); LegacyUnit.equal(editor.getBody().innerHTML, 'That is a misespelled text
'); LegacyUnit.equal(getContent(editor), 'that is a misespelled text
'); editor.selection.select(editor.dom.select('span')[0]); editor.formatter.remove('fontname', { value: 'verdana' }); LegacyUnit.equal(editor.getBody().innerHTML, 'That is a misespelled text
'); LegacyUnit.equal(getContent(editor), 'that is a misespelled text
'); }); suite.test('TINY-1180: Formatting gets applied outside the currently selected range', function (editor) { editor.getBody().innerHTML = 'a em
'; LegacyUnit.setSelection(editor, 'p', 0, 'em em', 0); editor.formatter.apply('strikethrough'); LegacyUnit.equal(getContent(editor), 'a em
'); }); suite.test('Superscript on subscript removes the subscript element', function (editor) { editor.getBody().innerHTML = 'a
'; LegacyUnit.setSelection(editor, 'sub', 0, 'sub', 1); editor.formatter.apply('superscript'); LegacyUnit.equal(getContent(editor), 'a
'); }); suite.test('Subscript on superscript removes the superscript element', function (editor) { editor.getBody().innerHTML = 'a
'; LegacyUnit.setSelection(editor, 'sup', 0, 'sup', 1); editor.formatter.apply('subscript'); LegacyUnit.equal(getContent(editor), 'a
'); }); suite.test('TINY-782: Can\'t apply sub/sup to word on own line with large font', function (editor) { editor.getBody().innerHTML = 'abc
'; LegacyUnit.setSelection(editor, 'span', 0, 'span', 3); editor.formatter.apply('superscript'); LegacyUnit.equal(getContent(editor), 'abc
'); }); suite.test('TINY-782: Apply sub/sup to range with multiple font sizes', function (editor) { editor.getBody().innerHTML = 'abc
'; LegacyUnit.setSelection(editor, 'p', 0, 'span:nth-child(2)', 1); editor.formatter.apply('superscript'); LegacyUnit.equal(getContent(editor), 'abc
'); }); suite.test('TINY-671: Background color on nested font size bug', function (editor) { editor.getBody().innerHTML = 'abc
'; LegacyUnit.setSelection(editor, 'span', 0, 'span', 3); editor.formatter.apply('hilitecolor', { value: '#ff0000' }); LegacyUnit.equal(getContent(editor), 'abc
'); }); suite.test('Background color over range of font sizes', function (editor) { editor.getBody().innerHTML = 'abc
'; LegacyUnit.setSelection(editor, 'p', 0, 'span:nth-child(2)', 1); editor.formatter.apply('hilitecolor', { value: '#ff0000' }); LegacyUnit.equal( getContent(editor), 'abc
' ); }); suite.test('TINY-865: Font size removed when changing background color', function (editor) { editor.getBody().innerHTML = ( 'a ' + 'b c
' ); LegacyUnit.setSelection(editor, 'span span:nth-child(2)', 0, 'span span:nth-child(2)', 1); editor.formatter.apply('hilitecolor', { value: '#ff0000' }); LegacyUnit.equal( getContent(editor), 'a b c
' ); }); suite.test('TINY-935: Text color, then size, then change color wraps span doesn\'t change color', function (editor) { editor.getBody().innerHTML = 'text
'; LegacyUnit.setSelection(editor, 'span', 0, 'span', 4); editor.formatter.apply('forecolor', { value: '#ff0000' }); LegacyUnit.equal(getContent(editor), 'text
'); }); suite.test('GH-3519: Font family selection does not work after changing font size', function (editor) { editor.getBody().innerHTML = 'text
'; LegacyUnit.setSelection(editor, 'span', 0, 'span', 4); editor.formatter.apply('fontname', { value: 'verdana' }); LegacyUnit.equal(getContent(editor), 'text
'); }); suite.test('Formatter should remove similar styles when clear_child_styles is set to true', function (editor) { editor.getBody().innerHTML = ( 'a' +
'b' +
'c
abc
abc
'; editor.selection.select(editor.dom.select('p')[0]); editor.formatter.register('format', { inline: 'span', styles: { fontSize: '14px' }, links: true, clear_child_styles: true }); editor.formatter.apply('format'); LegacyUnit.equal( getContent(editor), 'abc
' ); }); suite.test('Formatter should remove similar styles when clear_child_styles isn\'t defined', function (editor) { editor.getBody().innerHTML = ( 'a' +
'b' +
'c
abc
a
a
a
a b
'); editor.formatter.register('format', { inline: 'b' }); LegacyUnit.setSelection(editor, 'p', 0, 'p', 2); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a b
'); }); suite.test('Apply format with onformat handler', function (editor) { editor.setContent('a
'); editor.formatter.register('format', { inline: 'span', onformat (elm) { elm.className = 'x'; } }); LegacyUnit.setSelection(editor, 'p', 0, 'p', 1); editor.formatter.apply('format'); LegacyUnit.equal(getContent(editor), 'a
'); }); suite.test('Apply format to triple clicked selection (webkit)', function (editor) { editor.setContent('a
a
abcdef
'); LegacyUnit.setSelection(editor, 'span span', 1, 'strong', 1); editor.formatter.apply('hilitecolor', { value: '#00ff00' }); LegacyUnit.equal(getContent(editor), 'abcdef
'); }); TinyLoader.setup(function (editor, onSuccess, onFailure) { Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure); }, { indent: false, extended_valid_elements: 'b[id|style|title],i[id|style|title],span[id|class|style|title|contenteditable],font[face|size]', entities: 'raw', convert_fonts_to_spans: false, forced_root_block: 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,display,text-align' }, skin_url: '/project/js/tinymce/skins/lightgray' }, success, failure); });