浏览代码

Tests: Add test for `asWidget` option of `downcastInsertTable()`.

Maciej Gołaszewski 7 年之前
父节点
当前提交
8a8fe04830
共有 1 个文件被更改,包括 60 次插入0 次删除
  1. 60 0
      packages/ckeditor5-table/tests/converters/downcast.js

+ 60 - 0
packages/ckeditor5-table/tests/converters/downcast.js

@@ -255,6 +255,66 @@ describe( 'downcast converters', () => {
 				);
 			} );
 		} );
+
+		describe( 'asWidget', () => {
+			beforeEach( () => {
+				return VirtualTestEditor.create()
+					.then( newEditor => {
+						editor = newEditor;
+						model = editor.model;
+						doc = model.document;
+						root = doc.getRoot( 'main' );
+						viewDocument = editor.editing.view;
+
+						const conversion = editor.conversion;
+						const schema = model.schema;
+
+						schema.register( 'table', {
+							allowWhere: '$block',
+							allowAttributes: [ 'headingRows', 'headingColumns' ],
+							isBlock: true,
+							isObject: true
+						} );
+
+						schema.register( 'tableRow', {
+							allowIn: 'table',
+							allowAttributes: [],
+							isBlock: true,
+							isLimit: true
+						} );
+
+						schema.register( 'tableCell', {
+							allowIn: 'tableRow',
+							allowContentOf: '$block',
+							allowAttributes: [ 'colspan', 'rowspan' ],
+							isBlock: true,
+							isLimit: true
+						} );
+
+						conversion.for( 'editingDowncast' ).add( downcastInsertTable( { asWidget: true } ) );
+						conversion.for( 'dataDowncast' ).add( downcastInsertTable() );
+
+						conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
+						conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
+					} );
+			} );
+
+			it( 'should create table as a widget', () => {
+				setModelData( model,
+					'<table>' +
+					'<tableRow><tableCell></tableCell></tableRow>' +
+					'</table>'
+				);
+
+				expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
+					'<table class="ck-editor__editable ck-editor__nested-editable ck-widget" contenteditable="true">' +
+					'<tbody>' +
+					'<tr><td></td></tr>' +
+					'</tbody>' +
+					'</table>'
+				);
+			} );
+		} );
 	} );
 
 	describe( 'downcastInsertRow()', () => {