8
0
Просмотр исходного кода

Merge pull request #7410 from ckeditor/i/6574

Tests (table): Use real schema and conversion definitions in table tests. Closes #6574.

Other (table): Removed `options.asWidget` from most of the table converters which are never run in data pipeline.
Kuba Niegowski 5 лет назад
Родитель
Сommit
b127f41163

+ 28 - 40
packages/ckeditor5-table/src/converters/downcast.js

@@ -84,7 +84,7 @@ export function downcastInsertTable( options = {} ) {
  *
  * @returns {Function} Conversion helper.
  */
-export function downcastInsertRow( options = {} ) {
+export function downcastInsertRow() {
 	return dispatcher => dispatcher.on( 'insert:tableRow', ( evt, data, conversionApi ) => {
 		const tableRow = data.item;
 
@@ -120,7 +120,7 @@ export function downcastInsertRow( options = {} ) {
 
 			const insertPosition = conversionApi.writer.createPositionAt( trElement, 'end' );
 
-			createViewTableCellElement( tableSlot, tableAttributes, insertPosition, conversionApi, options );
+			createViewTableCellElement( tableSlot, tableAttributes, insertPosition, conversionApi, { asWidget: true } );
 		}
 	} );
 }
@@ -133,7 +133,7 @@ export function downcastInsertRow( options = {} ) {
  *
  * @returns {Function} Conversion helper.
  */
-export function downcastInsertCell( options = {} ) {
+export function downcastInsertCell() {
 	return dispatcher => dispatcher.on( 'insert:tableCell', ( evt, data, conversionApi ) => {
 		const tableCell = data.item;
 
@@ -158,7 +158,7 @@ export function downcastInsertCell( options = {} ) {
 				const trElement = conversionApi.mapper.toViewElement( tableRow );
 				const insertPosition = conversionApi.writer.createPositionAt( trElement, tableRow.getChildIndex( tableCell ) );
 
-				createViewTableCellElement( tableSlot, tableAttributes, insertPosition, conversionApi, options );
+				createViewTableCellElement( tableSlot, tableAttributes, insertPosition, conversionApi, { asWidget: true } );
 
 				// No need to iterate further.
 				return;
@@ -178,9 +178,7 @@ export function downcastInsertCell( options = {} ) {
  *
  * @returns {Function} Conversion helper.
  */
-export function downcastTableHeadingRowsChange( options = {} ) {
-	const asWidget = !!options.asWidget;
-
+export function downcastTableHeadingRowsChange() {
 	return dispatcher => dispatcher.on( 'attribute:headingRows:table', ( evt, data, conversionApi ) => {
 		const table = data.item;
 
@@ -205,7 +203,7 @@ export function downcastTableHeadingRowsChange( options = {} ) {
 			// Rename all table cells from moved rows to 'th' as they lands in <thead>.
 			for ( const tableRow of rowsToMove ) {
 				for ( const tableCell of tableRow.getChildren() ) {
-					renameViewTableCell( tableCell, 'th', conversionApi, asWidget );
+					renameViewTableCell( tableCell, 'th', conversionApi );
 				}
 			}
 		}
@@ -228,7 +226,7 @@ export function downcastTableHeadingRowsChange( options = {} ) {
 			};
 
 			for ( const tableSlot of tableWalker ) {
-				renameViewTableCellIfRequired( tableSlot, tableAttributes, conversionApi, asWidget );
+				renameViewTableCellIfRequired( tableSlot, tableAttributes, conversionApi );
 			}
 		}
 
@@ -249,9 +247,7 @@ export function downcastTableHeadingRowsChange( options = {} ) {
  *
  * @returns {Function} Conversion helper.
  */
-export function downcastTableHeadingColumnsChange( options = {} ) {
-	const asWidget = !!options.asWidget;
-
+export function downcastTableHeadingColumnsChange() {
 	return dispatcher => dispatcher.on( 'attribute:headingColumns:table', ( evt, data, conversionApi ) => {
 		const table = data.item;
 
@@ -270,7 +266,7 @@ export function downcastTableHeadingColumnsChange( options = {} ) {
 		const lastColumnToCheck = ( oldColumns > newColumns ? oldColumns : newColumns ) - 1;
 
 		for ( const tableSlot of new TableWalker( table, { endColumn: lastColumnToCheck } ) ) {
-			renameViewTableCellIfRequired( tableSlot, tableAttributes, conversionApi, asWidget );
+			renameViewTableCellIfRequired( tableSlot, tableAttributes, conversionApi );
 		}
 	} );
 }
@@ -327,8 +323,7 @@ function toTableWidget( viewElement, writer ) {
 // @param {module:engine/model/element~Element} tableCell
 // @param {String} desiredCellElementName
 // @param {module:engine/conversion/downcastdispatcher~DowncastConversionApi} conversionApi
-// @param {Boolean} asWidget
-function renameViewTableCell( tableCell, desiredCellElementName, conversionApi, asWidget ) {
+function renameViewTableCell( tableCell, desiredCellElementName, conversionApi ) {
 	const viewWriter = conversionApi.writer;
 	const viewCell = conversionApi.mapper.toViewElement( tableCell );
 
@@ -337,41 +332,30 @@ function renameViewTableCell( tableCell, desiredCellElementName, conversionApi,
 		return;
 	}
 
-	let renamedCell;
-
-	if ( asWidget ) {
-		const editable = viewWriter.createEditableElement( desiredCellElementName, viewCell.getAttributes() );
-		renamedCell = toWidgetEditable( editable, viewWriter );
+	const editable = viewWriter.createEditableElement( desiredCellElementName, viewCell.getAttributes() );
+	const renamedCell = toWidgetEditable( editable, viewWriter );
 
-		setHighlightHandling(
-			renamedCell,
-			viewWriter,
-			( element, descriptor, writer ) => writer.addClass( normalizeToArray( descriptor.classes ), element ),
-			( element, descriptor, writer ) => writer.removeClass( normalizeToArray( descriptor.classes ), element )
-		);
+	setHighlightHandling(
+		renamedCell,
+		viewWriter,
+		( element, descriptor, writer ) => writer.addClass( normalizeToArray( descriptor.classes ), element ),
+		( element, descriptor, writer ) => writer.removeClass( normalizeToArray( descriptor.classes ), element )
+	);
 
-		viewWriter.insert( viewWriter.createPositionAfter( viewCell ), renamedCell );
-		viewWriter.move( viewWriter.createRangeIn( viewCell ), viewWriter.createPositionAt( renamedCell, 0 ) );
-		viewWriter.remove( viewWriter.createRangeOn( viewCell ) );
-	} else {
-		renamedCell = viewWriter.rename( desiredCellElementName, viewCell );
-	}
+	viewWriter.insert( viewWriter.createPositionAfter( viewCell ), renamedCell );
+	viewWriter.move( viewWriter.createRangeIn( viewCell ), viewWriter.createPositionAt( renamedCell, 0 ) );
+	viewWriter.remove( viewWriter.createRangeOn( viewCell ) );
 
 	conversionApi.mapper.unbindViewElement( viewCell );
 	conversionApi.mapper.bindElements( tableCell, renamedCell );
 }
 
-function normalizeToArray( classes ) {
-	return Array.isArray( classes ) ? classes : [ classes ];
-}
-
 // Renames a table cell element in the view according to its location in the table.
 //
 // @param {module:table/tablewalker~TableSlot} tableSlot
 // @param {{headingColumns, headingRows}} tableAttributes
 // @param {module:engine/conversion/downcastdispatcher~DowncastConversionApi} conversionApi
-// @param {Boolean} asWidget
-function renameViewTableCellIfRequired( tableSlot, tableAttributes, conversionApi, asWidget ) {
+function renameViewTableCellIfRequired( tableSlot, tableAttributes, conversionApi ) {
 	const { cell } = tableSlot;
 
 	// Check whether current columnIndex is overlapped by table cells from previous rows.
@@ -382,7 +366,7 @@ function renameViewTableCellIfRequired( tableSlot, tableAttributes, conversionAp
 	// If in single change we're converting attribute changes and inserting cell the table cell might not be inserted into view
 	// because of child conversion is done after parent.
 	if ( viewCell && viewCell.name !== desiredCellElementName ) {
-		renameViewTableCell( cell, desiredCellElementName, conversionApi, asWidget );
+		renameViewTableCell( cell, desiredCellElementName, conversionApi );
 	}
 }
 
@@ -421,7 +405,7 @@ function createViewTableCellElement( tableSlot, tableAttributes, insertPosition,
 
 		conversionApi.consumable.consume( innerParagraph, 'insert' );
 
-		if ( options.asWidget ) {
+		if ( asWidget ) {
 			// Use display:inline-block to force Chrome/Safari to limit text mutations to this element.
 			// See #6062.
 			const fakeParagraph = conversionApi.writer.createContainerElement( 'span', { style: 'display:inline-block' } );
@@ -589,3 +573,7 @@ function getViewTable( viewFigure ) {
 function hasAnyAttribute( element ) {
 	return !![ ...element.getAttributeKeys() ].length;
 }
+
+function normalizeToArray( classes ) {
+	return Array.isArray( classes ) ? classes : [ classes ];
+}

+ 5 - 9
packages/ckeditor5-table/src/tableediting.js

@@ -100,26 +100,22 @@ export default class TableEditing extends Plugin {
 		conversion.for( 'upcast' ).elementToElement( { model: 'tableRow', view: 'tr' } );
 		conversion.for( 'upcast' ).add( skipEmptyTableRow() );
 
-		conversion.for( 'editingDowncast' ).add( downcastInsertRow( { asWidget: true } ) );
-		conversion.for( 'dataDowncast' ).add( downcastInsertRow() );
-		conversion.for( 'downcast' ).add( downcastRemoveRow() );
+		conversion.for( 'editingDowncast' ).add( downcastInsertRow() );
+		conversion.for( 'editingDowncast' ).add( downcastRemoveRow() );
 
 		// Table cell conversion.
 		conversion.for( 'upcast' ).add( upcastTableCell( 'td' ) );
 		conversion.for( 'upcast' ).add( upcastTableCell( 'th' ) );
 
-		conversion.for( 'editingDowncast' ).add( downcastInsertCell( { asWidget: true } ) );
-		conversion.for( 'dataDowncast' ).add( downcastInsertCell() );
+		conversion.for( 'editingDowncast' ).add( downcastInsertCell() );
 
 		// Table attributes conversion.
 		conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
 		conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
 
 		// Table heading rows and columns conversion.
-		conversion.for( 'editingDowncast' ).add( downcastTableHeadingColumnsChange( { asWidget: true } ) );
-		conversion.for( 'dataDowncast' ).add( downcastTableHeadingColumnsChange() );
-		conversion.for( 'editingDowncast' ).add( downcastTableHeadingRowsChange( { asWidget: true } ) );
-		conversion.for( 'dataDowncast' ).add( downcastTableHeadingRowsChange() );
+		conversion.for( 'editingDowncast' ).add( downcastTableHeadingColumnsChange() );
+		conversion.for( 'editingDowncast' ).add( downcastTableHeadingRowsChange() );
 
 		// Define all the commands.
 		editor.commands.add( 'insertTable', new InsertTableCommand( editor ) );

+ 12 - 94
packages/ckeditor5-table/tests/_utils/utils.js

@@ -3,21 +3,11 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable, { upcastTableCell } from '../../src/converters/upcasttable';
 import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import TableWalker from '../../src/tablewalker';
 
 const WIDGET_TABLE_CELL_CLASS = 'ck-editor__editable ck-editor__nested-editable';
-const BORDER_REG_EXP = /[\s\S]+/;
 
 /**
  * Returns a model representation of a table shorthand notation:
@@ -180,85 +170,6 @@ export function viewTable( tableData, attributes = {} ) {
 	return `<figure ${ figureAttributes }>${ asWidget ? widgetHandler : '' }<table>${ thead }${ tbody }</table></figure>`;
 }
 
-export function defaultSchema( schema, registerParagraph = true ) {
-	schema.register( 'table', {
-		allowWhere: '$block',
-		allowAttributes: [ 'headingRows', 'headingColumns' ],
-		isLimit: true,
-		isObject: true,
-		isBlock: true
-	} );
-
-	schema.register( 'tableRow', {
-		allowIn: 'table',
-		isLimit: true
-	} );
-
-	schema.register( 'tableCell', {
-		allowIn: 'tableRow',
-		allowAttributes: [ 'colspan', 'rowspan' ],
-		isObject: true
-	} );
-
-	// Allow all $block content inside table cell.
-	schema.extend( '$block', { allowIn: 'tableCell' } );
-
-	// Disallow table in table.
-	schema.addChildCheck( ( context, childDefinition ) => {
-		if ( childDefinition.name == 'table' && Array.from( context.getNames() ).includes( 'table' ) ) {
-			return false;
-		}
-	} );
-
-	if ( registerParagraph ) {
-		schema.register( 'paragraph', { inheritAllFrom: '$block' } );
-	}
-
-	// Styles
-	schema.extend( 'tableCell', {
-		allowAttributes: [ 'border' ]
-	} );
-}
-
-export function defaultConversion( conversion, asWidget = false ) {
-	conversion.elementToElement( { model: 'paragraph', view: 'p' } );
-
-	// Table conversion.
-	conversion.for( 'upcast' ).add( upcastTable() );
-	conversion.for( 'downcast' ).add( downcastInsertTable( { asWidget } ) );
-
-	// Table row conversion.
-	conversion.for( 'upcast' ).elementToElement( { model: 'tableRow', view: 'tr' } );
-	conversion.for( 'downcast' ).add( downcastInsertRow( { asWidget } ) );
-	conversion.for( 'downcast' ).add( downcastRemoveRow( { asWidget } ) );
-
-	// Table cell conversion.
-	conversion.for( 'upcast' ).add( upcastTableCell( 'td' ) );
-	conversion.for( 'upcast' ).add( upcastTableCell( 'th' ) );
-	conversion.for( 'downcast' ).add( downcastInsertCell( { asWidget } ) );
-
-	// Table attributes conversion.
-	conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-	conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-	conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange( { asWidget } ) );
-	conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange( { asWidget } ) );
-
-	// Styles
-	conversion.for( 'upcast' ).attributeToAttribute( {
-		view: {
-			name: 'td',
-			styles: {
-				border: BORDER_REG_EXP
-			}
-		},
-		model: {
-			key: 'border',
-			value: viewElement => viewElement.getStyle( 'border' )
-		}
-	} );
-}
-
 /**
  * An assertion helper for top-right-bottom-left attribute object.
  *
@@ -420,10 +331,10 @@ function formatAttributes( attributes ) {
 	let attributesString = '';
 
 	if ( attributes ) {
-		const entries = Object.entries( attributes );
+		const sortedKeys = Object.keys( attributes ).sort();
 
-		if ( entries.length ) {
-			attributesString = ' ' + entries.map( entry => `${ entry[ 0 ] }="${ entry[ 1 ] }"` ).join( ' ' );
+		if ( sortedKeys.length ) {
+			attributesString = ' ' + sortedKeys.map( key => `${ key }="${ attributes[ key ] }"` ).join( ' ' );
 		}
 	}
 
@@ -456,17 +367,24 @@ function makeRows( tableData, options ) {
 					delete tableCellData.isSelected;
 				}
 
-				const attributes = isObject ? tableCellData : {};
+				let attributes = {};
 
 				if ( asWidget ) {
 					attributes.class = getClassToSet( attributes );
 					attributes.contenteditable = 'true';
 				}
 
+				if ( isObject ) {
+					attributes = {
+						...attributes,
+						...tableCellData
+					};
+				}
+
 				if ( !( contents.replace( '[', '' ).replace( ']', '' ).startsWith( '<' ) ) && enforceWrapping ) {
 					contents =
 						`<${ wrappingElement == 'span' ? 'span style="display:inline-block"' : wrappingElement }>` +
-							contents +
+						contents +
 						`</${ wrappingElement }>`;
 				}
 

+ 51 - 20
packages/ckeditor5-table/tests/commands/insertcolumncommand.js

@@ -5,13 +5,15 @@
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 import HorizontalLineEditing from '@ckeditor/ckeditor5-horizontal-line/src/horizontallineediting';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
-import InsertColumnCommand from '../../src/commands/insertcolumncommand';
 import TableSelection from '../../src/tableselection';
-import { assertSelectedCells, defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
-import TableUtils from '../../src/tableutils';
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import TableEditing from '../../src/tableediting';
+import { assertSelectedCells, modelTable } from '../_utils/utils';
+
+import InsertColumnCommand from '../../src/commands/insertcolumncommand';
 
 describe( 'InsertColumnCommand', () => {
 	let editor, model, command;
@@ -19,14 +21,11 @@ describe( 'InsertColumnCommand', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils, TableSelection, HorizontalLineEditing ]
+				plugins: [ Paragraph, TableEditing, TableSelection, HorizontalLineEditing ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -168,18 +167,34 @@ describe( 'InsertColumnCommand', () => {
 			} );
 
 			it( 'should skip wide spanned columns', () => {
+				// +----+----+----+----+----+----+
+				// | 00 | 01 | 02 | 03 | 04 | 05 |
+				// +----+----+----+----+----+----+
+				// | 10 | 11 | 12      | 14 | 15 |
+				// +----+----+----+----+----+----+
+				// | 20                | 24      |
+				// +----+----+----+----+----+----+
+				//                     ^-- heading columns
 				setData( model, modelTable( [
-					[ '11', '12[]', '13', '14', '15' ],
-					[ '21', '22', { colspan: 2, contents: '23' }, '25' ],
-					[ { colspan: 4, contents: '31' }, { colspan: 2, contents: '34' } ]
+					[ '00', '01[]', '02', '03', '04', '05' ],
+					[ '10', '11', { contents: '12', colspan: 2 }, '14', '15' ],
+					[ { contents: '20', colspan: 4 }, { contents: '24', colspan: 2 } ]
 				], { headingColumns: 4 } ) );
 
 				command.execute();
 
+				// +----+----+----+----+----+----+----+
+				// | 00 | 01 |    | 02 | 03 | 04 | 05 |
+				// +----+----+----+----+----+----+----+
+				// | 10 | 11 |    | 12      | 14 | 15 |
+				// +----+----+----+----+----+----+----+
+				// | 20                     | 24      |
+				// +----+----+----+----+----+----+----+
+				//                          ^-- heading columns
 				assertEqualMarkup( getData( model ), modelTable( [
-					[ '11', '12[]', '', '13', '14', '15' ],
-					[ '21', '22', '', { colspan: 2, contents: '23' }, '25' ],
-					[ { colspan: 5, contents: '31' }, { colspan: 2, contents: '34' } ]
+					[ '00', '01[]', '', '02', '03', '04', '05' ],
+					[ '10', '11', '', { contents: '12', colspan: 2 }, '14', '15' ],
+					[ { contents: '20', colspan: 5 }, { contents: '24', colspan: 2 } ]
 				], { headingColumns: 5 } ) );
 			} );
 
@@ -335,18 +350,34 @@ describe( 'InsertColumnCommand', () => {
 			} );
 
 			it( 'should skip wide spanned columns', () => {
+				// +----+----+----+----+----+----+
+				// | 00 | 01 | 02 | 03 | 04 | 05 |
+				// +----+----+----+----+----+----+
+				// | 10 | 11 | 12      | 14 | 15 |
+				// +----+----+----+----+----+----+
+				// | 20                | 24      |
+				// +----+----+----+----+----+----+
+				//                     ^-- heading columns
 				setData( model, modelTable( [
-					[ '11', '12', '13[]', '14', '15' ],
-					[ '21', '22', { colspan: 2, contents: '23' }, '25' ],
-					[ { colspan: 4, contents: '31' }, { colspan: 2, contents: '34' } ]
+					[ '00', '01', '[]02', '03', '04', '05' ],
+					[ '10', '11', { contents: '12', colspan: 2 }, '14', '15' ],
+					[ { contents: '20', colspan: 4 }, { contents: '24', colspan: 2 } ]
 				], { headingColumns: 4 } ) );
 
 				command.execute();
 
+				// +----+----+----+----+----+----+----+
+				// | 00 | 01 |    | 02 | 03 | 04 | 05 |
+				// +----+----+----+----+----+----+----+
+				// | 10 | 11 |    | 12      | 14 | 15 |
+				// +----+----+----+----+----+----+----+
+				// | 20                     | 24      |
+				// +----+----+----+----+----+----+----+
+				//                          ^-- heading columns
 				assertEqualMarkup( getData( model ), modelTable( [
-					[ '11', '12', '', '13[]', '14', '15' ],
-					[ '21', '22', '', { colspan: 2, contents: '23' }, '25' ],
-					[ { colspan: 5, contents: '31' }, { colspan: 2, contents: '34' } ]
+					[ '00', '01', '', '[]02', '03', '04', '05' ],
+					[ '10', '11', '', { contents: '12', colspan: 2 }, '14', '15' ],
+					[ { contents: '20', colspan: 5 }, { contents: '24', colspan: 2 } ]
 				], { headingColumns: 5 } ) );
 			} );
 		} );

+ 71 - 22
packages/ckeditor5-table/tests/commands/insertrowcommand.js

@@ -5,13 +5,15 @@
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 import HorizontalLineEditing from '@ckeditor/ckeditor5-horizontal-line/src/horizontallineediting';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
-import InsertRowCommand from '../../src/commands/insertrowcommand';
+import TableEditing from '../../src/tableediting';
 import TableSelection from '../../src/tableselection';
-import { assertSelectedCells, defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
-import TableUtils from '../../src/tableutils';
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import { assertSelectedCells, modelTable } from '../_utils/utils';
+
+import InsertRowCommand from '../../src/commands/insertrowcommand';
 
 describe( 'InsertRowCommand', () => {
 	let editor, model, command;
@@ -19,14 +21,11 @@ describe( 'InsertRowCommand', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils, TableSelection, HorizontalLineEditing ]
+				plugins: [ Paragraph, TableEditing, TableSelection, HorizontalLineEditing ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -119,54 +118,104 @@ describe( 'InsertRowCommand', () => {
 			} );
 
 			it( 'should expand rowspan of a cell that overlaps inserted rows', () => {
+				// +----+----+----+----+
+				// | 00      | 02 | 03 |
+				// +----+----+----+----+ <-- heading rows
+				// | 10      | 12 | 13 |
+				// +         +----+----+
+				// |         | 22 | 23 |
+				// +----+----+----+----+
+				//                     ^-- heading columns
 				setData( model, modelTable( [
-					[ { colspan: 2, contents: '00' }, '02', '03' ],
-					[ { colspan: 2, rowspan: 4, contents: '10[]' }, '12', '13' ],
+					[ { contents: '00', colspan: 2 }, '02', '03' ],
+					[ { contents: '10[]', colspan: 2, rowspan: 2 }, '12', '13' ],
 					[ '22', '23' ]
 				], { headingColumns: 3, headingRows: 1 } ) );
 
 				command.execute();
 
+				// +----+----+----+----+
+				// | 00      | 02 | 03 |
+				// +----+----+----+----+ <-- heading rows
+				// | 10      | 12 | 13 |
+				// +         +----+----+
+				// |         |    |    |
+				// +         +----+----+
+				// |         | 22 | 23 |
+				// +----+----+----+----+
+				//                     ^-- heading columns
 				assertEqualMarkup( getData( model ), modelTable( [
-					[ { colspan: 2, contents: '00' }, '02', '03' ],
-					[ { colspan: 2, rowspan: 5, contents: '10[]' }, '12', '13' ],
+					[ { contents: '00', colspan: 2 }, '02', '03' ],
+					[ { contents: '10[]', colspan: 2, rowspan: 3 }, '12', '13' ],
 					[ '', '' ],
 					[ '22', '23' ]
 				], { headingColumns: 3, headingRows: 1 } ) );
 			} );
 
 			it( 'should not expand rowspan of a cell that does not overlaps inserted rows', () => {
+				// +----+----+----+
+				// | 00 | 01 | 02 |
+				// +    +----+----+
+				// |    | 11 | 12 |
+				// +----+----+----+ <-- heading rows
+				// | 20 | 21 | 22 |
+				// +----+----+----+
 				setData( model, modelTable( [
-					[ { rowspan: 2, contents: '00' }, '01', '02' ],
+					[ { contents: '00', rowspan: 2 }, '01', '02' ],
 					[ '11[]', '12' ],
 					[ '20', '21', '22' ]
-				], { headingColumns: 3, headingRows: 1 } ) );
+				], { headingRows: 2 } ) );
 
 				command.execute();
 
+				// +----+----+----+
+				// | 00 | 01 | 02 |
+				// +    +----+----+
+				// |    | 11 | 12 |
+				// +----+----+----+ <-- heading rows
+				// |    |    |    |
+				// +----+----+----+
+				// | 20 | 21 | 22 |
+				// +----+----+----+
 				assertEqualMarkup( getData( model ), modelTable( [
-					[ { rowspan: 2, contents: '00' }, '01', '02' ],
+					[ { contents: '00', rowspan: 2 }, '01', '02' ],
 					[ '11[]', '12' ],
 					[ '', '', '' ],
 					[ '20', '21', '22' ]
-				], { headingColumns: 3, headingRows: 1 } ) );
+				], { headingRows: 2 } ) );
 			} );
 
 			it( 'should properly calculate columns if next row has colspans', () => {
+				// +----+----+----+
+				// | 00 | 01 | 02 |
+				// +    +----+----+
+				// |    | 11 | 12 |
+				// +----+----+----+ <-- heading rows
+				// | 20           |
+				// +----+----+----+
 				setData( model, modelTable( [
-					[ { rowspan: 2, contents: '00' }, '01', '02' ],
+					[ { contents: '00', rowspan: 2 }, '01', '02' ],
 					[ '11[]', '12' ],
-					[ { colspan: 3, contents: '20' } ]
-				], { headingColumns: 3, headingRows: 1 } ) );
+					[ { contents: '20', colspan: 3 } ]
+				], { headingRows: 2 } ) );
 
 				command.execute();
 
+				// +----+----+----+
+				// | 00 | 01 | 02 |
+				// +    +----+----+
+				// |    | 11 | 12 |
+				// +----+----+----+ <-- heading rows
+				// |    |    |    |
+				// +----+----+----+
+				// | 20           |
+				// +----+----+----+
 				assertEqualMarkup( getData( model ), modelTable( [
-					[ { rowspan: 2, contents: '00' }, '01', '02' ],
+					[ { contents: '00', rowspan: 2 }, '01', '02' ],
 					[ '11[]', '12' ],
 					[ '', '', '' ],
-					[ { colspan: 3, contents: '20' } ]
-				], { headingColumns: 3, headingRows: 1 } ) );
+					[ { contents: '20', colspan: 3 } ]
+				], { headingRows: 2 } ) );
 			} );
 
 			it( 'should insert rows at the end of a table', () => {

+ 6 - 8
packages/ckeditor5-table/tests/commands/inserttablecommand.js

@@ -4,13 +4,14 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
-import InsertTableCommand from '../../src/commands/inserttablecommand';
-import TableUtils from '../../src/tableutils';
+import TableEditing from '../../src/tableediting';
+import { modelTable } from '../_utils/utils';
 
-import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import InsertTableCommand from '../../src/commands/inserttablecommand';
 
 describe( 'InsertTableCommand', () => {
 	let editor, model, command;
@@ -18,15 +19,12 @@ describe( 'InsertTableCommand', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils ]
+				plugins: [ Paragraph, TableEditing ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				command = new InsertTableCommand( editor );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 

+ 18 - 11
packages/ckeditor5-table/tests/commands/mergecellcommand.js

@@ -4,12 +4,14 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+
+import TableEditing from '../../src/tableediting';
+import { modelTable } from '../_utils/utils';
 
 import MergeCellCommand from '../../src/commands/mergecellcommand';
-import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
-import TableUtils from '../../src/tableutils';
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'MergeCellCommand', () => {
 	let editor, model, command, root;
@@ -17,15 +19,12 @@ describe( 'MergeCellCommand', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils ]
+				plugins: [ Paragraph, TableEditing ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				root = model.document.getRoot( 'main' );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -65,7 +64,9 @@ describe( 'MergeCellCommand', () => {
 
 			it( 'should be false if in a cell that has sibling but with different rowspan', () => {
 				setData( model, modelTable( [
-					[ { rowspan: 2, contents: '00[]' }, { rowspan: 3, contents: '01' } ]
+					[ { rowspan: 2, contents: '00[]' }, { rowspan: 3, contents: '01' }, '02' ],
+					[ '12' ],
+					[ '20', '22' ]
 				] ) );
 
 				expect( command.isEnabled ).to.be.false;
@@ -173,7 +174,9 @@ describe( 'MergeCellCommand', () => {
 
 			it( 'should be undefined if in a cell that has sibling but with different rowspan', () => {
 				setData( model, modelTable( [
-					[ { rowspan: 2, contents: '00[]' }, { rowspan: 3, contents: '01' } ]
+					[ { rowspan: 2, contents: '00[]' }, { rowspan: 3, contents: '01' }, '02' ],
+					[ '12' ],
+					[ '20', '22' ]
 				] ) );
 
 				expect( command.value ).to.be.undefined;
@@ -309,7 +312,9 @@ describe( 'MergeCellCommand', () => {
 
 			it( 'should be false if in a cell that has sibling but with different rowspan', () => {
 				setData( model, modelTable( [
-					[ { rowspan: 2, contents: '00' }, { rowspan: 3, contents: '01[]' } ]
+					[ { rowspan: 2, contents: '00' }, { rowspan: 3, contents: '01[]' } ],
+					[ '12' ],
+					[ '20', '22' ]
 				] ) );
 
 				expect( command.isEnabled ).to.be.false;
@@ -409,7 +414,9 @@ describe( 'MergeCellCommand', () => {
 
 			it( 'should be undefined if in a cell that has sibling but with different rowspan', () => {
 				setData( model, modelTable( [
-					[ { rowspan: 2, contents: '00' }, { rowspan: 3, contents: '01[]' } ]
+					[ { rowspan: 2, contents: '00' }, { rowspan: 3, contents: '01[]' } ],
+					[ '12' ],
+					[ '20', '22' ]
 				] ) );
 
 				expect( command.value ).to.be.undefined;

+ 7 - 8
packages/ckeditor5-table/tests/commands/removecolumncommand.js

@@ -4,13 +4,15 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
-import RemoveColumnCommand from '../../src/commands/removecolumncommand';
+import TableEditing from '../../src/tableediting';
 import TableSelection from '../../src/tableselection';
-import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
-import TableUtils from '../../src/tableutils';
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import { modelTable } from '../_utils/utils';
+
+import RemoveColumnCommand from '../../src/commands/removecolumncommand';
 
 describe( 'RemoveColumnCommand', () => {
 	let editor, model, command;
@@ -18,15 +20,12 @@ describe( 'RemoveColumnCommand', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils, TableSelection ]
+				plugins: [ Paragraph, TableEditing, TableSelection ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				command = new RemoveColumnCommand( editor );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 

+ 6 - 6
packages/ckeditor5-table/tests/commands/selectcolumncommand.js

@@ -4,26 +4,26 @@
  */
 
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
-import SelectColumnCommand from '../../src/commands/selectcolumncommand';
+import TableEditing from '../../src/tableediting';
 import TableSelection from '../../src/tableselection';
-import { assertSelectedCells, defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
+import { assertSelectedCells, modelTable } from '../_utils/utils';
+
+import SelectColumnCommand from '../../src/commands/selectcolumncommand';
 
 describe( 'SelectColumnCommand', () => {
 	let editor, model, modelRoot, command, tableSelection;
 
 	beforeEach( () => {
-		return VirtualTestEditor.create( { plugins: [ TableSelection ] } )
+		return VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing, TableSelection ] } )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				modelRoot = model.document.getRoot();
 				command = new SelectColumnCommand( editor );
 				tableSelection = editor.plugins.get( TableSelection );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 

+ 6 - 6
packages/ckeditor5-table/tests/commands/selectrowcommand.js

@@ -4,26 +4,26 @@
  */
 
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
-import SelectRowCommand from '../../src/commands/selectrowcommand';
+import TableEditing from '../../src/tableediting';
 import TableSelection from '../../src/tableselection';
-import { assertSelectedCells, defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
+import { assertSelectedCells, modelTable } from '../_utils/utils';
+
+import SelectRowCommand from '../../src/commands/selectrowcommand';
 
 describe( 'SelectRowCommand', () => {
 	let editor, model, modelRoot, command, tableSelection;
 
 	beforeEach( () => {
-		return VirtualTestEditor.create( { plugins: [ TableSelection ] } )
+		return VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing, TableSelection ] } )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				modelRoot = model.document.getRoot();
 				command = new SelectRowCommand( editor );
 				tableSelection = editor.plugins.get( TableSelection );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 

+ 7 - 8
packages/ckeditor5-table/tests/commands/setheadercolumncommand.js

@@ -4,13 +4,15 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
-import SetHeaderColumnCommand from '../../src/commands/setheadercolumncommand';
-import { assertSelectedCells, defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
 import TableSelection from '../../src/tableselection';
-import TableUtils from '../../src/tableutils';
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import TableEditing from '../../src/tableediting';
+import { assertSelectedCells, modelTable } from '../_utils/utils';
+
+import SetHeaderColumnCommand from '../../src/commands/setheadercolumncommand';
 
 describe( 'SetHeaderColumnCommand', () => {
 	let editor, model, command;
@@ -18,15 +20,12 @@ describe( 'SetHeaderColumnCommand', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils, TableSelection ]
+				plugins: [ Paragraph, TableEditing, TableSelection ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				command = new SetHeaderColumnCommand( editor );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 

+ 8 - 8
packages/ckeditor5-table/tests/commands/setheaderrowcommand.js

@@ -4,28 +4,28 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import SetHeaderRowCommand from '../../src/commands/setheaderrowcommand';
-import { assertSelectedCells, defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
-import TableSelection from '../../src/tableselection';
-import TableUtils from '../../src/tableutils';
 import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
+import TableEditing from '../../src/tableediting';
+import TableSelection from '../../src/tableselection';
+import { assertSelectedCells, modelTable } from '../_utils/utils';
+
+import SetHeaderRowCommand from '../../src/commands/setheaderrowcommand';
+
 describe( 'SetHeaderRowCommand', () => {
 	let editor, model, command;
 
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils, TableSelection ]
+				plugins: [ Paragraph, TableEditing, TableSelection ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				command = new SetHeaderRowCommand( editor );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 

+ 7 - 8
packages/ckeditor5-table/tests/commands/splitcellcommand.js

@@ -4,13 +4,15 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
-import SplitCellCommand from '../../src/commands/splitcellcommand';
-import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
+import TableEditing from '../../src/tableediting';
 import TableSelection from '../../src/tableselection';
-import TableUtils from '../../src/tableutils';
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import { modelTable } from '../_utils/utils';
+
+import SplitCellCommand from '../../src/commands/splitcellcommand';
 
 describe( 'SplitCellCommand', () => {
 	let editor, model, command;
@@ -18,15 +20,12 @@ describe( 'SplitCellCommand', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils, TableSelection ]
+				plugins: [ Paragraph, TableEditing, TableSelection ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				command = new SplitCellCommand( editor );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 

Разница между файлами не показана из-за своего большого размера
+ 353 - 533
packages/ckeditor5-table/tests/converters/downcast.js


+ 7 - 12
packages/ckeditor5-table/tests/converters/table-cell-refresh-post-fixer.js

@@ -5,16 +5,15 @@
 
 /* globals document */
 
-import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
-
-import { defaultConversion, defaultSchema, viewTable } from '../_utils/utils';
-import injectTableCellRefreshPostFixer from '../../src/converters/table-cell-refresh-post-fixer';
-
-import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
-
 import Delete from '@ckeditor/ckeditor5-typing/src/delete';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+
+import TableEditing from '../../src/tableediting';
+import { viewTable } from '../_utils/utils';
 
 describe( 'Table cell refresh post-fixer', () => {
 	let editor, model, doc, root, view, refreshItemSpy, element;
@@ -25,7 +24,7 @@ describe( 'Table cell refresh post-fixer', () => {
 		element = document.createElement( 'div' );
 		document.body.appendChild( element );
 
-		return ClassicTestEditor.create( element, { extraPlugins: [ Delete ] } )
+		return ClassicTestEditor.create( element, { plugins: [ Paragraph, TableEditing, Delete ] } )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
@@ -33,9 +32,6 @@ describe( 'Table cell refresh post-fixer', () => {
 				root = doc.getRoot( 'main' );
 				view = editor.editing.view;
 
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion, true );
-
 				editor.model.schema.register( 'block', {
 					inheritAllFrom: '$block'
 				} );
@@ -45,7 +41,6 @@ describe( 'Table cell refresh post-fixer', () => {
 				editor.conversion.attributeToAttribute( { model: 'foo', view: 'foo' } );
 				editor.conversion.attributeToAttribute( { model: 'bar', view: 'bar' } );
 
-				injectTableCellRefreshPostFixer( model );
 				refreshItemSpy = sinon.spy( model.document.differ, 'refreshItem' );
 			} );
 	} );

+ 123 - 171
packages/ckeditor5-table/tests/tableutils.js

@@ -4,57 +4,40 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-
-import { defaultConversion, defaultSchema, modelTable } from './_utils/utils';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 import TableEditing from '../src/tableediting';
+import { modelTable } from './_utils/utils';
+
 import TableUtils from '../src/tableutils';
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
-import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 
 describe( 'TableUtils', () => {
 	let editor, model, root, tableUtils;
 
+	beforeEach( () => {
+		return ModelTestEditor.create( {
+			plugins: [ Paragraph, TableEditing, TableUtils ]
+		} ).then( newEditor => {
+			editor = newEditor;
+			model = editor.model;
+			root = model.document.getRoot( 'main' );
+			tableUtils = editor.plugins.get( TableUtils );
+		} );
+	} );
+
 	afterEach( () => {
 		return editor.destroy();
 	} );
 
 	describe( '#pluginName', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
-			} );
-		} );
-
 		it( 'should provide plugin name', () => {
 			expect( TableUtils.pluginName ).to.equal( 'TableUtils' );
 		} );
 	} );
 
 	describe( 'getCellLocation()', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
-			} );
-		} );
-
 		it( 'should return proper table cell location', () => {
 			setData( model, modelTable( [
 				[ { rowspan: 2, colspan: 2, contents: '00[]' }, '02' ],
@@ -68,20 +51,6 @@ describe( 'TableUtils', () => {
 	} );
 
 	describe( 'insertRows()', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
-			} );
-		} );
-
 		it( 'should insert row in given table at given index', () => {
 			setData( model, modelTable( [
 				[ '11[]', '12' ],
@@ -147,60 +116,122 @@ describe( 'TableUtils', () => {
 		} );
 
 		it( 'should expand rowspan of a cell that overlaps inserted rows', () => {
+			// +----+----+----+----+
+			// | 00      | 02 | 03 |
+			// +----+----+----+----+ <-- heading rows
+			// | 10      | 12 | 13 |
+			// +         +----+----+
+			// |         | 22 | 23 |
+			// +----+----+----+----+
+			//                     ^-- heading columns
 			setData( model, modelTable( [
-				[ { colspan: 2, contents: '11[]' }, '13', '14' ],
-				[ { colspan: 2, rowspan: 4, contents: '21' }, '23', '24' ],
-				[ '33', '34' ]
+				[ { contents: '00', colspan: 2 }, '02', '03' ],
+				[ { contents: '10[]', colspan: 2, rowspan: 2 }, '12', '13' ],
+				[ '22', '23' ]
 			], { headingColumns: 3, headingRows: 1 } ) );
 
 			tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 2, rows: 3 } );
 
+			// +----+----+----+----+
+			// | 00      | 02 | 03 |
+			// +----+----+----+----+ <-- heading rows
+			// | 10      | 12 | 13 |
+			// +         +----+----+
+			// |         |    |    |
+			// +         +----+----+
+			// |         |    |    |
+			// +         +----+----+
+			// |         |    |    |
+			// +         +----+----+
+			// |         | 22 | 23 |
+			// +----+----+----+----+
+			//                     ^-- heading columns
 			assertEqualMarkup( getData( model ), modelTable( [
-				[ { colspan: 2, contents: '11[]' }, '13', '14' ],
-				[ { colspan: 2, rowspan: 7, contents: '21' }, '23', '24' ],
+				[ { contents: '00', colspan: 2 }, '02', '03' ],
+				[ { contents: '10[]', colspan: 2, rowspan: 5 }, '12', '13' ],
 				[ '', '' ],
 				[ '', '' ],
 				[ '', '' ],
-				[ '33', '34' ]
+				[ '22', '23' ]
 			], { headingColumns: 3, headingRows: 1 } ) );
 		} );
 
 		it( 'should not expand rowspan of a cell that does not overlaps inserted rows', () => {
+			// +----+----+----+
+			// | 00 | 01 | 02 |
+			// +    +----+----+
+			// |    | 11 | 12 |
+			// +----+----+----+ <-- heading rows
+			// | 20 | 21 | 22 |
+			// +----+----+----+
 			setData( model, modelTable( [
-				[ { rowspan: 2, contents: '11[]' }, '12', '13' ],
-				[ '22', '23' ],
-				[ '31', '32', '33' ]
-			], { headingColumns: 3, headingRows: 1 } ) );
+				[ { contents: '00', rowspan: 2 }, '01', '02' ],
+				[ '11[]', '12' ],
+				[ '20', '21', '22' ]
+			], { headingRows: 2 } ) );
 
 			tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 2, rows: 3 } );
 
+			// +----+----+----+
+			// | 00 | 01 | 02 |
+			// +    +----+----+
+			// |    | 11 | 12 |
+			// +----+----+----+ <-- heading rows
+			// |    |    |    |
+			// +----+----+----+
+			// |    |    |    |
+			// +----+----+----+
+			// |    |    |    |
+			// +----+----+----+
+			// | 20 | 21 | 22 |
+			// +----+----+----+
 			assertEqualMarkup( getData( model ), modelTable( [
-				[ { rowspan: 2, contents: '11[]' }, '12', '13' ],
-				[ '22', '23' ],
+				[ { contents: '00', rowspan: 2 }, '01', '02' ],
+				[ '11[]', '12' ],
 				[ '', '', '' ],
 				[ '', '', '' ],
 				[ '', '', '' ],
-				[ '31', '32', '33' ]
-			], { headingColumns: 3, headingRows: 1 } ) );
+				[ '20', '21', '22' ]
+			], { headingRows: 2 } ) );
 		} );
 
 		it( 'should properly calculate columns if next row has colspans', () => {
+			// +----+----+----+
+			// | 00 | 01 | 02 |
+			// +    +----+----+
+			// |    | 11 | 12 |
+			// +----+----+----+ <-- heading rows
+			// | 20           |
+			// +----+----+----+
 			setData( model, modelTable( [
-				[ { rowspan: 2, contents: '11[]' }, '12', '13' ],
-				[ '22', '23' ],
-				[ { colspan: 3, contents: '31' } ]
-			], { headingColumns: 3, headingRows: 1 } ) );
+				[ { contents: '00', rowspan: 2 }, '01', '02' ],
+				[ '11[]', '12' ],
+				[ { contents: '20', colspan: 3 } ]
+			], { headingRows: 2 } ) );
 
 			tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 2, rows: 3 } );
 
+			// +----+----+----+
+			// | 00 | 01 | 02 |
+			// +    +----+----+
+			// |    | 11 | 12 |
+			// +----+----+----+ <-- heading rows
+			// |    |    |    |
+			// +----+----+----+
+			// |    |    |    |
+			// +----+----+----+
+			// |    |    |    |
+			// +----+----+----+
+			// | 20           |
+			// +----+----+----+
 			assertEqualMarkup( getData( model ), modelTable( [
-				[ { rowspan: 2, contents: '11[]' }, '12', '13' ],
-				[ '22', '23' ],
+				[ { contents: '00', rowspan: 2 }, '01', '02' ],
+				[ '11[]', '12' ],
 				[ '', '', '' ],
 				[ '', '', '' ],
 				[ '', '', '' ],
-				[ { colspan: 3, contents: '31' } ]
-			], { headingColumns: 3, headingRows: 1 } ) );
+				[ { contents: '20', colspan: 3 } ]
+			], { headingRows: 2 } ) );
 		} );
 
 		it( 'should insert rows at the end of a table', () => {
@@ -304,20 +335,6 @@ describe( 'TableUtils', () => {
 	} );
 
 	describe( 'insertColumns()', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
-			} );
-		} );
-
 		it( 'should insert column in given table at given index', () => {
 			setData( model, modelTable( [
 				[ '11[]', '12' ],
@@ -465,18 +482,34 @@ describe( 'TableUtils', () => {
 		} );
 
 		it( 'should skip wide spanned columns', () => {
+			// +----+----+----+----+----+----+
+			// | 00 | 01 | 02 | 03 | 04 | 05 |
+			// +----+----+----+----+----+----+
+			// | 10 | 11 | 12      | 14 | 15 |
+			// +----+----+----+----+----+----+
+			// | 20                | 24      |
+			// +----+----+----+----+----+----+
+			//                     ^-- heading columns
 			setData( model, modelTable( [
-				[ '11[]', '12', '13', '14', '15' ],
-				[ '21', '22', { colspan: 2, contents: '23' }, '25' ],
-				[ { colspan: 4, contents: '31' }, { colspan: 2, contents: '34' } ]
+				[ '00', '01[]', '02', '03', '04', '05' ],
+				[ '10', '11', { contents: '12', colspan: 2 }, '14', '15' ],
+				[ { contents: '20', colspan: 4 }, { contents: '24', colspan: 2 } ]
 			], { headingColumns: 4 } ) );
 
 			tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 2, columns: 2 } );
 
+			// +----+----+----+----+----+----+----+----+
+			// | 00 | 01 |    |    | 02 | 03 | 04 | 05 |
+			// +----+----+----+----+----+----+----+----+
+			// | 10 | 11 |    |    | 12      | 14 | 15 |
+			// +----+----+----+----+----+----+----+----+
+			// | 20                          | 24      |
+			// +----+----+----+----+----+----+----+----+
+			//                               ^-- heading columns
 			assertEqualMarkup( getData( model ), modelTable( [
-				[ '11[]', '12', '', '', '13', '14', '15' ],
-				[ '21', '22', '', '', { colspan: 2, contents: '23' }, '25' ],
-				[ { colspan: 6, contents: '31' }, { colspan: 2, contents: '34' } ]
+				[ '00', '01[]', '', '', '02', '03', '04', '05' ],
+				[ '10', '11', '', '', { contents: '12', colspan: 2 }, '14', '15' ],
+				[ { contents: '20', colspan: 6 }, { contents: '24', colspan: 2 } ]
 			], { headingColumns: 6 } ) );
 		} );
 
@@ -523,20 +556,6 @@ describe( 'TableUtils', () => {
 	} );
 
 	describe( 'splitCellVertically()', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
-			} );
-		} );
-
 		it( 'should split table cell to given table cells number', () => {
 			setData( model, modelTable( [
 				[ '00', '01', '02' ],
@@ -681,20 +700,6 @@ describe( 'TableUtils', () => {
 	} );
 
 	describe( 'splitCellHorizontally()', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
-			} );
-		} );
-
 		it( 'should split table cell to default table cells number', () => {
 			setData( model, modelTable( [
 				[ '00', '01', '02' ],
@@ -835,7 +840,7 @@ describe( 'TableUtils', () => {
 		it( 'should split row-spanned & col-spanned cell', () => {
 			setData( model, modelTable( [
 				[ '00', { colspan: 2, contents: '01[]' } ],
-				[ '10', '11' ]
+				[ '10', '11', '12' ]
 			] ) );
 
 			const tableCell = root.getNodeByPath( [ 0, 0, 1 ] );
@@ -846,7 +851,7 @@ describe( 'TableUtils', () => {
 				[ { rowspan: 3, contents: '00' }, { colspan: 2, contents: '01[]' } ],
 				[ { colspan: 2, contents: '' } ],
 				[ { colspan: 2, contents: '' } ],
-				[ '10', '11' ]
+				[ '10', '11', '12' ]
 			] ) );
 		} );
 
@@ -870,20 +875,6 @@ describe( 'TableUtils', () => {
 	} );
 
 	describe( 'getColumns()', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
-			} );
-		} );
-
 		it( 'should return proper number of columns', () => {
 			setData( model, modelTable( [
 				[ '00', { colspan: 3, contents: '01' }, '04' ]
@@ -894,20 +885,6 @@ describe( 'TableUtils', () => {
 	} );
 
 	describe( 'getRows()', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
-			} );
-		} );
-
 		it( 'should return proper number of columns for simple table', () => {
 			setData( model, modelTable( [
 				[ '00', '01' ],
@@ -938,17 +915,6 @@ describe( 'TableUtils', () => {
 	} );
 
 	describe( 'removeRows()', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ Paragraph, TableEditing, TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-			} );
-		} );
-
 		describe( 'single row', () => {
 			it( 'should remove a given row from a table start', () => {
 				setData( model, modelTable( [
@@ -1289,20 +1255,6 @@ describe( 'TableUtils', () => {
 	} );
 
 	describe( 'removeColumns()', () => {
-		beforeEach( () => {
-			return ModelTestEditor.create( {
-				plugins: [ TableUtils ]
-			} ).then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				root = model.document.getRoot( 'main' );
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
-			} );
-		} );
-
 		describe( 'single row', () => {
 			it( 'should remove a given column', () => {
 				setData( model, modelTable( [

+ 5 - 6
packages/ckeditor5-table/tests/tablewalker.js

@@ -3,11 +3,13 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
-import { defaultConversion, defaultSchema, modelTable } from './_utils/utils';
+import TableEditing from '../src/tableediting';
+import { modelTable } from './_utils/utils';
 
 import TableWalker from '../src/tablewalker';
 
@@ -15,15 +17,12 @@ describe( 'TableWalker', () => {
 	let editor, model, doc, root;
 
 	beforeEach( () => {
-		return ModelTestEditor.create()
+		return ModelTestEditor.create( { plugins: [ Paragraph, TableEditing ] } )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				doc = model.document;
 				root = doc.getRoot( 'main' );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
 			} );
 	} );
 

+ 7 - 7
packages/ckeditor5-table/tests/utils/common.js

@@ -4,9 +4,12 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import TableUtils from '../../src/tableutils';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
+
+import TableEditing from '../../src/tableediting';
+import { modelTable } from '../_utils/utils';
+
 import { findAncestor, isHeadingColumnCell } from '../../src/utils/common';
 
 describe( 'table utils', () => {
@@ -14,16 +17,13 @@ describe( 'table utils', () => {
 	beforeEach( () => {
 		return ModelTestEditor
 			.create( {
-				plugins: [ TableUtils ]
+				plugins: [ Paragraph, TableEditing ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
 				model = editor.model;
 				modelRoot = model.document.getRoot();
-				tableUtils = editor.plugins.get( TableUtils );
-
-				defaultSchema( model.schema );
-				defaultConversion( editor.conversion );
+				tableUtils = editor.plugins.get( 'TableUtils' );
 			} );
 	} );
 

Некоторые файлы не были показаны из-за большого количества измененных файлов