Browse Source

Tests: moved helper function expectOperation to tools.js.

Szymon Cofalik 10 years ago
parent
commit
c8d551b584

+ 25 - 0
packages/ckeditor5-utils/tests/_tools/tools.js

@@ -67,4 +67,29 @@
 			return count;
 		}
 	};
+
+	bender.tools.operations = {
+		expectOperation: ( Position, Range ) => {
+			return ( op, params ) => {
+				for ( let i in params ) {
+					if ( params.hasOwnProperty( i ) ) {
+						if ( i == 'type' ) {
+							expect( op ).to.be.instanceof( params[ i ] );
+						}
+						else if ( params[ i ] instanceof Array ) {
+							expect( op[ i ].length ).to.equal( params[ i ].length );
+
+							for ( let j = 0; j < params[ i ].length; j++ ) {
+								expect( op[ i ][ j ] ).to.equal( params[ i ][ j ] );
+							}
+						} else if ( params[ i ] instanceof Position || params[ i ] instanceof Range ) {
+							expect( op[ i ].isEqual( params[ i ] ) ).to.be.true;
+						} else {
+							expect( op[ i ] ).to.equal( params[ i ] );
+						}
+					}
+				}
+			}
+		}
+	};
 } )();

+ 6 - 21
packages/ckeditor5-utils/tests/document/operation/changeoperation.js

@@ -4,6 +4,7 @@
  */
 
 /* bender-tags: document */
+/* bender-include: ../../_tools/tools.js */
 /* global describe, before, beforeEach, it, expect */
 
 /* bender-include: ../../_tools/tools.js */
@@ -46,6 +47,8 @@ describe( 'ChangeOperation', () => {
 		NodeList = modules[ 'document/nodelist' ];
 		Text = modules[ 'document/text' ];
 		CKEditorError = modules.ckeditorerror;
+
+
 	} );
 
 	let doc, root;
@@ -392,6 +395,7 @@ describe( 'ChangeOperation', () => {
 
 	describe( 'getTransformedBy', () => {
 		let nodeA, nodeB, start, end, range, oldAttr, newAttr, op, baseVersion, expected;
+		let expectOperation;
 
 		beforeEach( () => {
 			nodeA = new Node();
@@ -408,28 +412,9 @@ describe( 'ChangeOperation', () => {
 				newAttr: newAttr,
 				baseVersion: baseVersion + 1
 			};
-		} );
 
-		function expectOperation( op, params ) {
-			for ( let i in params ) {
-				if ( params.hasOwnProperty( i ) ) {
-					if ( i == 'type' ) {
-						expect( op ).to.be.instanceof( params[ i ] );
-					}
-					else if ( params[ i ] instanceof Array ) {
-						expect( op[ i ].length ).to.equal( params[ i ].length );
-
-						for ( let j = 0; j < params[ i ].length; j++ ) {
-							expect( op[ i ][ j ] ).to.equal( params[ i ][ j ] );
-						}
-					} else if ( params[ i ] instanceof Position || params[ i ] instanceof Range ) {
-						expect( op[ i ].isEqual( params[ i ] ) ).to.be.true;
-					} else {
-						expect( op[ i ] ).to.equal( params[ i ] );
-					}
-				}
-			}
-		}
+			expectOperation = bender.tools.operations.expectOperation( Position, Range );
+		} );
 
 		describe( 'single-level range', () => {
 			beforeEach( () => {

+ 4 - 21
packages/ckeditor5-utils/tests/document/operation/insertoperation.js

@@ -4,6 +4,7 @@
  */
 
 /* bender-tags: document */
+/* bender-include: ../../_tools/tools.js */
 /* global describe, before, beforeEach, it, expect */
 
 'use strict';
@@ -198,6 +199,7 @@ describe( 'InsertOperation', () => {
 
 	describe( 'getTransformedBy', () => {
 		let nodeA, nodeB, nodeC, nodeD, position, op, baseVersion, expected;
+		let expectOperation;
 
 		beforeEach( () => {
 			nodeA = new Node();
@@ -216,28 +218,9 @@ describe( 'InsertOperation', () => {
 				position: position.clone(),
 				baseVersion: baseVersion + 1
 			};
-		} );
 
-		function expectOperation( op, params ) {
-			for ( let i in params ) {
-				if ( params.hasOwnProperty( i ) ) {
-					if ( i == 'type' ) {
-						expect( op ).to.be.instanceof( params[ i ] );
-					}
-					else if ( params[ i ] instanceof Array ) {
-						expect( op[ i ].length ).to.equal( params[ i ].length );
-
-						for ( let j = 0; j < params[ i ].length; j++ ) {
-							expect( op[ i ][ j ] ).to.equal( params[ i ][ j ] );
-						}
-					} else if ( params[ i ] instanceof Position || params[ i ] instanceof Range ) {
-						expect( op[ i ].isEqual( params[ i ] ) ).to.be.true;
-					} else {
-						expect( op[ i ] ).to.equal( params[ i ] );
-					}
-				}
-			}
-		}
+			expectOperation = bender.tools.operations.expectOperation( Position, Range );
+		} );
 
 		describe( 'InsertOperation', () => {
 			it( 'should not change when positions are different', () => {

+ 4 - 21
packages/ckeditor5-utils/tests/document/operation/moveoperation.js

@@ -4,6 +4,7 @@
  */
 
 /* bender-tags: document */
+/* bender-include: ../../_tools/tools.js */
 /* global describe, before, beforeEach, it, expect */
 
 'use strict';
@@ -263,6 +264,7 @@ describe( 'MoveOperation', () => {
 
 	describe( 'getTransformedBy', () => {
 		let nodeA, nodeB, op, baseVersion, sourcePosition, targetPosition, rangeEnd, howMany, expected;
+		let expectOperation;
 
 		beforeEach( () => {
 			nodeA = new Node();
@@ -286,28 +288,9 @@ describe( 'MoveOperation', () => {
 				howMany: howMany,
 				baseVersion: baseVersion + 1
 			};
-		} );
 
-		function expectOperation( op, params ) {
-			for ( let i in params ) {
-				if ( params.hasOwnProperty( i ) ) {
-					if ( i == 'type' ) {
-						expect( op ).to.be.instanceof( params[ i ] );
-					}
-					else if ( params[ i ] instanceof Array ) {
-						expect( op[ i ].length ).to.equal( params[ i ].length );
-
-						for ( let j = 0; j < params[ i ].length; j++ ) {
-							expect( op[ i ][ j ] ).to.equal( params[ i ][ j ] );
-						}
-					} else if ( params[ i ] instanceof Position || params[ i ] instanceof Range ) {
-						expect( op[ i ].isEqual( params[ i ] ) ).to.be.true;
-					} else {
-						expect( op[ i ] ).to.equal( params[ i ] );
-					}
-				}
-			}
-		}
+			expectOperation = bender.tools.operations.expectOperation( Position, Range );
+		} );
 
 		describe( 'InsertOperation', () => {
 			// insert in different spots than move op