瀏覽代碼

Added test which ensures whether DocumentSelection#change:range event is fired once.

Kamil Piechaczek 8 年之前
父節點
當前提交
986abde22b
共有 1 個文件被更改,包括 27 次插入0 次删除
  1. 27 0
      packages/ckeditor5-engine/tests/model/documentselection.js

+ 27 - 0
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -740,6 +740,33 @@ describe( 'DocumentSelection', () => {
 				expect( selection.getFirstPosition().path ).to.deep.equal( [ 0, 0 ] );
 				expect( selection.getFirstPosition().path ).to.deep.equal( [ 0, 0 ] );
 			} );
 			} );
 		} );
 		} );
+
+		it( '`DocumentSelection#change:range` event should be fire once even if selection contains multi-ranges', () => {
+			root.removeChildren( 0, root.childCount );
+			root.insertChildren( 0, [
+				new Element( 'p', [], new Text( 'abcdef' ) ),
+				new Element( 'p', [], new Text( 'foobar' ) ),
+				new Text( 'xyz #2' )
+			] );
+
+			selection._setTo( [
+				Range.createIn( root.getNodeByPath( [ 0 ] ) ),
+				Range.createIn( root.getNodeByPath( [ 1 ] ) )
+			] );
+
+			spyRange = sinon.spy();
+			selection.on( 'change:range', spyRange );
+
+			model.applyOperation( wrapInDelta(
+				new InsertOperation(
+					new Position( root, [ 0 ] ),
+					'xyz #1',
+					doc.version
+				)
+			) );
+
+			expect( spyRange.calledOnce ).to.be.true;
+		} );
 	} );
 	} );
 
 
 	describe( 'attributes', () => {
 	describe( 'attributes', () => {