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

Merge pull request #929 from ckeditor/t/895

Internal: Added missing test and updated docs in the `DataController#insertContent()`. Closes #895.
Piotrek Koszuliński 8 лет назад
Родитель
Сommit
cf37dacf88

+ 2 - 2
packages/ckeditor5-engine/src/controller/datacontroller.js

@@ -251,7 +251,7 @@ export default class DataController {
 	 * See {@link module:engine/controller/insertcontent~insertContent}.
 	 *
 	 * @fires insertContent
-	 * @param {module:engine/model/documentfragment~DocumentFragment} content The content to insert.
+	 * @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert.
 	 * @param {module:engine/model/selection~Selection} selection Selection into which the content should be inserted.
 	 * @param {module:engine/model/batch~Batch} [batch] Batch to which deltas will be added. If not specified, then
 	 * changes will be added to a new batch.
@@ -316,7 +316,7 @@ mix( DataController, EmitterMixin );
  *
  * @event insertContent
  * @param {Object} data
- * @param {module:engine/view/documentfragment~DocumentFragment} data.content The content to insert.
+ * @param {module:engine/view/documentfragment~DocumentFragment||module:engine/model/item~Item} data.content The content to insert.
  * @param {module:engine/model/selection~Selection} data.selection Selection into which the content should be inserted.
  * @param {module:engine/model/batch~Batch} [data.batch] Batch to which deltas will be added.
  */

+ 15 - 1
packages/ckeditor5-engine/tests/controller/datacontroller.js

@@ -43,7 +43,7 @@ describe( 'DataController', () => {
 			expect( data.processor ).to.be.undefined;
 		} );
 
-		it( 'should add insertContent listener', () => {
+		it( 'should add insertContent listener and inserts document fragment when event fires', () => {
 			const batch = modelDocument.batch();
 			const content = new ModelDocumentFragment( [ new ModelText( 'x' ) ] );
 
@@ -57,6 +57,20 @@ describe( 'DataController', () => {
 			expect( batch.deltas.length ).to.be.above( 0 );
 		} );
 
+		it( 'should add insertContent listener and inserts an item when event fires', () => {
+			const batch = modelDocument.batch();
+			const content = new ModelText( 'x' );
+
+			schema.registerItem( 'paragraph', '$block' );
+
+			setData( modelDocument, '<paragraph>a[]b</paragraph>' );
+
+			data.fire( 'insertContent', { content, selection: modelDocument.selection, batch } );
+
+			expect( getData( modelDocument ) ).to.equal( '<paragraph>ax[]b</paragraph>' );
+			expect( batch.deltas.length ).to.be.above( 0 );
+		} );
+
 		it( 'should add deleteContent listener', () => {
 			schema.registerItem( 'paragraph', '$block' );