浏览代码

Merge pull request #111 from ckeditor/t/93

t/92: Fixed: A View#id Number breaks parent ViewCollection.
Piotrek Koszuliński 9 年之前
父节点
当前提交
13f97a27b1
共有 2 个文件被更改,包括 24 次插入8 次删除
  1. 5 1
      packages/ckeditor5-ui/src/viewcollection.js
  2. 19 7
      packages/ckeditor5-ui/tests/viewcollection.js

+ 5 - 1
packages/ckeditor5-ui/src/viewcollection.js

@@ -21,7 +21,11 @@ export default class ViewCollection extends Collection {
 	 * @param {utils.Locale} [locale] The {@link core.editor.Editor#locale editor's locale} instance.
 	 */
 	constructor( locale ) {
-		super();
+		super( {
+			// An #id Number attribute should be legal and not break the `ViewCollection` instance.
+			// https://github.com/ckeditor/ckeditor5-ui/issues/93
+			idProperty: 'viewUid'
+		} );
 
 		// Handle {@link ui.View#element} in DOM when a new view is added to the collection.
 		this.on( 'add', ( evt, view, index ) => {

+ 19 - 7
packages/ckeditor5-ui/tests/viewcollection.js

@@ -27,6 +27,7 @@ describe( 'ViewCollection', () => {
 			expect( collection.ready ).to.be.false;
 			expect( collection._parentElement ).to.be.null;
 			expect( collection._boundItemsToViewsMap ).to.be.instanceOf( Map );
+			expect( collection._idProperty ).to.equal( 'viewUid' );
 		} );
 
 		it( 'accepts locale and defines the locale property', () => {
@@ -139,7 +140,7 @@ describe( 'ViewCollection', () => {
 		} );
 	} );
 
-	describe( 'add', () => {
+	describe( 'add()', () => {
 		it( 'returns a promise', () => {
 			expect( collection.add( {} ) ).to.be.instanceof( Promise );
 		} );
@@ -169,6 +170,17 @@ describe( 'ViewCollection', () => {
 				} );
 			} );
 		} );
+
+		it( 'works for a view with a Number view#id attribute', () => {
+			const view = new View();
+
+			view.set( 'id', 1 );
+
+			return collection.add( view ).then( () => {
+				expect( view.id ).to.equal( 1 );
+				expect( view.viewUid ).to.be.a( 'string' );
+			} );
+		} );
 	} );
 
 	describe( 'setParent', () => {
@@ -181,7 +193,7 @@ describe( 'ViewCollection', () => {
 		} );
 	} );
 
-	describe( 'bindTo', () => {
+	describe( 'bindTo()', () => {
 		class ViewClass extends View {
 			constructor( locale, data ) {
 				super( locale );
@@ -194,14 +206,14 @@ describe( 'ViewCollection', () => {
 			}
 		}
 
-		it( 'provides "as" interface', () => {
+		it( 'provides "as()" interface', () => {
 			const returned = collection.bindTo( {} );
 
 			expect( returned ).to.have.keys( 'as' );
 			expect( returned.as ).to.be.a( 'function' );
 		} );
 
-		describe( 'as', () => {
+		describe( 'as()', () => {
 			it( 'does not chain', () => {
 				const returned = collection.bindTo( new Collection() ).as( ViewClass );
 
@@ -292,7 +304,7 @@ describe( 'ViewCollection', () => {
 		} );
 	} );
 
-	describe( 'delegate', () => {
+	describe( 'delegate()', () => {
 		it( 'should throw when event names are not strings', () => {
 			expect( () => {
 				collection.delegate();
@@ -311,14 +323,14 @@ describe( 'ViewCollection', () => {
 			expect( collection.delegate( 'foo' ) ).to.be.an( 'object' );
 		} );
 
-		it( 'provides "to" interface', () => {
+		it( 'provides "to()" interface', () => {
 			const delegate = collection.delegate( 'foo' );
 
 			expect( delegate ).to.have.keys( 'to' );
 			expect( delegate.to ).to.be.a( 'function' );
 		} );
 
-		describe( 'to', () => {
+		describe( 'to()', () => {
 			it( 'does not chain', () => {
 				const returned = collection.delegate( 'foo' ).to( {} );