Przeglądaj źródła

Tests: add missing tests for clearAttributes.

Piotr Jasiun 8 lat temu
rodzic
commit
f2500dd483
1 zmienionych plików z 55 dodań i 0 usunięć
  1. 55 0
      packages/ckeditor5-engine/tests/model/batch.js

+ 55 - 0
packages/ckeditor5-engine/tests/model/batch.js

@@ -1283,6 +1283,61 @@ describe( 'Batch', () => {
 					expect( spy.callCount ).to.equal( 0 );
 				} );
 			} );
+
+			describe( 'clearAttributes', () => {
+				it( 'should clear attributes from range', () => {
+					batch.appendText( 'xxx', { a: 1, b: 2, c: 3 }, root );
+					batch.appendText( 'xxx', root );
+					batch.appendText( 'xxx', { a: 1 }, root );
+					batch.appendText( 'xxx', { b: 2 }, root );
+					batch.appendText( 'xxx', root );
+					batch.appendElement( 'e', { a: 1 }, root );
+					batch.appendText( 'xxx', root );
+
+					const range = Range.createIn( root );
+
+					batch.clearAttributes( range );
+
+					let itemsCount = 0;
+
+					for ( const item of range.getItems() ) {
+						itemsCount++;
+						expect( Array.from( item.getAttributeKeys() ).length ).to.equal( 0 );
+					}
+
+					expect( itemsCount ).to.equal( 3 );
+				} );
+
+				it( 'should clear attributes on element', () => {
+					const element = batch.createElement( 'x', { a: 1, b: 2, c: 3 }, root );
+
+					expect( Array.from( element.getAttributeKeys() ).length ).to.equal( 3 );
+
+					batch.clearAttributes( element );
+
+					expect( Array.from( element.getAttributeKeys() ).length ).to.equal( 0 );
+				} );
+
+				it( 'should clear attributes on root element', () => {
+					batch.setAttributes( root, { a: 1, b: 2, c: 3 } );
+
+					expect( Array.from( root.getAttributeKeys() ).length ).to.equal( 3 );
+
+					batch.clearAttributes( root );
+
+					expect( Array.from( root.getAttributeKeys() ).length ).to.equal( 0 );
+				} );
+
+				it( 'should do nothing if there are no attributes', () => {
+					const element = batch.createElement( 'x' );
+
+					expect( Array.from( element.getAttributeKeys() ).length ).to.equal( 0 );
+
+					batch.clearAttributes( element );
+
+					expect( Array.from( element.getAttributeKeys() ).length ).to.equal( 0 );
+				} );
+			} );
 		} );
 
 		it( 'should not add empty delta to the batch', () => {