Kaynağa Gözat

Added missing tests.

Maciej Bukowski 8 yıl önce
ebeveyn
işleme
370a981bd1

+ 34 - 2
packages/ckeditor5-engine/tests/controller/insertcontent.js

@@ -17,11 +17,11 @@ describe( 'DataController', () => {
 
 	describe( 'insertContent', () => {
 		it( 'uses the passed batch', () => {
-			doc = new Document();
+			const doc = new Document();
 			doc.createRoot();
 			doc.schema.allow( { name: '$text', inside: '$root' } );
 
-			dataController = new DataController( doc );
+			const dataController = new DataController( doc );
 
 			const batch = doc.batch();
 
@@ -32,6 +32,36 @@ describe( 'DataController', () => {
 			expect( batch.deltas.length ).to.be.above( 0 );
 		} );
 
+		it( 'accepts DocumentFragment' , () => {
+			const doc = new Document();
+			const dataController = new DataController( doc );
+			const batch = doc.batch();
+
+			doc.createRoot();
+			doc.schema.allow( { name: '$text', inside: '$root' } );
+
+			setData( doc, 'x[]x' );
+
+			insertContent( dataController, new DocumentFragment( [ new Text( 'a' ) ] ), doc.selection, batch );
+
+			expect( getData( doc ) ).to.equal( 'xa[]x' );
+		} );
+
+		it( 'accepts Item' , () => {
+			const doc = new Document();
+			const dataController = new DataController( doc );
+			const batch = doc.batch();
+
+			doc.createRoot();
+			doc.schema.allow( { name: '$text', inside: '$root' } );
+
+			setData( doc, 'x[]x' );
+
+			insertContent( dataController, new Text( 'a' ), doc.selection, batch );
+
+			expect( getData( doc ) ).to.equal( 'xa[]x' );
+		} );
+
 		describe( 'in simple scenarios', () => {
 			beforeEach( () => {
 				doc = new Document();
@@ -604,6 +634,8 @@ describe( 'DataController', () => {
 		} );
 	} );
 
+	// Helper function that parses given content and inserts it at the cursor position.
+	//
 	// @param {module:engine/model/item~Item|String} content
 	function insertHelper( content ) {
 		if ( typeof content == 'string' ) {