Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Added test checking balloon positioning with multiple stacks in rotator.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Jul 22, 2019
1 parent c39a615 commit cec3fc7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/widgettoolbarrepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand Down
37 changes: 36 additions & 1 deletion tests/widgettoolbarrepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit cec3fc7

Please sign in to comment.