Forráskód Böngészése

Merge branch 'master' into t/101

Oskar Wróbel 8 éve
szülő
commit
0a5feabf3d

+ 3 - 3
packages/ckeditor5-link/src/link.js

@@ -11,7 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import ClickObserver from '@ckeditor/ckeditor5-engine/src/view/observer/clickobserver';
 import LinkEngine from './linkengine';
 import LinkElement from './linkelement';
-import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/contextualballoon';
+import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
 
 import clickOutsideHandler from '@ckeditor/ckeditor5-ui/src/bindings/clickoutsidehandler';
 
@@ -27,7 +27,7 @@ import '../theme/theme.scss';
  * The link plugin. It introduces the Link and Unlink buttons and the <kbd>Ctrl+K</kbd> keystroke.
  *
  * It uses the {@link module:link/linkengine~LinkEngine link engine plugin} and the
- * {@link module:ui/contextualballoon~ContextualBalloon contextual balloon plugin}.
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon plugin}.
  *
  * @extends module:core/plugin~Plugin
  */
@@ -63,7 +63,7 @@ export default class Link extends Plugin {
 		 * The contextual balloon plugin instance.
 		 *
 		 * @private
-		 * @member {module:ui/contextualballoon~ContextualBalloon}
+		 * @member {module:ui/panel/balloon/contextualballoon~ContextualBalloon}
 		 */
 		this._balloon = this.editor.plugins.get( ContextualBalloon );
 

+ 87 - 61
packages/ckeditor5-link/tests/link.js

@@ -12,7 +12,7 @@ import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-util
 
 import Link from '../src/link';
 import LinkEngine from '../src/linkengine';
-import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/contextualballoon';
+import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 
 import Range from '@ckeditor/ckeditor5-engine/src/view/range';
@@ -44,6 +44,8 @@ describe( 'Link', () => {
 			// There is no point to execute BalloonPanelView attachTo and pin methods so lets override it.
 			testUtils.sinon.stub( balloon.view, 'attachTo', () => {} );
 			testUtils.sinon.stub( balloon.view, 'pin', () => {} );
+
+			return formView.init();
 		} );
 	} );
 
