Преглед на файлове

Add 'is()' method to operations.

Mateusz Samsel преди 6 години
родител
ревизия
90c3e45662
променени са 22 файла, в които са добавени 376 реда и са изтрити 0 реда
  1. 7 0
      packages/ckeditor5-engine/src/model/operation/attributeoperation.js
  2. 7 0
      packages/ckeditor5-engine/src/model/operation/detachoperation.js
  3. 7 0
      packages/ckeditor5-engine/src/model/operation/insertoperation.js
  4. 7 0
      packages/ckeditor5-engine/src/model/operation/markeroperation.js
  5. 7 0
      packages/ckeditor5-engine/src/model/operation/mergeoperation.js
  6. 7 0
      packages/ckeditor5-engine/src/model/operation/moveoperation.js
  7. 7 0
      packages/ckeditor5-engine/src/model/operation/nooperation.js
  8. 28 0
      packages/ckeditor5-engine/src/model/operation/operation.js
  9. 7 0
      packages/ckeditor5-engine/src/model/operation/renameoperation.js
  10. 9 0
      packages/ckeditor5-engine/src/model/operation/rootattributeoperation.js
  11. 7 0
      packages/ckeditor5-engine/src/model/operation/splitoperation.js
  12. 31 0
      packages/ckeditor5-engine/tests/model/operation/attributeoperation.js
  13. 25 0
      packages/ckeditor5-engine/tests/model/operation/detachoperation.js
  14. 25 0
      packages/ckeditor5-engine/tests/model/operation/insertoperation.js
  15. 24 0
      packages/ckeditor5-engine/tests/model/operation/markeroperation.js
  16. 26 0
      packages/ckeditor5-engine/tests/model/operation/mergeoperation.js
  17. 26 0
      packages/ckeditor5-engine/tests/model/operation/moveoperation.js
  18. 18 0
      packages/ckeditor5-engine/tests/model/operation/nooperation.js
  19. 22 0
      packages/ckeditor5-engine/tests/model/operation/operation.js
  20. 24 0
      packages/ckeditor5-engine/tests/model/operation/renameoperation.js
  21. 30 0
      packages/ckeditor5-engine/tests/model/operation/rootattributeoperation.js
  22. 25 0
      packages/ckeditor5-engine/tests/model/operation/splitoperation.js

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/attributeoperation.js

