浏览代码

Simpliefied SelectionObserver test.

Oskar Wróbel 8 年之前
父节点
当前提交
d42c9cb034
共有 1 个文件被更改,包括 17 次插入26 次删除
  1. 17 26
      packages/ckeditor5-engine/tests/view/observer/selectionobserver.js

+ 17 - 26
packages/ckeditor5-engine/tests/view/observer/selectionobserver.js

@@ -243,41 +243,32 @@ describe( 'SelectionObserver', () => {
 			// Check if spy was called.
 			expect( spy.notCalled ).to.true;
 
-			// Change selection.
+			// Change selection one more time.
 			changeDomSelection();
 
-			// Wait 100ms.
+			// Wait 210ms (debounced function should be called).
 			setTimeout( () => {
-				// Check if spy was called.
-				expect( spy.notCalled ).to.true;
-
-				// Change selection.
-				changeDomSelection();
+				const data = spy.firstCall.args[ 1 ];
 
-				// Wait 210ms (debounced function should be called).
-				setTimeout( () => {
-					const data = spy.firstCall.args[ 1 ];
+				expect( spy.calledOnce ).to.true;
+				expect( data ).to.have.property( 'domSelection' ).to.equal( document.getSelection() );
 
-					expect( spy.calledOnce ).to.true;
-					expect( data ).to.have.property( 'domSelection' ).to.equal( document.getSelection() );
+				expect( data ).to.have.property( 'oldSelection' ).to.instanceof( ViewSelection );
+				expect( data.oldSelection.rangeCount ).to.equal( 0 );
 
-					expect( data ).to.have.property( 'oldSelection' ).to.instanceof( ViewSelection );
-					expect( data.oldSelection.rangeCount ).to.equal( 0 );
+				expect( data ).to.have.property( 'newSelection' ).to.instanceof( ViewSelection );
+				expect( data.newSelection.rangeCount ).to.equal( 1 );
 
-					expect( data ).to.have.property( 'newSelection' ).to.instanceof( ViewSelection );
-					expect( data.newSelection.rangeCount ).to.equal( 1 );
+				const newViewRange = data.newSelection.getFirstRange();
+				const viewFoo = viewDocument.getRoot().getChild( 0 ).getChild( 0 );
 
-					const newViewRange = data.newSelection.getFirstRange();
-					const viewFoo = viewDocument.getRoot().getChild( 0 ).getChild( 0 );
+				expect( newViewRange.start.parent ).to.equal( viewFoo );
+				expect( newViewRange.start.offset ).to.equal( 3 );
+				expect( newViewRange.end.parent ).to.equal( viewFoo );
+				expect( newViewRange.end.offset ).to.equal( 3 );
 
-					expect( newViewRange.start.parent ).to.equal( viewFoo );
-					expect( newViewRange.start.offset ).to.equal( 2 );
-					expect( newViewRange.end.parent ).to.equal( viewFoo );
-					expect( newViewRange.end.offset ).to.equal( 2 );
-
-					done();
-				}, 210 );
-			}, 100 );
+				done();
+			}, 210 );
 		}, 100 );
 	} );