瀏覽代碼

Increased operations CC.

Oskar Wróbel 8 年之前
父節點
當前提交
a802932151

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

@@ -398,6 +398,22 @@ describe( 'AttributeOperation', () => {
 		expect( root.getChild( 1 ).data ).to.equal( 'bcxyz' );
 	} );
 
+	it( 'should do nothing when attribute value is the same', () => {
+		root.insertChildren( 0, new Text( 'x', { foo: true } ) );
+
+		expect( () => {
+			doc.applyOperation( wrapInDelta(
+				new AttributeOperation(
+					new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
+					'foo',
+					true,
+					true,
+					doc.version
+				)
+			) );
+		} ).to.not.throw();
+	} );
+
 	describe( 'toJSON', () => {
 		it( 'should create proper serialized object', () => {
 			const range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) );

+ 17 - 1
packages/ckeditor5-engine/tests/model/operation/detachoperation.js

@@ -5,7 +5,7 @@
 
 import Document from '../../../src/model/document';
 import DetachOperation from '../../../src/model/operation/detachoperation';
-import { wrapInDelta } from '../../../tests/model/_utils/utils';
+import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import Position from '../../../src/model/position';
 
@@ -52,4 +52,20 @@ describe( 'DetachOperation', () => {
 
 		expect( op.isDocumentOperation ).to.false;
 	} );
+
+	describe( 'toJSON', () => {
+		it( 'should create proper json object', () => {
+			const position = Position.createBefore( element );
+			const op = new DetachOperation( position, 1, doc.version );
+
+			const serialized = jsonParseStringify( op );
+
+			expect( serialized ).to.deep.equal( {
+				__className: 'engine.model.operation.DetachOperation',
+				baseVersion: 0,
+				sourcePosition: jsonParseStringify( position ),
+				howMany: 1
+			} );
+		} );
+	} );
 } );

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

@@ -0,0 +1,26 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import Document from '../../../src/model/document';
+import NoOperation from '../../../src/model/operation/nooperation';
+import OperationFactory from '../../../src/model/operation/operationfactory';
+
+describe( 'OperationFactory', () => {
+	let doc;
+
+	beforeEach( () => {
+		doc = new Document();
+	} );
+
+	it( 'should create operation from JSON', () => {
+		const operation = OperationFactory.fromJSON( {
+			__className: 'engine.model.operation.NoOperation',
+			baseVersion: 0
+		}, doc );
+
+		expect( operation ).to.instanceof( NoOperation );
+		expect( operation.baseVersion ).to.equal( 0 );
+	} );
+} );

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

@@ -92,6 +92,14 @@ describe( 'RenameOperation', () => {
 		expect( clone.newName ).to.equal( newName );
 	} );
 
+	it( 'should do nothing when new name is the same as previous', () => {
+		const op = new RenameOperation( position, oldName, oldName, doc.version );
+
+		expect( () => {
+			doc.applyOperation( wrapInDelta( op ) );
+		} ).to.not.throw();
+	} );
+
 	describe( 'isDocumentOperation', () => {
 		it( 'should be true when target item is in the document', () => {
 			const op = new RenameOperation( position, oldName, newName, doc.version );