@@ -110,6 +110,13 @@ export default class AttributeOperation extends Operation {
 	/**
 	/**
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
+	is( type ) {
+		return type == 'attributeOperation' || type == 'model:operation:attribute' || super.is( type );
+	}
+
+	/**
+	 * @inheritDoc
+	 */
 	toJSON() {
 	toJSON() {
 		const json = super.toJSON();
 		const json = super.toJSON();
 
 

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/detachoperation.js

@@ -55,6 +55,13 @@ export default class DetachOperation extends Operation {
 	/**
 	/**
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
+	is( type ) {
+		return type == 'detachOperation' || type == 'model:operation:detach' || super.is( type );
+	}
+
+	/**
+	 * @inheritDoc
+	 */
 	toJSON() {
 	toJSON() {
 		const json = super.toJSON();
 		const json = super.toJSON();
 
 

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/insertoperation.js

@@ -77,6 +77,13 @@ export default class InsertOperation extends Operation {
 	}
 	}
 
 
 	/**
 	/**
+	 * @inheritDoc
+	 */
+	is( type ) {
+		return type == 'insertOperation' || type == 'model:operation:insert' || super.is( type );
+	}
+
+	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 *
 	 * @returns {module:engine/model/operation/insertoperation~InsertOperation} Clone of this operation.
 	 * @returns {module:engine/model/operation/insertoperation~InsertOperation} Clone of this operation.

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/markeroperation.js

@@ -77,6 +77,13 @@ export default class MarkerOperation extends Operation {
 	}
 	}
 
 
 	/**
 	/**
+	 * @inheritDoc
+	 */
+	is( type ) {
+		return type == 'markerOperation' || type == 'model:operation:marker' || super.is( type );
+	}
+
+	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 *
 	 * @returns {module:engine/model/operation/markeroperation~MarkerOperation} Clone of this operation.
 	 * @returns {module:engine/model/operation/markeroperation~MarkerOperation} Clone of this operation.

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/mergeoperation.js

@@ -105,6 +105,13 @@ export default class MergeOperation extends Operation {
 	}
 	}
 
 
 	/**
 	/**
+	 * @inheritDoc
+	 */
+	is( type ) {
+		return type == 'mergeOperation' || type == 'model:operation:merge' || super.is( type );
+	}
+
+	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 *
 	 * @returns {module:engine/model/operation/mergeoperation~MergeOperation} Clone of this operation.
 	 * @returns {module:engine/model/operation/mergeoperation~MergeOperation} Clone of this operation.

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/moveoperation.js

@@ -74,6 +74,13 @@ export default class MoveOperation extends Operation {
 	}
 	}
 
 
 	/**
 	/**
+	 * @inheritDoc
+	 */
+	is( type ) {
+		return type == 'moveOperation' || type == 'model:operation:move' || super.is( type );
+	}
+
+	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 *
 	 * @returns {module:engine/model/operation/moveoperation~MoveOperation} Clone of this operation.
 	 * @returns {module:engine/model/operation/moveoperation~MoveOperation} Clone of this operation.

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/nooperation.js

@@ -25,6 +25,13 @@ export default class NoOperation extends Operation {
 	}
 	}
 
 
 	/**
 	/**
+	 * @inheritDoc
+	 */
+	is( type ) {
+		return type == 'noOperation' || type == 'model:operation:no' || super.is( type );
+	}
+
+	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 *
 	 * @returns {module:engine/model/operation/nooperation~NoOperation} Clone of this operation.
 	 * @returns {module:engine/model/operation/nooperation~NoOperation} Clone of this operation.

+ 28 - 0
packages/ckeditor5-engine/src/model/operation/operation.js

@@ -82,6 +82,34 @@ export default class Operation {
 	}
 	}
 
 
 	/**
 	/**
+	 * Checks whether given object is of `operation` type. This method is useful when processing operations are of unknown type.
+	 * This method can be used to check what type of operation is returned. General rules how to check operation are presented for
+	 * attribute operation. You need to use analogical syntax for other {@link module:engine/model/operation/operation~Operation}.
+	 *
+	 * 	// Examples for AttributeOperation.
+	 * 	operation.is( 'operation' ) // true for any operation
+	 * 	operation.is( 'model:operation' ) // true for any operation
+	 * 	operation.is( 'attributeOperation' ) // true for AttributeOperation
+	 * 	operation.is( 'model:operation:attribute' ) // true for AttributeOperation
+	 *
+	 * 	// Random examples for other Operations
+	 * 	operation.is( 'model:operation:no ) // true for no-operation
+	 * 	operation.is( 'noOperation' ) // true for no-operation
+	 * 	operation.is( 'model:operation:marker ) // true for marker operation
+	 * 	operation.is( 'insertOperation' ) // true for insert operation
+	 * 	operation.is( 'model:operation:rootAttribute' ) // true for rootAttributeOperation
+	 *
+	 * 	// Disallowed syntax
+	 * 	operation.is( 'operation:attribute' ) // will always return false
+	 *
+	 * @param {String} type
+	 * @returns {Boolean}
+	 */
+	is( type ) {
+		return type == 'operation' || type == 'model:operation';
+	}
+
+	/**
 	 * Checks whether the operation's parameters are correct and the operation can be correctly executed. Throws
 	 * Checks whether the operation's parameters are correct and the operation can be correctly executed. Throws
 	 * an error if operation is not valid.
 	 * an error if operation is not valid.
 	 *
 	 *

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/renameoperation.js

@@ -64,6 +64,13 @@ export default class RenameOperation extends Operation {
 	}
 	}
 
 
 	/**
 	/**
+	 * @inheritDoc
+	 */
+	is( type ) {
+		return type == 'renameOperation' || type == 'model:operation:rename' || super.is( type );
+	}
+
+	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 *
 	 * @returns {module:engine/model/operation/renameoperation~RenameOperation} Clone of this operation.
 	 * @returns {module:engine/model/operation/renameoperation~RenameOperation} Clone of this operation.

