Selaa lähdekoodia

Tests and documentation for the Editable.

Piotrek Koszuliński 9 vuotta sitten
vanhempi
commit
aab7970078

+ 34 - 0
packages/ckeditor5-utils/tests/_utils/utils.js

@@ -101,6 +101,40 @@ const utils = {
 		} );
 
 		return observer;
+	},
+
+	/**
+	 * Checkes wether observable properties are properly bound to each other.
+	 *
+	 * Syntax given that observable `A` is bound to observables [`B`, `C`, ...]:
+	 *
+	 *		assertBinding( A,
+	 *			{ initial `A` attributes },
+	 *			[
+	 *				[ B, { new `B` attributes } ],
+	 *				[ C, { new `C` attributes } ],
+	 *				...
+	 *			],
+	 *			{ `A` attributes after [`B`, 'C', ...] changed }
+	 *		);
+	 */
+	assertBinding( observable, stateBefore, data, stateAfter ) {
+		let key, pair;
+
+		for ( key in stateBefore ) {
+			expect( observable[ key ] ).to.be.equal( stateBefore[ key ] );
+		}
+
+		// Change attributes of bound observables.
+		for ( pair of data ) {
+			for ( key in pair[ 1 ] ) {
+				pair[ 0 ][ key ] = pair[ 1 ][ key ];
+			}
+		}
+
+		for ( key in stateAfter ) {
+			expect( observable[ key ] ).to.be.equal( stateAfter[ key ] );
+		}
 	}
 };
 

+ 3 - 31
packages/ckeditor5-utils/tests/observablemixin.js

@@ -6,12 +6,15 @@
 'use strict';
 
 import testUtils from '/tests/_utils/utils.js';
+import coreTestUtils from '/tests/core/_utils/utils.js';
 import ObservableMixin from '/ckeditor5/core/observablemixin.js';
 import EmitterMixin from '/ckeditor5/core/emittermixin.js';
 import EventInfo from '/ckeditor5/core/eventinfo.js';
 import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
 import utils from '/ckeditor5/core/utils.js';
 
+const assertBinding = coreTestUtils.assertBinding;
+
 testUtils.createSinonSandbox();
 
 describe( 'ObservableMixin', () => {
@@ -781,35 +784,4 @@ describe( 'Observable', () => {
 			);
 		} );
 	} );
-
-	// Syntax given that observable `A` is bound to observables [`B`, `C`, ...]:
-	//
-	//		assertBinding( A,
-	//			{ initial `A` attributes },
-	//			[
-	//				[ B, { new `B` attributes } ],
-	//				[ C, { new `C` attributes } ],
-	//				...
-	//			],
-	//			{ `A` attributes after [`B`, 'C', ...] changed }
-	//		);
-	//
-	function assertBinding( observable, stateBefore, data, stateAfter ) {
-		let key, pair;
-
-		for ( key in stateBefore ) {
-			expect( observable[ key ] ).to.be.equal( stateBefore[ key ] );
-		}
-
-		// Change attributes of bound observables.
-		for ( pair of data ) {
-			for ( key in pair[ 1 ] ) {
-				pair[ 0 ][ key ] = pair[ 1 ][ key ];
-			}
-		}
-
-		for ( key in stateAfter ) {
-			expect( observable[ key ] ).to.be.equal( stateAfter[ key ] );
-		}
-	}
 } );