@@ -91,6 +93,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;
@@ -99,13 +103,18 @@ describe( 'Link', () => {
 
 			const linkElement = editorElement.querySelector( 'a' );
 
-			sinon.assert.calledWithExactly( balloon.view.pin, 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;
@@ -114,10 +123,13 @@ describe( 'Link', () => {
 
 			const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
 
-			sinon.assert.calledWithExactly( balloon.view.pin, 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', () => {
@@ -204,21 +216,23 @@ describe( 'Link', () => {
 			sinon.assert.notCalled( spy );
 
 			// Balloon is visible, form focused.
-			balloon.add( { view: formView } );
-			formView.focusTracker.isFocused = true;
+			return balloon.add( { view: formView } )
+				.then( () => {
+					formView.focusTracker.isFocused = true;
 
-			editor.keystrokes.press( keyEvtData );
-			sinon.assert.notCalled( keyEvtData.preventDefault );
-			sinon.assert.notCalled( keyEvtData.stopPropagation );
-			sinon.assert.notCalled( spy );
+					editor.keystrokes.press( keyEvtData );
+					sinon.assert.notCalled( keyEvtData.preventDefault );
+					sinon.assert.notCalled( keyEvtData.stopPropagation );
+					sinon.assert.notCalled( spy );
 
-			// Balloon is still visible, form not focused.
-			formView.focusTracker.isFocused = false;
+					// Balloon is still visible, form not focused.
+					formView.focusTracker.isFocused = false;
 
-			editor.keystrokes.press( keyEvtData );
-			sinon.assert.calledOnce( keyEvtData.preventDefault );
-			sinon.assert.calledOnce( keyEvtData.stopPropagation );
-			sinon.assert.calledOnce( spy );
+					editor.keystrokes.press( keyEvtData );
+					sinon.assert.calledOnce( keyEvtData.preventDefault );
+					sinon.assert.calledOnce( keyEvtData.stopPropagation );
+					sinon.assert.calledOnce( spy );
+				} );
 		} );
 
 		describe( 'close listeners', () => {
@@ -231,12 +245,12 @@ describe( 'Link', () => {
 					};
 
 					// Balloon is visible.
-					balloon.add( { view: formView } );
+					return balloon.add( { view: formView } ).then( () => {
+						editor.keystrokes.press( keyEvtData );
 
-					editor.keystrokes.press( keyEvtData );
-
-					expect( balloon.visibleView ).to.null;
-					sinon.assert.notCalled( focusEditableSpy );
+						expect( balloon.visibleView ).to.null;
+						sinon.assert.notCalled( focusEditableSpy );
+					} );
 				} );
 
 				it( 'should not close after Esc key press (from editor) when panel is in stack but not visible', () => {
@@ -247,17 +261,21 @@ describe( 'Link', () => {
 					};
 
 					const viewMock = {
+						init: () => {},
 						destroy: () => {}
 					};
 
-					balloon.add( { view: formView } );
-					balloon.add( { view: viewMock } );
-
-					editor.keystrokes.press( keyEvtData );
-
-					expect( balloon.visibleView ).to.equal( viewMock );
-					expect( balloon.hasView( formView ) ).to.true;
-					sinon.assert.notCalled( focusEditableSpy );
+					return balloon.add( { view: formView } )
+						.then( () => {
+							return balloon.add( { view: viewMock } );
+						} )
+						.then( () => {
+							editor.keystrokes.press( keyEvtData );
+
+							expect( balloon.visibleView ).to.equal( viewMock );
+							expect( balloon.hasView( formView ) ).to.true;
+							sinon.assert.notCalled( focusEditableSpy );
+						} );
 				} );
 
 				it( 'should close after Esc key press (from the form) and focus editable', () => {
@@ -267,29 +285,34 @@ describe( 'Link', () => {
 						stopPropagation: sinon.spy()
 					};
 
-					balloon.add( { view: formView } );
+					return balloon.add( { view: formView } )
+						.then( () => {
+							formView.keystrokes.press( keyEvtData );
 
-					formView.keystrokes.press( keyEvtData );
-
-					expect( balloon.visibleView ).to.null;
-					sinon.assert.calledOnce( focusEditableSpy );
+							expect( balloon.visibleView ).to.null;
+							sinon.assert.calledOnce( focusEditableSpy );
+						} );
 				} );
 			} );
 
 			describe( 'mouse', () => {
 				it( 'should close and not focus editable on click outside the panel', () => {
-					balloon.add( { view: formView } );
-					document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
+					return balloon.add( { view: formView } )
+						.then( () => {
+							document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
 
-					expect( balloon.visibleView ).to.null;
-					expect( focusEditableSpy.notCalled ).to.true;
+							expect( balloon.visibleView ).to.null;
+							expect( focusEditableSpy.notCalled ).to.true;
+						} );
 				} );
 
 				it( 'should not close on click inside the panel', () => {
-					balloon.add( { view: formView } );
-					balloon.view.element.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
+					return balloon.add( { view: formView } )
+						.then( () => {
+							balloon.view.element.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
 
-					expect( balloon.visibleView ).to.equal( formView );
+							expect( balloon.visibleView ).to.equal( formView );
+						} );
 				} );
 			} );
 		} );
@@ -493,12 +516,13 @@ describe( 'Link', () => {
 			} );
 
 			it( 'should hide and focus editable on formView#submit event', () => {
-				balloon.add( { view: formView } );
-
-				formView.fire( 'submit' );
+				return balloon.add( { view: formView } )
+					.then( () => {
+						formView.fire( 'submit' );
 
-				expect( balloon.visibleView ).to.null;
-				expect( focusEditableSpy.calledOnce ).to.true;
+						expect( balloon.visibleView ).to.null;
+						expect( focusEditableSpy.calledOnce ).to.true;
+					} );
 			} );
 
 			it( 'should execute unlink command on formView#unlink event', () => {
@@ -511,21 +535,23 @@ describe( 'Link', () => {
 			} );
 
 			it( 'should hide and focus editable on formView#unlink event', () => {
-				balloon.add( { view: formView } );
-
-				formView.fire( 'unlink' );
+				return balloon.add( { view: formView } )
+					.then( () => {
+						formView.fire( 'unlink' );
 
-				expect( balloon.visibleView ).to.null;
-				expect( focusEditableSpy.calledOnce ).to.true;
+						expect( balloon.visibleView ).to.null;
+						expect( focusEditableSpy.calledOnce ).to.true;
+					} );
 			} );
 
 			it( 'should hide and focus editable on formView#cancel event', () => {
-				balloon.add( { view: formView } );
+				return balloon.add( { view: formView } )
+					.then( () => {
+						formView.fire( 'cancel' );
 
-				formView.fire( 'cancel' );
-
-				expect( balloon.visibleView ).to.null;
-				expect( focusEditableSpy.calledOnce ).to.true;
+						expect( balloon.visibleView ).to.null;
+						expect( focusEditableSpy.calledOnce ).to.true;
+					} );
 			} );
 		} );
 	} );