import { afterEach, describe, it } from '@ephox/bedrock-client'; import { Arr } from '@ephox/katamari'; import { 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.TableDeleteRowTest', () => { let events: Array> = []; const hook = TinyHooks.bddSetupLight({ indent: false, base_url: '/project/tinymce/js/tinymce', setup: (editor: Editor) => { editor.on('TableModified', logEvent); } }, [], true); afterEach(() => { events = []; }); const logEvent = (event: EditorEvent) => { events.push(event); }; const assertEvents = (count: number) => { assert.lengthOf(events, count); Arr.each(events, (event) => { assert.equal(event.type, 'tablemodified', 'Event name'); assert.isTrue(event.structure, 'Table modified structure'); assert.isFalse(event.style, 'Table modified style'); }); }; it('TINY-7916: Delete all rows should delete the table', () => { const editor = hook.editor(); editor.setContent('
1
2
3
'); TinySelections.setCursor(editor, [ 0, 0, 2, 0, 0 ], 1); editor.execCommand('mceTableDeleteRow'); TinyAssertions.assertCursor(editor, [ 0, 0, 1, 0, 0 ], 1); editor.execCommand('mceTableDeleteRow'); TinyAssertions.assertCursor(editor, [ 0, 0, 0, 0, 0 ], 1); editor.execCommand('mceTableDeleteRow'); TinyAssertions.assertContent(editor, ''); assertEvents(2); }); it('TINY-7916: Delete all rows with a contenteditable=false cell', () => { const editor = hook.editor(); editor.setContent('
1
2
3
'); TinySelections.setCursor(editor, [ 0, 0, 2, 0, 0 ], 1); editor.execCommand('mceTableDeleteRow'); TinyAssertions.assertCursor(editor, [ 0, 0, 1, 0, 0 ], 1); editor.execCommand('mceTableDeleteRow'); TinyAssertions.assertSelection(editor, [ 0, 0, 0 ], 0, [ 0, 0, 0 ], 1); editor.execCommand('mceTableDeleteRow'); TinyAssertions.assertContent(editor, ''); assertEvents(2); }); it('TINY-9459: Should not apply mceTableDeleteRow command on table in noneditable root', () => { TableTestUtils.withNoneditableRootEditor(hook.editor(), (editor) => { const initalContent = '
cell
'; editor.setContent(initalContent); TinySelections.setCursor(editor, [ 0, 0, 0, 0, 0 ], 0); editor.execCommand('mceTableDeleteRow'); TinyAssertions.assertContent(editor, initalContent); }); }); it('TINY-9459: Should not apply mceTableDeleteRow command on table in noneditable table', () => { const editor = hook.editor(); const initalContent = '
cell
'; editor.setContent(initalContent); TinySelections.setCursor(editor, [ 1, 0, 0, 0, 0 ], 0); // Index off by one due to cef fake caret editor.execCommand('mceTableDeleteRow'); TinyAssertions.assertContent(editor, initalContent); }); });