8
0
Pārlūkot izejas kodu

MoveOperation minor improvements + code style in tests.

Szymon Cofalik 10 gadi atpakaļ
vecāks
revīzija
c9fe7c1197

+ 3 - 3
packages/ckeditor5-utils/src/document/operation/moveoperation.js

@@ -88,8 +88,8 @@ CKEDITOR.define( [
 					'operation-move-range-into-itself: Trying to move a range of nodes to the inside of that range.'
 				);
 			} else {
-				const sourcePath = this.sourcePosition.getParentPath();
-				const targetPath = this.targetPosition.getParentPath();
+				const sourcePath = this.sourcePosition.parentPath;
+				const targetPath = this.targetPosition.parentPath;
 
 				if ( utils.compareArrays( sourcePath, targetPath ) == utils.compareArrays.PREFIX ) {
 					let i = sourcePath.length;
@@ -120,7 +120,7 @@ CKEDITOR.define( [
 		}
 
 		getReversed() {
-			return new MoveOperation( this.targetPosition, this.sourcePosition, this.howMany, this.baseVersion + 1 );
+			return new MoveOperation( this.targetPosition.clone(), this.sourcePosition.clone(), this.howMany, this.baseVersion + 1 );
 		}
 	}
 

+ 13 - 29
packages/ckeditor5-utils/tests/document/operation/moveoperation.js

@@ -114,8 +114,8 @@ describe( 'MoveOperation', () => {
 		expect( reverse ).to.be.an.instanceof( MoveOperation );
 		expect( reverse.baseVersion ).to.equal( 1 );
 		expect( reverse.howMany ).to.equal( nodeList.length );
-		expect( reverse.sourcePosition ).to.equal( targetPosition );
-		expect( reverse.targetPosition ).to.equal( sourcePosition );
+		expect( reverse.sourcePosition.isEqual( targetPosition ) ).to.be.true;
+		expect( reverse.targetPosition.isEqual( sourcePosition ) ).to.be.true;
 	} );
 
 	it( 'should undo move node by applying reverse operation', () => {
@@ -151,18 +151,14 @@ describe( 'MoveOperation', () => {
 	it( 'should throw an error if number of nodes to move exceeds the number of existing nodes in given element', () => {
 		root.insertChildren( 0, 'xbarx' );
 
-		expect(
-			() => {
-				doc.applyOperation(
-					new MoveOperation(
-						new Position( [ 3 ], root ),
-						new Position( [ 1 ], root ),
-						3,
-						doc.version
-					)
-				);
-			}
-		).to.throw( CKEditorError, /operation-move-nodes-do-not-exist/ );
+		let operation = new MoveOperation(
+			new Position( [ 3 ], root ),
+			new Position( [ 1 ], root ),
+			3,
+			doc.version
+		);
+
+		expect( () => doc.applyOperation( operation ) ).to.throw( CKEditorError, /operation-move-nodes-do-not-exist/ );
 	} );
 
 	it( 'should throw an error if target or source parent-element specified by position does not exist', () => {
@@ -179,11 +175,7 @@ describe( 'MoveOperation', () => {
 
 		root.removeChildren( 2, 1 );
 
-		expect(
-			() => {
-				doc.applyOperation( operation );
-			}
-		).to.throw( CKEditorError, /operation-move-position-invalid/ );
+		expect( () => doc.applyOperation( operation ) ).to.throw( CKEditorError, /operation-move-position-invalid/ );
 	} );
 
 	it( 'should throw an error if operation tries to move a range between the beginning and the end of that range', () => {
@@ -196,11 +188,7 @@ describe( 'MoveOperation', () => {
 			doc.version
 		);
 
-		expect(
-			() => {
-				doc.applyOperation( operation );
-			}
-		).to.throw( CKEditorError, /operation-move-range-into-itself/ );
+		expect( () => doc.applyOperation( operation ) ).to.throw( CKEditorError, /operation-move-range-into-itself/ );
 	} );
 
 	it( 'should throw an error if operation tries to move a range into a sub-tree of a node that is in that range', () => {
@@ -214,11 +202,7 @@ describe( 'MoveOperation', () => {
 			doc.version
 		);
 
-		expect(
-			() => {
-				doc.applyOperation( operation );
-			}
-		).to.throw( CKEditorError, /operation-move-node-into-itself/ );
+		expect( () => doc.applyOperation( operation ) ).to.throw( CKEditorError, /operation-move-node-into-itself/ );
 	} );
 
 	it( 'should not throw an error if operation move a range into a sibling', () => {