Browse Source

Fixed failing tests.

Oskar Wróbel 8 years ago
parent
commit
0b0e91f198
1 changed files with 24 additions and 16 deletions
  1. 24 16
      packages/ckeditor5-link/tests/link.js

+ 24 - 16
packages/ckeditor5-link/tests/link.js

@@ -43,6 +43,8 @@ describe( 'Link', () => {
 
 			// There is no point to execute `BalloonPanelView#attachTo` so override it.
 			testUtils.sinon.stub( balloon.view, 'attachTo', () => {} );
+
+			return formView.init();
 		} );
 	} );
 
@@ -90,6 +92,8 @@ describe( 'Link', () => {
 		it( 'should add link form to the ContextualBalloon and attach balloon to the link element ' +
 			'when collapsed selection is inside link element',
 		() => {
+			const balloonAddSpy = testUtils.sinon.spy( balloon, 'add' );
+
 			editor.document.schema.allow( { name: '$text', inside: '$root' } );
 			setModelData( editor.document, '<$text linkHref="url">some[] url</$text>' );
 			editor.editing.view.isFocused = true;
@@ -98,13 +102,18 @@ describe( 'Link', () => {
 
 			const linkElement = editorElement.querySelector( 'a' );
 
-			sinon.assert.calledWithExactly( balloon.view.attachTo, sinon.match( {
-				target: linkElement,
-				limiter: editorElement
-			} ) );
+			sinon.assert.calledWithExactly( balloonAddSpy, {
+				view: formView,
+				position: {
+					target: linkElement,
+					limiter: editorElement
+				}
+			} );
 		} );
 
 		it( 'should add link form to the ContextualBalloon and attach balloon to the selection, when selection is non-collapsed', () => {
+			const balloonAddSpy = testUtils.sinon.spy( balloon, 'add' );
+
 			editor.document.schema.allow( { name: '$text', inside: '$root' } );
 			setModelData( editor.document, 'so[me ur]l' );
 			editor.editing.view.isFocused = true;
@@ -113,10 +122,13 @@ describe( 'Link', () => {
 
 			const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
 
-			sinon.assert.calledWithExactly( balloon.view.attachTo, sinon.match( {
-				target: selectedRange,
-				limiter: editorElement
-			} ) );
+			sinon.assert.calledWithExactly( balloonAddSpy, {
+				view: formView,
+				position: {
+					target: selectedRange,
+					limiter: editorElement
+				}
+			} );
 		} );
 
 		it( 'should select link input value when link balloon is opened', () => {
@@ -308,6 +320,7 @@ describe( 'Link', () => {
 			} );
 
 			it( 'should keep open and update position until collapsed selection stay inside the same link element', () => {
+				const balloonUpdatePositionSpy = testUtils.sinon.spy( balloon, 'updatePosition' );
 				const observer = editor.editing.view.getObserver( ClickObserver );
 
 				editor.document.schema.allow( { name: '$text', inside: '$root' } );
@@ -320,16 +333,13 @@ describe( 'Link', () => {
 
 				expect( balloon.visibleView ).to.equal( formView );
 
-				// Reset attachTo call counter.
-				balloon.view.attachTo.reset();
-
 				// Move selection.
 				editor.editing.view.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 1, text, 1 ) ], true );
 				editor.editing.view.render();
 
 				// Check if balloon is still open and position was updated.
 				expect( balloon.visibleView ).to.equal( formView );
-				expect( balloon.view.attachTo.calledOnce ).to.true;
+				expect( balloonUpdatePositionSpy.calledOnce ).to.true;
 			} );
 
 			it( 'should not duplicate `render` listener on `ViewDocument`', () => {
@@ -415,6 +425,7 @@ describe( 'Link', () => {
 			} );
 
 			it( 'should stop updating position after close', () => {
+				const balloonUpdatePositionSpy = testUtils.sinon.spy( balloon, 'updatePosition' );
 				const observer = editor.editing.view.getObserver( ClickObserver );
 
 				editor.document.schema.allow( { name: '$text', inside: '$root' } );
@@ -430,14 +441,11 @@ describe( 'Link', () => {
 				// Close balloon by dispatching `cancel` event on formView.
 				formView.fire( 'cancel' );
 
-				// Reset attachTo call counter.
-				balloon.view.attachTo.reset();
-
 				// Move selection inside link element.
 				editor.editing.view.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 2, text, 2 ) ], true );
 				editor.editing.view.render();
 
-				expect( balloon.view.attachTo.notCalled ).to.true;
+				expect( balloonUpdatePositionSpy.notCalled ).to.true;
 			} );
 
 			it( 'should not open when selection is not inside link element', () => {