import { context, describe, it } from '@ephox/bedrock-client'; import { LegacyUnit, TinyAssertions, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import { assert } from 'chai'; import Editor from 'tinymce/core/api/Editor'; import { TableModifiedEvent } from 'tinymce/core/api/EventTypes'; import { EditorEvent } from 'tinymce/core/api/util/EventDispatcher'; import * as TableTestUtils from '../../../module/table/TableTestUtils'; describe('browser.tinymce.models.dom.table.command.InsertCommandsTest', () => { const hook = TinyHooks.bddSetupLight({ indent: false, valid_styles: { '*': 'height,vertical-align,text-align,float,border-color,background-color,border,padding,border-spacing,border-collapse' }, base_url: '/project/tinymce/js/tinymce', setup: (editor: Editor) => { editor.on('TableModified', logEvent); } }, [], true); const cleanTableHtml = (html: string) => html.replace(/

( |]+>)<\/p>$/, ''); let events: Array> = []; const logEvent = (event: EditorEvent) => { events.push(event); }; const execCmdAndAssertEvent = (editor: Editor, cmdName: string) => { assert.lengthOf(events, 0); editor.execCommand(cmdName); assert.lengthOf(events, 1); assert.equal(events[0].type, 'tablemodified'); assert.isTrue(events[0].structure); assert.isFalse(events[0].style); events = []; }; it('TBA: mceTableInsertColAfter command', () => { const editor = hook.editor(); editor.setContent('
1
2
'); LegacyUnit.setSelection(editor, 'td', 0); execCmdAndAssertEvent(editor, 'mceTableInsertColAfter'); assert.equal( cleanTableHtml(editor.getContent()), '
1 
2 
' ); }); it('TBA: mceTableInsertColAfter command with two selected columns', () => { const editor = hook.editor(); editor.getBody().innerHTML = ( '' + '
123
456
' ); LegacyUnit.setSelection(editor, 'td', 0); execCmdAndAssertEvent(editor, 'mceTableInsertColAfter'); assert.equal( cleanTableHtml(editor.getContent()), '' + '
12  3
45  6
' ); }); it('TBA: mceTableInsertColBefore command', () => { const editor = hook.editor(); editor.setContent('
1
2
'); LegacyUnit.setSelection(editor, 'td', 0); execCmdAndAssertEvent(editor, 'mceTableInsertColBefore'); assert.equal( cleanTableHtml(editor.getContent()), '
 1
 2
' ); }); it('TBA: mceTableInsertColBefore command with two selected columns', () => { const editor = hook.editor(); editor.getBody().innerHTML = ( '' + '
123
456
' ); LegacyUnit.setSelection(editor, 'td:nth-child(2)', 0); execCmdAndAssertEvent(editor, 'mceTableInsertColBefore'); assert.equal( cleanTableHtml(editor.getContent()), '' + '
1  23
4  56
' ); }); it('TBA: mceTableInsertRowAfter command', () => { const editor = hook.editor(); editor.setContent('
12
'); LegacyUnit.setSelection(editor, 'td', 0); execCmdAndAssertEvent(editor, 'mceTableInsertRowAfter'); assert.equal( cleanTableHtml(editor.getContent()), '
12
  
' ); }); it('TBA: mceTableInsertRowAfter command with two selected rows', () => { const editor = hook.editor(); editor.getBody().innerHTML = ( '
12
34
' ); LegacyUnit.setSelection(editor, 'tr', 0); execCmdAndAssertEvent(editor, 'mceTableInsertRowAfter'); assert.equal( cleanTableHtml(editor.getContent()), '' + '
12
34
  
  
' ); }); it('TBA: mceTableInsertRowAfter command on merged cells', () => { const editor = hook.editor(); editor.setContent( '' + '' + '' + '' + '
123
45
6
' ); LegacyUnit.setSelection(editor, 'tr:nth-child(2) td', 0); execCmdAndAssertEvent(editor, 'mceTableInsertRowAfter'); assert.equal( cleanTableHtml(editor.getContent()), '' + '' + '' + '' + '' + '' + '' + '
123
45
 
6
' ); }); it('TBA: mceTableInsertRowBefore command', () => { const editor = hook.editor(); editor.setContent('
12
'); LegacyUnit.setSelection(editor, 'td', 0); execCmdAndAssertEvent(editor, 'mceTableInsertRowBefore'); assert.equal( cleanTableHtml(editor.getContent()), '
  
12
' ); }); it('TBA: mceTableInsertRowBefore command with two selected rows', () => { const editor = hook.editor(); editor.getBody().innerHTML = ( '
12
34
' ); LegacyUnit.setSelection(editor, 'tr', 0); execCmdAndAssertEvent(editor, 'mceTableInsertRowBefore'); assert.equal( cleanTableHtml(editor.getContent()), '' + '
  
  
12
34
' ); }); context('Noneditable root', () => { const testNoopExecCommand = (cmd: string) => () => { TableTestUtils.withNoneditableRootEditor(hook.editor(), (editor) => { const initalContent = '
cell
'; editor.setContent(initalContent); TinySelections.setCursor(editor, [ 0, 0, 0, 0, 0 ], 0); editor.execCommand(cmd); TinyAssertions.assertContent(editor, initalContent); }); }; it('TINY-9459: Should not apply mceInsertColBefore command on table in noneditable root', testNoopExecCommand('mceInsertColBefore')); it('TINY-9459: Should not apply mceInsertColAfter command on table in noneditable root', testNoopExecCommand('mceInsertColAfter')); it('TINY-9459: Should not apply mceInsertRowBefore command on table in noneditable root', testNoopExecCommand('mceInsertRowBefore')); it('TINY-9459: Should not apply mceInsertRowAfter command on table in noneditable root', testNoopExecCommand('mceInsertRowAfter')); }); });