import { UiFinder } from '@ephox/agar'; import { context, describe, it } from '@ephox/bedrock-client'; import { Arr, Optional, Optionals } from '@ephox/katamari'; import { TinyAssertions, TinyDom, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import { assert } from 'chai'; import Editor from 'tinymce/core/api/Editor'; describe('browser.tinymce.models.dom.table.InvalidColCountTest', () => { const hook = TinyHooks.bddSetupLight({ base_url: '/project/tinymce/js/tinymce', }, [], true); const assertBasicTablePresence = (editor: Editor, tdCount: number, colCountOpt: Optional) => { TinyAssertions.assertContentPresence(editor, { td: tdCount, }); colCountOpt.each((colCount) => { const cols = UiFinder.findAllIn(TinyDom.body(editor), 'col'); assert.lengthOf(cols, colCount); }); }; // Note: The goal of these tests is to make sure an exception is not thrown and each table operation works // when there are less or more col elements than actual columns Arr.each([ { label: 'less cols', colgroupHtml: '', assertColCount: true }, { label: 'less cols with span', colgroupHtml: '', }, { label: 'more cols', colgroupHtml: '', assertColCount: true }, { label: 'more cols with span at beginning', colgroupHtml: '', }, { label: 'more cols with span at end', colgroupHtml: '', }, { label: 'single col with span greater than cells', colgroupHtml: '', } ], (scenario) => { context(scenario.label, () => { const tableHtml = '' + scenario.colgroupHtml + '' + '' + '' + '' + '
123
456
'; const assertColCount = scenario.assertColCount === true; const colCountAfterInsertColumn = Optionals.someIf(assertColCount, 4); const colCountAfterDeleteColumn = Optionals.someIf(assertColCount, 2); const colCountAfterNonColumnAction = Optionals.someIf(assertColCount, 3); it('TINY-7041: insert new column at the start of the table', () => { const editor = hook.editor(); editor.setContent(tableHtml); TinySelections.setCursor(editor, [ 0, 1, 0, 0, 0 ], 0); editor.execCommand('mceTableInsertColBefore'); assertBasicTablePresence(editor, 8, colCountAfterInsertColumn); }); it('TINY-7041: insert new column in the middle of the table from first column', () => { const editor = hook.editor(); editor.setContent(tableHtml); TinySelections.setCursor(editor, [ 0, 1, 0, 0, 0 ], 0); editor.execCommand('mceTableInsertColAfter'); assertBasicTablePresence(editor, 8, colCountAfterInsertColumn); }); it('TINY-7041: insert new column in the middle of the table from last column', () => { const editor = hook.editor(); editor.setContent(tableHtml); TinySelections.setCursor(editor, [ 0, 1, 0, 2, 0 ], 0); editor.execCommand('mceTableInsertColBefore'); assertBasicTablePresence(editor, 8, colCountAfterInsertColumn); }); it('TINY-7041: insert new column at the end of the table', () => { const editor = hook.editor(); editor.setContent(tableHtml); TinySelections.setCursor(editor, [ 0, 1, 0, 2, 0 ], 0); editor.execCommand('mceTableInsertColAfter'); assertBasicTablePresence(editor, 8, colCountAfterInsertColumn); }); it('TINY-7041: insert new row', () => { const editor = hook.editor(); editor.setContent(tableHtml); TinySelections.setCursor(editor, [ 0, 1, 0, 0, 0 ], 0); editor.execCommand('mceTableInsertRowAfter'); assertBasicTablePresence(editor, 9, colCountAfterNonColumnAction); }); it('TINY-7041: delete first column in the table', () => { const editor = hook.editor(); editor.setContent(tableHtml); TinySelections.setCursor(editor, [ 0, 1, 0, 0, 0 ], 0); editor.execCommand('mceTableDeleteCol'); assertBasicTablePresence(editor, 4, colCountAfterDeleteColumn); }); it('TINY-7041: delete last column in the table', () => { const editor = hook.editor(); editor.setContent(tableHtml); TinySelections.setCursor(editor, [ 0, 1, 0, 2, 0 ], 0); editor.execCommand('mceTableDeleteCol'); assertBasicTablePresence(editor, 4, colCountAfterDeleteColumn); }); }); }); });