浏览代码

Remove defaultSchema() and defaultConversion from table tests.

Maciej Gołaszewski 5 年之前
父节点
当前提交
83e6d67b03
共有 2 个文件被更改,包括 33 次插入156 次删除
  1. 0 89
      packages/ckeditor5-table/tests/_utils/utils.js
  2. 33 67
      packages/ckeditor5-table/tests/converters/downcast.js

+ 0 - 89
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.
  *

+ 33 - 67
packages/ckeditor5-table/tests/converters/downcast.js

@@ -11,7 +11,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
-import { defaultConversion, defaultSchema, modelTable, viewTable } from '../_utils/utils';
+import { modelTable, viewTable } from '../_utils/utils';
 
 function paragraphInTableCell() {
 	return dispatcher => dispatcher.on( 'insert:paragraph', ( evt, data, conversionApi ) => {
@@ -43,16 +43,26 @@ describe( 'downcast converters', () => {
 
 	testUtils.createSinonSandbox();
 
+	beforeEach( async () => {
+		editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } );
+
+		model = editor.model;
+		root = model.document.getRoot( 'main' );
+		view = editor.editing.view;
+	} );
+
+	afterEach( () => {
+		return editor.destroy();
+	} );
+
 	describe( 'downcastInsertTable()', () => {
-		beforeEach( () => {
-			return VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } )
-				.then( newEditor => {
-					editor = newEditor;
-					model = editor.model;
-					doc = model.document;
-					root = doc.getRoot( 'main' );
-					view = editor.editing.view;
-				} );
+		beforeEach( async () => {
+			editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } );
+
+			model = editor.model;
+			doc = model.document;
+			root = doc.getRoot( 'main' );
+			view = editor.editing.view;
 		} );
 
 		describe( 'editing pipeline', () => {
@@ -337,18 +347,6 @@ describe( 'downcast converters', () => {
 	} );
 
 	describe( 'downcastInsertRow()', () => {
-		// The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
-		beforeEach( () => {
-			return VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } )
-				.then( newEditor => {
-					editor = newEditor;
-					model = editor.model;
-					doc = model.document;
-					root = doc.getRoot( 'main' );
-					view = editor.editing.view;
-				} );
-		} );
-
 		// The insert row downcast conversion is not executed in data pipeline.
 		describe( 'editing pipeline', () => {
 			it( 'should react to changed rows', () => {
@@ -576,18 +574,6 @@ describe( 'downcast converters', () => {
 	} );
 
 	describe( 'downcastInsertCell()', () => {
-		// The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
-		beforeEach( () => {
-			return VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } )
-				.then( newEditor => {
-					editor = newEditor;
-					model = editor.model;
-					doc = model.document;
-					root = doc.getRoot( 'main' );
-					view = editor.editing.view;
-				} );
-		} );
-
 		// The insert table cell downcast conversion is not executed in data pipeline.
 		describe( 'editing pipeline', () => {
 			it( 'should add tableCell on proper index in tr', () => {
@@ -900,18 +886,6 @@ describe( 'downcast converters', () => {
 	} );
 
 	describe( 'downcastTableHeadingRowsChange()', () => {
-		// The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
-		beforeEach( () => {
-			return VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } )
-				.then( newEditor => {
-					editor = newEditor;
-					model = editor.model;
-					doc = model.document;
-					root = doc.getRoot( 'main' );
-					view = editor.editing.view;
-				} );
-		} );
-
 		// The heading rows change downcast conversion is not executed in data pipeline.
 		describe( 'editing pipeline', () => {
 			it( 'should work for adding heading rows', () => {
@@ -1122,15 +1096,6 @@ describe( 'downcast converters', () => {
 	} );
 
 	describe( 'downcastRemoveRow()', () => {
-		// The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
-		beforeEach( async () => {
-			editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } );
-
-			model = editor.model;
-			root = model.document.getRoot( 'main' );
-			view = editor.editing.view;
-		} );
-
 		// The remove row downcast conversion is not executed in data pipeline.
 		describe( 'editing pipeline', () => {
 			it( 'should react to removed row from the beginning of a body rows (no heading rows)', () => {
@@ -1374,20 +1339,21 @@ describe( 'downcast converters', () => {
 	} );
 
 	describe( 'options.asWidget=true', () => {
-		beforeEach( () => {
-			return VirtualTestEditor.create()
-				.then( newEditor => {
-					editor = newEditor;
-					model = editor.model;
-					doc = model.document;
-					root = doc.getRoot( 'main' );
-					view = editor.editing.view;
+		let editor;
 
-					defaultSchema( model.schema );
-					defaultConversion( editor.conversion, true );
+		beforeEach( async () => {
+			editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } )
 
-					editor.conversion.for( 'downcast' ).add( paragraphInTableCell() );
-				} );
+			model = editor.model;
+			doc = model.document;
+			root = doc.getRoot( 'main' );
+			view = editor.editing.view;
+
+			editor.conversion.for( 'downcast' ).add( paragraphInTableCell() );
+		} );
+
+		afterEach( () => {
+			return editor.destroy();
 		} );
 
 		it( 'should rename <span> to <p> when more then one block content inside table cell', () => {