浏览代码

Added test checking balloon positioning with multiple stacks in rotator.

Oskar Wróbel 6 年之前
父节点
当前提交
2a415e7e65

+ 1 - 1
packages/ckeditor5-widget/src/widgettoolbarrepository.js

@@ -213,7 +213,7 @@ export default class WidgetToolbarRepository extends Plugin {
 
 			// Update toolbar position each time stack with toolbar view is switched to visible.
 			// This is in a case target element has changed when toolbar was in invisible stack
-			// e.g. target image was wrapper by a block quote.
+			// e.g. target image was wrapped by a block quote.
 			// See https://github.com/ckeditor/ckeditor5-widget/issues/92.
 			this.listenTo( this._balloon, 'change:visibleView', () => {
 				for ( const definition of this._toolbarDefinitions.values() ) {

+ 36 - 1
packages/ckeditor5-widget/tests/widgettoolbarrepository.js

@@ -333,7 +333,42 @@ describe( 'WidgetToolbarRepository', () => {
 				view.domConverter.viewToDom( fakeChildViewElement ) );
 		} );
 
-		it( 'should update position when is switched in rotator to a visible panel', () => {
+		it( 'should not update balloon position when toolbar is in not visible stack', () => {
+			const customView = new View();
+
+			sinon.spy( balloon.view, 'pin' );
+
+			widgetToolbarRepository.register( 'fake', {
+				items: editor.config.get( 'fake.toolbar' ),
+				getRelatedElement: getSelectedFakeWidget
+			} );
+
+			setData( model,
+				'<paragraph>foo</paragraph>' +
+				'[<fake-widget></fake-widget>]'
+			);
+
+			balloon.add( {
+				stackId: 'custom',
+				view: customView,
+				position: { target: {} }
+			} );
+
+			balloon.showStack( 'custom' );
+
+			const fakeWidgetToolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;
+
+			expect( balloon.visibleView ).to.equal( customView );
+			expect( balloon.hasView( fakeWidgetToolbarView ) ).to.equal( true );
+
+			const spy = testUtils.sinon.spy( balloon, 'updatePosition' );
+
+			editor.ui.fire( 'update' );
+
+			sinon.assert.notCalled( spy );
+		} );
+
+		it( 'should update balloon position when stack with toolbar is switched in rotator to visible', () => {
 			const view = editor.editing.view;
 			const customView = new View();