import { UiFinder } from '@ephox/agar'; import { context, describe, it } from '@ephox/bedrock-client'; import { SelectorFind } from '@ephox/sugar'; import { TinyDom, TinyHooks } from '@ephox/wrap-mcagar'; import Editor from 'tinymce/core/api/Editor'; import * as TableTestUtils from '../../module/table/TableTestUtils'; interface Scenario { readonly html: string; } describe('browser.tinymce.models.dom.table.InsertColumnTableSizeTest', () => { const hook = TinyHooks.bddSetup({ width: 400, base_url: '/project/tinymce/js/tinymce' }, [], true); const emptyTable = { html: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' }; const contentsInSomeCells = { html: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1b1
' }; const contentsInAllCells = { html: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1b1
a2b2
a3b3
' }; const tableWithHeadings = { html: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1b1
a1b1
a2b2
' }; const tableWithCaption = { html: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
alphabet
a1b1
a2b2
' }; const nestedTables = { html: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
a1' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
b1
a2b2
' }; const insertTable = (editor: Editor, table: string) => { editor.setContent(table); const bodyElem = TinyDom.body(editor); const tableElem = UiFinder.findIn(bodyElem, 'table').getOrDie(); SelectorFind.descendant(tableElem, 'td,th').each((cell) => { editor.selection.select(cell.dom, true); editor.selection.collapse(true); }); return tableElem; }; const pInsertColumnMeasureWidth = async (editor: Editor, scenario: Scenario) => { const table = insertTable(editor, scenario.html); await TableTestUtils.pDragHandle(editor, 'se', -100, 0); const widthBefore = TableTestUtils.getWidths(editor, table.dom); TableTestUtils.insertColumnBefore(editor); TableTestUtils.insertColumnAfter(editor); TableTestUtils.deleteColumn(editor); const widthAfter = TableTestUtils.getWidths(editor, table.dom); return { widthBefore, widthAfter }; }; const pInsertColumnAssertWidth = async (scenario: Scenario) => { const widths = await pInsertColumnMeasureWidth(hook.editor(), scenario); TableTestUtils.assertWidths(widths); }; context('Insert columns, erase column and assert the table width does not change', () => { it('table which is empty', () => pInsertColumnAssertWidth(emptyTable)); it('table with contents in some cells', () => pInsertColumnAssertWidth(contentsInSomeCells)); it('table with contents in all cells', () => pInsertColumnAssertWidth(contentsInAllCells)); it('table with headings', () => pInsertColumnAssertWidth(tableWithHeadings)); it('table with caption', () => pInsertColumnAssertWidth(tableWithCaption)); it('table with nested tables', () => pInsertColumnAssertWidth(nestedTables)); }); });