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

Commit

Permalink
Merge pull request #102 from ckeditor/t/101
Browse files Browse the repository at this point in the history
Tests: Aligned tests to the latest ContextuaBalloon plugin API. Closes #101.
  • Loading branch information
oleq committed Apr 12, 2017
2 parents 84a5bf9 + 22ad049 commit c35c2ba
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ describe( 'Link', () => {
balloon = editor.plugins.get( ContextualBalloon );
formView = linkFeature.formView;

// There is no point to execute `BalloonPanelView#attachTo` so override it.
// 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();
} );
Expand Down Expand Up @@ -331,7 +332,6 @@ 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' } );
Expand All @@ -344,13 +344,15 @@ describe( 'Link', () => {

expect( balloon.visibleView ).to.equal( formView );

const updatePositionSpy = testUtils.sinon.spy( balloon, 'updatePosition' );

// 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( balloonUpdatePositionSpy.calledOnce ).to.true;
expect( updatePositionSpy.calledOnce ).to.true;
} );

it( 'should not duplicate `render` listener on `ViewDocument`', () => {
Expand Down Expand Up @@ -436,7 +438,6 @@ 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' } );
Expand All @@ -452,11 +453,13 @@ describe( 'Link', () => {
// Close balloon by dispatching `cancel` event on formView.
formView.fire( 'cancel' );

const updatePositionSpy = testUtils.sinon.spy( balloon, 'updatePosition' );

// Move selection inside link element.
editor.editing.view.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 2, text, 2 ) ], true );
editor.editing.view.render();

expect( balloonUpdatePositionSpy.notCalled ).to.true;
expect( updatePositionSpy.notCalled ).to.true;
} );

it( 'should not open when selection is not inside link element', () => {
Expand Down

0 comments on commit c35c2ba

Please sign in to comment.