import { Pipeline } from '@ephox/agar'; import { UnitTest } from '@ephox/bedrock'; import { LegacyUnit, TinyLoader } from '@ephox/mcagar'; import Plugin from 'tinymce/plugins/table/Plugin'; import Theme from 'tinymce/themes/modern/Theme'; UnitTest.asynctest('browser.tinymce.plugins.table.MergeCellCommandTest', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; const suite = LegacyUnit.createSuite(); Plugin(); Theme(); const testCommand = function (editor, command, tests) { // TODO: Figure out why these doesn't work /*Tools.each(tests, function (test) { editor.getBody().innerHTML = test.before; editor.selection.select(editor.dom.select('td[data-mce-selected]')[0], true); editor.selection.collapse(true); editor.execCommand(command); LegacyUnit.equal(cleanTableHtml(editor.getContent()), test.after, test.message); });*/ }; // const cleanTableHtml = function (html) { // return html.replace(/

( |]+>)<\/p>$/, ''); // }; suite.test('mceTableMergeCells', function (editor) { testCommand(editor, 'mceTableMergeCells', [ { message: 'Should merge all cells into one', before: ( '' + '' + '' + '' + '' + '
a1b1
a2b2
' ), after: ( '' + '' + '' + '' + '
a1b1a2b2
' ) }, { message: 'Should merge cells in two cols/rows into one cell with colspan', before: ( '' + '' + '' + '' + '' + '' + '
a1b1
a2b2
a3b3
' ), after: ( '' + '' + '' + '' + '' + '
a1b1a2b2
a3b3
' ) }, { message: 'Should remove all rowspans since the table is fully merged', before: ( '' + '' + '' + '' + '' + '
a1b1
b2
' ), after: ( '' + '' + '' + '' + '
a1b1b2
' ) }, { message: 'Should remove all colspans since the table is fully merged', before: ( '' + '' + '' + '' + '' + '
a1
a2b2
' ), after: ( '' + '' + '' + '' + '' + '
a1
a2b2
' ) }, { message: 'Should remove rowspans since the table is fully merged', before: ( '' + '' + '' + '' + '' + '' + '
a1b1c1
c2
c3
' ), after: ( '' + '' + '' + '' + '
a1b1c1c2c3
' ) }, { message: 'Should remove colspans since the table is fully merged', before: ( '' + '' + '' + '' + '' + '' + '
a1b1c1
a2
a3
' ), after: ( '' + '' + '' + '' + '' + '' + '
a1b1c1
a2
a3
' ) }, { message: 'Should reduce rowspans to 2 keep the colspan and remove one tr', before: ( '' + '' + '' + '' + '' + '' + '
a1b1c1
c2
a3b3c3
' ), after: ( '' + '' + '' + '' + '' + '
a1b1c1c2c3
a3b3
' ) }, { message: 'Should reduce colspans to 2 keep the rowspan', before: ( '' + '' + '' + '' + '' + '' + '' + '
a1b1c1
a2
a3c3
c4
' ), after: ( '' + '' + '' + '' + '' + '' + '' + '
a1b1c1
a2
a3c3
c4
' ) }, { message: 'Should merge b3+c3 but not reduce a2a3', before: ( '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1b1c1
a2a3b2c2
b3c3
' ), after: ( '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1b1c1
a2a3b2c2
b3c3
' ) }, { message: 'Should merge b1+c1 and reduce a2', before: ( '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1b1c1
a2
' ), after: ( '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1b1c1
a2
' ) }, { message: 'Should merge a2+a3 and reduce b1', before: ( '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1b1
a2
a3
' ), after: ( '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1b1
a2a3
' ) } ]); }); TinyLoader.setup(function (editor, onSuccess, onFailure) { Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure); }, { plugins: 'table', indent: false, valid_styles: { '*': 'width,height,vertical-align,text-align,float,border-color,background-color,border,padding,border-spacing,border-collapse' }, skin_url: '/project/js/tinymce/skins/lightgray' }, success, failure); });