瀏覽代碼

Tests: Added more tests.

Piotrek Koszuliński 10 年之前
父節點
當前提交
4daca8ff99
共有 1 個文件被更改,包括 21 次插入8 次删除
  1. 21 8
      packages/ckeditor5-ui/tests/collection.js

+ 21 - 8
packages/ckeditor5-ui/tests/collection.js

@@ -172,10 +172,10 @@ describe( 'Collection', () => {
 				collectionB.add( itemB );
 				collectionB.add( collectionA.remove( itemA ) );
 
-				expect( collectionA.length ).to.be.equal( 0 );
-				expect( collectionB.length ).to.be.equal( 2 );
-				expect( collectionB.get( 0 ) ).to.be.equal( itemB );
-				expect( collectionB.get( 1 ) ).to.be.equal( itemA );
+				expect( collectionA.length ).to.equal( 0 );
+				expect( collectionB.length ).to.equal( 2 );
+				expect( collectionB.get( 0 ) ).to.equal( itemB );
+				expect( collectionB.get( 1 ) ).to.equal( itemA );
 
 				expect( itemA.id ).to.not.equal( itemB.id );
 			}
@@ -195,15 +195,28 @@ describe( 'Collection', () => {
 				collectionB.add( itemB );
 				collectionB.add( collectionA.remove( itemA ) );
 
-				expect( collectionA.length ).to.be.equal( 0 );
-				expect( collectionB.length ).to.be.equal( 2 );
-				expect( collectionB.get( 0 ) ).to.be.equal( itemB );
-				expect( collectionB.get( 1 ) ).to.be.equal( itemA );
+				expect( collectionA.length ).to.equal( 0 );
+				expect( collectionB.length ).to.equal( 2 );
+				expect( collectionB.get( 0 ) ).to.equal( itemB );
+				expect( collectionB.get( 1 ) ).to.equal( itemA );
 
 				expect( itemA.foo ).to.not.equal( itemB.foo );
 			}
 		);
 
+		it( 'should allow an item which is already in some other collection', () => {
+			const collectionA = new Collection();
+			const collectionB = new Collection();
+			const item = {};
+
+			collectionA.add( item );
+			collectionB.add( item );
+
+			expect( collectionA.length ).to.equal( 1 );
+			expect( collectionB.length ).to.equal( 1 );
+			expect( collectionA.get( item.id ) ).to.equal( collectionB.get( 0 ) );
+		} );
+
 		it( 'should fire the "add" event', () => {
 			let spy = sinon.spy();
 			let item = {};