+ 9 - 0
packages/ckeditor5-engine/src/model/operation/rootattributeoperation.js

@@ -84,6 +84,15 @@ export default class RootAttributeOperation extends Operation {
 	}
 	}
 
 
 	/**
 	/**
+	 * @inheritDoc
+	 */
+	is( type ) {
+		return type == 'rootAttributeOperation' ||
+			type == 'model:operation:rootAttribute' ||
+			super.is( type );
+	}
+
+	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 *
 	 * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation} Clone of this operation.
 	 * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation} Clone of this operation.

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/splitoperation.js

@@ -112,6 +112,13 @@ export default class SplitOperation extends Operation {
 	}
 	}
 
 
 	/**
 	/**
+	 * @inheritDoc
+	 */
+	is( type ) {
+		return type == 'splitOperation' || type == 'model:operation:split' || super.is( type );
+	}
+
+	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 *
 	 * @returns {module:engine/model/operation/splitoperation~SplitOperation} Clone of this operation.
 	 * @returns {module:engine/model/operation/splitoperation~SplitOperation} Clone of this operation.

+ 31 - 0
packages/ckeditor5-engine/tests/model/operation/attributeoperation.js

@@ -60,6 +60,37 @@ describe( 'AttributeOperation', () => {
 		} );
 		} );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			const range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) );
