瀏覽代碼

Removed obsolete assertions from Controller and View methods (also tests).

Aleksander Nowodzinski 10 年之前
父節點
當前提交
7c2ee8659f

+ 8 - 17
packages/ckeditor5-ui/src/ui/controller.js

@@ -150,13 +150,13 @@ CKEDITOR.define( [
 				throw new CKEditorError( 'ui-controller-addchild-nocol' );
 			}
 
-			if ( !childController || !( childController instanceof Controller ) ) {
+			if ( !childController ) {
 				/**
-				 * Passed controller is of a wrong type.
+				 * Passed no controller.
 				 *
-				 * @error ui-controller-addchild-badtype
+				 * @error ui-controller-addchild-no-controller
 				 */
-				throw new CKEditorError( 'ui-controller-addchild-badtype' );
+				throw new CKEditorError( 'ui-controller-addchild-no-controller' );
 			}
 
 			// ChildController.init() returns Promise.
@@ -209,13 +209,13 @@ CKEDITOR.define( [
 				throw new CKEditorError( 'ui-controller-removechild-nocol' );
 			}
 
-			if ( !childController || !( childController instanceof Controller ) ) {
+			if ( !childController ) {
 				/**
-				 * The controller is of a wrong type.
+				 * Passed no controller.
 				 *
-				 * @error ui-controller-removechild-badtype
+				 * @error ui-controller-removechild-no-controller
 				 */
-				throw new CKEditorError( 'ui-controller-removechild-badtype' );
+				throw new CKEditorError( 'ui-controller-removechild-no-controller' );
 			}
 
 			collection.remove( childController );
@@ -261,15 +261,6 @@ CKEDITOR.define( [
 			const registered = this._collections.get( collectionName );
 			const that = this;
 
-			if ( !( collection instanceof Collection ) ) {
-				/**
-				 * The collection must be an instance of Collection.
-				 *
-				 * @error ui-controller-register-badtype
-				 */
-				throw new CKEditorError( 'ui-controller-register-badtype' );
-			}
-
 			if ( !registered ) {
 				add( collection );
 			} else {

+ 17 - 8
packages/ckeditor5-ui/src/ui/view.js

@@ -140,13 +140,13 @@ CKEDITOR.define( [
 				throw new CKEditorError( 'ui-view-addchild-noreg' );
 			}
 
-			if ( !childView || !( childView instanceof View ) ) {
+			if ( !childView ) {
 				/**
-				 * Child view must be an instance of View.
+				 * No child view passed.
 				 *
-				 * @error ui-view-addchild-badtype
+				 * @error ui-view-addchild-no-view
 				 */
-				throw new CKEditorError( 'ui-view-addchild-badtype' );
+				throw new CKEditorError( 'ui-view-addchild-no-view' );
 			}
 
 			region.views.add( childView, index );
@@ -160,13 +160,13 @@ CKEDITOR.define( [
 		 * @returns {View} A child view instance after removal.
 		 */
 		removeChild( regionName, childView ) {
-			if ( !childView || !( childView instanceof View ) ) {
+			if ( !regionName ) {
 				/**
-				 * The view must be an instance of View.
+				 * The name of the region is required.
 				 *
-				 * @error ui-view-removechild-badtype
+				 * @error ui-view-removechild-badrname
 				 */
-				throw new CKEditorError( 'ui-view-removechild-badtype' );
+				throw new CKEditorError( 'ui-view-removechild-badrname' );
 			}
 
 			const region = this.regions.get( regionName );
@@ -180,6 +180,15 @@ CKEDITOR.define( [
 				throw new CKEditorError( 'ui-view-removechild-noreg' );
 			}
 
+			if ( !childView ) {
+				/**
+				 * The view must be an instance of View.
+				 *
+				 * @error ui-view-removechild-no-view
+				 */
+				throw new CKEditorError( 'ui-view-removechild-no-view' );
+			}
+
 			region.views.remove( childView );
 
 			return childView;

+ 3 - 19
packages/ckeditor5-ui/tests/ui/controller.js

@@ -110,14 +110,6 @@ describe( 'Controller', () => {
 			expect( () => {
 				controller.register();
 			} ).to.throw;
-
-			expect( () => {
-				controller.register( 'x' );
-			} ).to.throw( CKEditorError, /ui-controller-register-badtype/ );
-
-			expect( () => {
-				controller.register( 'x', new Date() );
-			} ).to.throw( CKEditorError, /ui-controller-register-badtype/ );
 		} );
 
 		it( 'should throw when already registered but no override flag', () => {
@@ -183,18 +175,14 @@ describe( 'Controller', () => {
 			} ).to.throw( CKEditorError, /ui-controller-addchild-nocol/ );
 		} );
 
-		it( 'should throw when controller or wrong controller is passed', () => {
+		it( 'should throw when no controller is passed', () => {
 			const controller = new Controller();
 
 			controller.register( 'x', new Collection() );
 
 			expect( () => {
 				controller.addChild( 'x' );
-			} ).to.throw( CKEditorError, /ui-controller-addchild-badtype/ );
-
-			expect( () => {
-				controller.addChild( 'x', new Date() );
-			} ).to.throw( CKEditorError, /ui-controller-addchild-badtype/ );
+			} ).to.throw( CKEditorError, /ui-controller-addchild-no-controller/ );
 		} );
 
 		it( 'should add a child controller to given collection and return promise', () => {
@@ -356,11 +344,7 @@ describe( 'Controller', () => {
 
 			expect( () => {
 				controller.removeChild( 'x' );
-			} ).to.throw( CKEditorError, /ui-controller-removechild-badtype/ );
-
-			expect( () => {
-				controller.removeChild( 'x', new Date() );
-			} ).to.throw( CKEditorError, /ui-controller-removechild-badtype/ );
+			} ).to.throw( CKEditorError, /ui-controller-removechild-no-controller/ );
 		} );
 
 		it( 'should remove child controller and return it', () => {

+ 9 - 11
packages/ckeditor5-ui/tests/ui/view.js

@@ -154,14 +154,10 @@ describe( 'View', () => {
 			} ).to.throw( CKEditorError, /ui-view-addchild-noreg/ );
 		} );
 
-		it( 'should throw when child view is of a wrong type', () => {
+		it( 'should throw when no child view passed', () => {
 			expect( () => {
 				view.addChild( 'x' );
-			} ).to.throw( CKEditorError, /ui-view-addchild-badtype/ );
-
-			expect( () => {
-				view.addChild( 'x', new Date() );
-			} ).to.throw( CKEditorError, /ui-view-addchild-badtype/ );
+			} ).to.throw( CKEditorError, /ui-view-addchild-no-view/ );
 		} );
 
 		it( 'should add a child to the region views', () => {
@@ -196,14 +192,16 @@ describe( 'View', () => {
 			setTestViewInstance();
 		} );
 
-		it( 'should throw when child view is of a wrong type', () => {
+		it( 'should throw when no region name', () => {
 			expect( () => {
-				view.removeChild( 'x' );
-			} ).to.throw( CKEditorError, /ui-view-removechild-badtype/ );
+				view.removeChild();
+			} ).to.throw( CKEditorError, /ui-view-removechild-badrname/ );
+		} );
 
+		it( 'should throw when child view passed', () => {
 			expect( () => {
-				view.removeChild( 'x', new Date() );
-			} ).to.throw( CKEditorError, /ui-view-removechild-badtype/ );
+				view.removeChild( 'x' );
+			} ).to.throw( CKEditorError, /ui-view-removechild-no-view/ );
 		} );
 
 		it( 'should throw when region does not exist', () => {