Bläddra i källkod

Tests: operation.type, document.applyTransformation.

Piotr Jasiun 10 år sedan
förälder
incheckning
d00ea2fb70

+ 8 - 9
packages/ckeditor5-utils/tests/document/document.js

@@ -77,30 +77,29 @@ describe( 'Document', () => {
 	} );
 
 	describe( 'applyOperation', () => {
-		it( 'should increase document version, execute operation and fire operationApplied', () => {
-			let operationApplied = sinon.spy();
+		it( 'should increase document version and execute operation', () => {
+			let changeCallback = sinon.spy();
 			let operation = {
+				type: 't',
 				baseVersion: 0,
-				_execute: sinon.spy()
+				_execute: sinon.stub().returns( { data: 'x' } )
 			};
 
-			document.on( 'operationApplied', operationApplied );
-
+			document.on( 'change', changeCallback );
 			document.applyOperation( operation );
 
 			expect( document.version ).to.equal( 1 );
-			sinon.assert.calledOnce( operationApplied );
 			sinon.assert.calledOnce( operation._execute );
+
+			sinon.assert.calledOnce( changeCallback );
+			expect( changeCallback.args[ 0 ][ 1 ] ).to.deep.equal( { data: 'x', type: 't' } );
 		} );
 
 		it( 'should throw an error on the operation base version and the document version is different', () => {
-			let operationApplied = sinon.spy();
 			let operation = {
 				baseVersion: 1
 			};
 
-			document.on( 'operationApplied', operationApplied );
-
 			expect(
 				() => {
 					document.applyOperation( operation );

+ 11 - 0
packages/ckeditor5-utils/tests/document/operation/changeoperation.js

@@ -44,6 +44,17 @@ describe( 'ChangeOperation', () => {
 		root = doc.createRoot( 'root' );
 	} );
 
+	it( 'should have proper type', () => {
+		const opp = new ChangeOperation(
+			new Range( new Position( [ 0 ], root ), new Position( [ 2 ], root ) ),
+			null,
+			new Attribute( 'isNew', true ),
+			doc.version
+		);
+
+		expect( opp.type ).to.equal( 'attr' );
+	} );
+
 	it( 'should insert attribute to the set of nodes', () => {
 		let newAttr = new Attribute( 'isNew', true );
 

+ 10 - 0
packages/ckeditor5-utils/tests/document/operation/insertoperation.js

@@ -39,6 +39,16 @@ describe( 'InsertOperation', () => {
 		root = doc.createRoot( 'root' );
 	} );
 
+	it( 'should have proper type', () => {
+		const opp = new InsertOperation(
+			new Position( [ 0 ], root ),
+			new Character( 'x' ),
+			doc.version
+		);
+
+		expect( opp.type ).to.equal( 'insert' );
+	} );
+
 	it( 'should insert node', () => {
 		doc.applyOperation(
 			new InsertOperation(

+ 11 - 0
packages/ckeditor5-utils/tests/document/operation/moveoperation.js

@@ -36,6 +36,17 @@ describe( 'MoveOperation', () => {
 		root = doc.createRoot( 'root' );
 	} );
 
+	it( 'should have proper type', () => {
+		const opp = new MoveOperation(
+			new Position( [ 0, 0 ], root ),
+			new Position( [ 1, 0 ], root ),
+			1,
+			doc.version
+		);
+
+		expect( opp.type ).to.equal( 'move' );
+	} );
+
 	it( 'should move from one node to another', () => {
 		let p1 = new Element( 'p1', [], new Element( 'x' ) );
 		let p2 = new Element( 'p2' );

+ 4 - 0
packages/ckeditor5-utils/tests/document/operation/reinsertoperation.js

@@ -44,6 +44,10 @@ describe( 'ReinsertOperation', () => {
 		);
 	} );
 
+	it( 'should have proper type', () => {
+		expect( operation.type ).to.equal( 'reinsert' );
+	} );
+
 	it( 'should extend MoveOperation class', () => {
 		expect( operation ).to.be.instanceof( MoveOperation );
 	} );

+ 10 - 0
packages/ckeditor5-utils/tests/document/operation/removeoperation.js

@@ -34,6 +34,16 @@ describe( 'RemoveOperation', () => {
 		graveyard = doc._graveyard;
 	} );
 
+	it( 'should have proper type', () => {
+		const opp = new RemoveOperation(
+			new Position( [ 2 ], root ),
+			2,
+			doc.version
+		);
+
+		expect( opp.type ).to.equal( 'remove' );
+	} );
+
 	it( 'should extend MoveOperation class', () => {
 		let operation = new RemoveOperation(
 			new Position( [ 2 ], root ),