Преглед изворни кода

Tests: Added missing test coverage.

Marek Lewandowski пре 5 година
родитељ
комит
74765bfbe6
1 измењених фајлова са 25 додато и 0 уклоњено
  1. 25 0
      packages/ckeditor5-utils/tests/collection.js

+ 25 - 0
packages/ckeditor5-utils/tests/collection.js

@@ -50,6 +50,31 @@ describe( 'Collection', () => {
 				expect( collection.get( 0 ) ).to.equal( item1 );
 				expect( collection.get( 1 ) ).to.equal( item2 );
 			} );
+
+			it( 'generates id for items that doesn\'t have it', () => {
+				const item = {};
+				const collection = new Collection( [ item ] );
+
+				expect( collection.get( 0 ).id ).to.be.a( 'string' );
+				expect( collection.get( 0 ).id ).not.to.be.empty;
+			} );
+
+			it( 'throws an error when invalid item key is provided', () => {
+				const badIdItem = getItem( 1 ); // Number id is not supported.
+
+				expectToThrowCKEditorError( () => {
+					return new Collection( [ badIdItem ] );
+				}, /^collection-add-invalid-id/ );
+			} );
+
+			it( 'throws an error when items have a duplicated key', () => {
+				const item1 = getItem( 'foo' );
+				const item2 = getItem( 'foo' );
+
+				expectToThrowCKEditorError( () => {
+					return new Collection( [ item1, item2 ] );
+				}, /^collection-add-item-already-exists/ );
+			} );
 		} );
 
 		describe( 'options', () => {