+			operation = new AttributeOperation(
+				range,
+				'key',
+				null,
+				'newValue',
+				doc.version
+			);
+		} );
+
+		it( 'should return true for all valid names of "attribute" operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+			expect( operation.is( 'attributeOperation' ) ).to.be.true;
+			expect( operation.is( 'model:operation:attribute' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:attribute' ) ).to.be.false;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'detachOperation' ) ).to.be.false;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	it( 'should insert attribute to the set of nodes', () => {
 	it( 'should insert attribute to the set of nodes', () => {
 		root._insertChild( 0, new Text( 'bar' ) );
 		root._insertChild( 0, new Text( 'bar' ) );
 
 

+ 25 - 0
packages/ckeditor5-engine/tests/model/operation/detachoperation.js

@@ -35,6 +35,31 @@ describe( 'DetachOperation', () => {
 		expect( docFrag.childCount ).to.equal( 0 );
 		expect( docFrag.childCount ).to.equal( 0 );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			const position = Position._createBefore( element );
+			operation = new DetachOperation( position, 1 );
+		} );
+
+		it( 'should return true for all valid names of "detach" operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+			expect( operation.is( 'detachOperation' ) ).to.be.true;
+			expect( operation.is( 'model:operation:detach' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:detach' ) ).to.be.false;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'attributeOperation' ) ).to.be.false;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( '_validate()', () => {
 	describe( '_validate()', () => {
 		it( 'should throw when is executed on element from document', () => {
 		it( 'should throw when is executed on element from document', () => {
 			const root = doc.createRoot();
 			const root = doc.createRoot();

+ 25 - 0
packages/ckeditor5-engine/tests/model/operation/insertoperation.js

@@ -220,6 +220,31 @@ describe( 'InsertOperation', () => {
 		expect( op2.nodes.getNode( 0 ) ).not.to.equal( text );
 		expect( op2.nodes.getNode( 0 ) ).not.to.equal( text );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			const position = new Position( root, [ 0 ] );
+			operation = new InsertOperation( position, new Text( 'x' ), doc.version );
+		} );
+
+		it( 'should return true for all valid names of "insert" operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+			expect( operation.is( 'insertOperation' ) ).to.be.true;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:insert' ) ).to.be.false;
+			expect( operation.is( 'model:operation:attribute' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'detachOperation' ) ).to.be.false;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( '_validate()', () => {
 	describe( '_validate()', () => {
 		it( 'should throw an error if target position does not exist', () => {
 		it( 'should throw an error if target position does not exist', () => {
 			const element = new Element( 'p' );
 			const element = new Element( 'p' );

+ 24 - 0
packages/ckeditor5-engine/tests/model/operation/markeroperation.js

@@ -130,6 +130,30 @@ describe( 'MarkerOperation', () => {
 		expect( clone ).to.deep.equal( op );
 		expect( clone ).to.deep.equal( op );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			operation = new MarkerOperation( 'name', null, range, model.markers, true, doc.version );
+		} );
+
+		it( 'should return true for all valid names of "marker" operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+			expect( operation.is( 'markerOperation' ) ).to.be.true;
+			expect( operation.is( 'model:operation:marker' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:marker' ) ).to.be.false;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'detachOperation' ) ).to.be.false;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 	describe( 'toJSON', () => {
 		it( 'should create proper serialized object', () => {
 		it( 'should create proper serialized object', () => {
 			const op = new MarkerOperation( 'name', null, range, model.markers, true, doc.version );
 			const op = new MarkerOperation( 'name', null, range, model.markers, true, doc.version );

+ 26 - 0
packages/ckeditor5-engine/tests/model/operation/mergeoperation.js

@@ -195,6 +195,32 @@ describe( 'MergeOperation', () => {
 		expect( clone.baseVersion ).to.equal( baseVersion );
 		expect( clone.baseVersion ).to.equal( baseVersion );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			const sourcePosition = new Position( root, [ 1, 0 ] );
+			const targetPosition = new Position( root, [ 0, 3 ] );
+			operation = new MergeOperation( sourcePosition, 1, targetPosition, gyPos, doc.version );
+		} );
+
+		it( 'should return true for all valid names of "merge" operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+			expect( operation.is( 'mergeOperation' ) ).to.be.true;
+			expect( operation.is( 'model:operation:merge' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:merge' ) ).to.be.false;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'detachOperation' ) ).to.be.false;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 	describe( 'toJSON', () => {
 		it( 'should create proper json object', () => {
 		it( 'should create proper json object', () => {
 			const sourcePosition = new Position( root, [ 1, 0 ] );
 			const sourcePosition = new Position( root, [ 1, 0 ] );

+ 26 - 0
packages/ckeditor5-engine/tests/model/operation/moveoperation.js

@@ -264,6 +264,32 @@ describe( 'MoveOperation', () => {
 		} );
 		} );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			const sourcePosition = new Position( root, [ 0, 0 ] );
+			const targetPosition = new Position( root, [ 1, 0 ] );
+			operation = new MoveOperation( sourcePosition, 1, targetPosition, doc.version );
+		} );
+
+		it( 'should return true for all valid names of "move" operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+			expect( operation.is( 'moveOperation' ) ).to.be.true;
+			expect( operation.is( 'model:operation:move' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:move' ) ).to.be.false;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'detachOperation' ) ).to.be.false;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 	describe( 'toJSON', () => {
 		it( 'should create proper json object', () => {
 		it( 'should create proper json object', () => {
 			const sourcePosition = new Position( root, [ 0, 0 ] );
 			const sourcePosition = new Position( root, [ 0, 0 ] );

+ 18 - 0
packages/ckeditor5-engine/tests/model/operation/nooperation.js

@@ -33,6 +33,24 @@ describe( 'NoOperation', () => {
 		expect( clone.baseVersion ).to.equal( 0 );
 		expect( clone.baseVersion ).to.equal( 0 );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		it( 'should return true for all valid names of "no" operation', () => {
+			expect( noop.is( 'operation' ) ).to.be.true;
+			expect( noop.is( 'model:operation' ) ).to.be.true;
+			expect( noop.is( 'noOperation' ) ).to.be.true;
+			expect( noop.is( 'model:operation:no' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( noop.is( 'operation:no' ) ).to.be.false;
+			expect( noop.is( 'model:operation:insert' ) ).to.be.false;
+			expect( noop.is( 'attributeOperation' ) ).to.be.false;
+			expect( noop.is( 'detachOperation' ) ).to.be.false;
+			expect( noop.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( noop.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 	describe( 'toJSON', () => {
 		it( 'should create proper json object', () => {
 		it( 'should create proper json object', () => {
 			const serialized = noop.toJSON();
 			const serialized = noop.toJSON();

+ 22 - 0
packages/ckeditor5-engine/tests/model/operation/operation.js

@@ -27,6 +27,28 @@ describe( 'Operation', () => {
 		} );
 		} );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			operation = new Operation( null );
+		} );
+
+		it( 'should return true for all valid names of operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:attribute' ) ).to.be.false;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'detachOperation' ) ).to.be.false;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 	describe( 'toJSON', () => {
 		it( 'should create proper json object #1', () => {
 		it( 'should create proper json object #1', () => {
 			const op = new Operation( 4 );
 			const op = new Operation( 4 );

+ 24 - 0
packages/ckeditor5-engine/tests/model/operation/renameoperation.js

@@ -103,6 +103,30 @@ describe( 'RenameOperation', () => {
 		expect( clone.newName ).to.equal( newName );
 		expect( clone.newName ).to.equal( newName );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			operation = new RenameOperation( Position._createAt( root, 'end' ), oldName, newName, doc.version );
+		} );
+
+		it( 'should return true for all valid names of "rename" operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+			expect( operation.is( 'renameOperation' ) ).to.be.true;
+			expect( operation.is( 'model:operation:rename' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:rename' ) ).to.be.false;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'detachOperation' ) ).to.be.false;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 	describe( 'toJSON', () => {
 		it( 'should create proper serialized object', () => {
 		it( 'should create proper serialized object', () => {
 			const op = new RenameOperation( Position._createAt( root, 'end' ), oldName, newName, doc.version );
 			const op = new RenameOperation( Position._createAt( root, 'end' ), oldName, newName, doc.version );

+ 30 - 0
packages/ckeditor5-engine/tests/model/operation/rootattributeoperation.js

@@ -257,6 +257,36 @@ describe( 'RootAttributeOperation', () => {
 		expect( clone.baseVersion ).to.equal( baseVersion );
 		expect( clone.baseVersion ).to.equal( baseVersion );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			operation = new RootAttributeOperation(
+				root,
+				'key',
+				null,
+				'newValue',
+				doc.version
+			);
+		} );
+
+		it( 'should return true for all valid names of "rootAttribute" operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.true;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:rootAttribute' ) ).to.be.false;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'detachOperation' ) ).to.be.false;
+			expect( operation.is( 'attributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:attribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 	describe( 'toJSON', () => {
 		it( 'should create proper serialized object', () => {
 		it( 'should create proper serialized object', () => {
 			const op = new RootAttributeOperation(
 			const op = new RootAttributeOperation(

+ 25 - 0
packages/ckeditor5-engine/tests/model/operation/splitoperation.js

@@ -201,6 +201,31 @@ describe( 'SplitOperation', () => {
 		expect( clone.baseVersion ).to.equal( baseVersion );
 		expect( clone.baseVersion ).to.equal( baseVersion );
 	} );
 	} );
 
 
+	describe( 'is()', () => {
+		let operation;
+
+		before( () => {
+			const position = new Position( root, [ 0, 3 ] );
+			operation = new SplitOperation( position, 2, null, doc.version );
+		} );
+
+		it( 'should return true for all valid names of "split" operation', () => {
+			expect( operation.is( 'operation' ) ).to.be.true;
+			expect( operation.is( 'model:operation' ) ).to.be.true;
+			expect( operation.is( 'splitOperation' ) ).to.be.true;
+			expect( operation.is( 'model:operation:split' ) ).to.be.true;
+		} );
+
+		it( 'should return false for invalid parameters', () => {
+			expect( operation.is( 'operation:split' ) ).to.be.false;
+			expect( operation.is( 'model:operation:insert' ) ).to.be.false;
+			expect( operation.is( 'noOperation' ) ).to.be.false;
+			expect( operation.is( 'detachOperation' ) ).to.be.false;
+			expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
+			expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 	describe( 'toJSON', () => {
 		it( 'should create proper json object #1', () => {
 		it( 'should create proper json object #1', () => {
 			const position = new Position( root, [ 0, 3 ] );
 			const position = new Position( root, [ 0, 3 ] );