Browse Source

Added missing test for LiveSelection.

Maciej Bukowski 7 years ago
parent
commit
91b652b12a

+ 4 - 6
packages/ckeditor5-engine/src/model/liveselection.js

@@ -338,7 +338,7 @@ export default class LiveSelection extends Selection {
 			}
 		}
 
-		this._setAttributesTo( newAttributes, false );
+		this._setAttributesTo( newAttributes );
 
 		// Let's evaluate which attributes really changed.
 		const changed = [];
@@ -458,11 +458,9 @@ export default class LiveSelection extends Selection {
 	 *
 	 * @private
 	 * @param {Map.<String,*>} attrs Iterable object containing attributes to be set.
-	 * @param {Boolean} [directChange=true] `true` if the change is caused by `Selection` API, `false` if change
-	 * is caused by `Batch` API.
 	 * @returns {Set.<String>} Changed attribute keys.
 	 */
-	_setAttributesTo( attrs, directChange = true ) {
+	_setAttributesTo( attrs ) {
 		const changed = new Set();
 
 		for ( const [ oldKey, oldValue ] of this.getAttributes() ) {
@@ -472,14 +470,14 @@ export default class LiveSelection extends Selection {
 			}
 
 			// Attribute still might not get removed because of priorities.
-			if ( this._removeAttribute( oldKey, directChange ) ) {
+			if ( this._removeAttribute( oldKey, false ) ) {
 				changed.add( oldKey );
 			}
 		}
 
 		for ( const [ key, value ] of attrs ) {
 			// Attribute may not be set because of attributes or because same key/value is already added.
-			const gotAdded = this._setAttribute( key, value, directChange );
+			const gotAdded = this._setAttribute( key, value, false );
 
 			if ( gotAdded ) {
 				changed.add( key );

+ 15 - 1
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -304,7 +304,6 @@ describe( 'DocumentSelection', () => {
 		} );
 	} );
 
-	// TODO - merge with other setTo's
 	describe( 'setTo()', () => {
 		it( 'should throw an error when range is invalid', () => {
 			expect( () => {
@@ -312,6 +311,21 @@ describe( 'DocumentSelection', () => {
 			} ).to.throw( CKEditorError, /model-selection-added-not-range/ );
 		} );
 
+		it( 'should log a warning when trying to set selection to the graveyard', () => {
+			// eslint-disable-next-line no-undef
+			const warnStub = sinon.stub( console, 'warn' );
+
+			const range = new Range( new Position( model.document.graveyard, [ 0 ] ) );
+			selection._setTo( range );
+
+			expect( warnStub.calledOnce ).to.equal( true );
+			expect( warnStub.getCall( 0 ).args[ 0 ] ).to.match( /model-selection-range-in-graveyard/ );
+
+			expect( selection._ranges ).to.deep.equal( [] );
+
+			warnStub.restore();
+		} );
+
 		it( 'should detach removed ranges', () => {
 			selection._setTo( [ liveRange, range ] );