|
|
@@ -80,18 +80,6 @@ describe( 'Link', () => {
|
|
|
expect( linkFeature.balloonPanel.view.isVisible ).to.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'should select panel input value when panel is opened', () => {
|
|
|
- const selectSpy = sinon.spy( linkFeature.balloonPanel.urlInput.view, 'select' );
|
|
|
-
|
|
|
- editor.editing.view.isFocused = true;
|
|
|
-
|
|
|
- linkButton.model.fire( 'execute' );
|
|
|
-
|
|
|
- expect( selectSpy.calledOnce ).to.true;
|
|
|
-
|
|
|
- selectSpy.restore();
|
|
|
- } );
|
|
|
-
|
|
|
it( 'should not open panel on linkButton#model execute event, when editor is not focused', () => {
|
|
|
editor.editing.view.isFocused = false;
|
|
|
|
|
|
@@ -101,7 +89,7 @@ describe( 'Link', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should open panel attached to the link element, when collapsed selection is inside link element', () => {
|
|
|
- const attachToSpy = sinon.spy( balloonPanel.view, 'attachTo' );
|
|
|
+ const attachToSpy = testUtils.sinon.spy( balloonPanel.view, 'attachTo' );
|
|
|
|
|
|
editor.document.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
setModelData( editor.document, '<$text linkHref="url">some[] url</$text>' );
|
|
|
@@ -115,7 +103,7 @@ describe( 'Link', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should open panel attached to the selection, when there is non-collapsed selection', () => {
|
|
|
- const attachToSpy = sinon.spy( balloonPanel.view, 'attachTo' );
|
|
|
+ const attachToSpy = testUtils.sinon.spy( balloonPanel.view, 'attachTo' );
|
|
|
|
|
|
editor.document.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
setModelData( editor.document, 'so[me ur]l' );
|
|
|
@@ -127,6 +115,16 @@ describe( 'Link', () => {
|
|
|
|
|
|
expect( attachToSpy.calledWithExactly( selectedRange, editorElement ) ).to.true;
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'should select panel input value when panel is opened', () => {
|
|
|
+ const selectUrlInputSpy = testUtils.sinon.spy( balloonPanel.urlInput.view, 'select' );
|
|
|
+
|
|
|
+ editor.editing.view.isFocused = true;
|
|
|
+
|
|
|
+ linkButton.model.fire( 'execute' );
|
|
|
+
|
|
|
+ expect( selectUrlInputSpy.calledOnce ).to.true;
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
describe( 'unlink toolbar button', () => {
|
|
|
@@ -152,114 +150,109 @@ describe( 'Link', () => {
|
|
|
expect( executeSpy.calledOnce ).to.true;
|
|
|
expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
|
|
|
} );
|
|
|
-
|
|
|
- it( 'should hide panel on unlinkButton#model execute event', () => {
|
|
|
- balloonPanel.view.model.isVisible = true;
|
|
|
-
|
|
|
- unlinkButton.model.fire( 'execute' );
|
|
|
-
|
|
|
- expect( balloonPanel.view.model.isVisible ).to.false;
|
|
|
- } );
|
|
|
} );
|
|
|
|
|
|
describe( 'link balloon panel', () => {
|
|
|
- it( 'should create LinkBalloonPanel component', () => {
|
|
|
- expect( balloonPanel ).to.instanceOf( LinkBalloonPanel );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should bind balloonPanel#model to link command', () => {
|
|
|
- const model = balloonPanel.model;
|
|
|
- const command = editor.commands.get( 'link' );
|
|
|
+ let hidePanelSpy, focusEditableSpy;
|
|
|
|
|
|
- expect( model.url ).to.undefined;
|
|
|
-
|
|
|
- command.value = 'http://cksource.com';
|
|
|
-
|
|
|
- expect( model.url ).to.equal( 'http://cksource.com' );
|
|
|
+ beforeEach( () => {
|
|
|
+ hidePanelSpy = testUtils.sinon.spy( balloonPanel.view, 'hide' );
|
|
|
+ focusEditableSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should execute link command on balloonPanel#model executeLink event', () => {
|
|
|
- const executeSpy = testUtils.sinon.spy( editor, 'execute' );
|
|
|
-
|
|
|
- balloonPanel.model.url = 'http://cksource.com';
|
|
|
- balloonPanel.model.fire( 'executeLink' );
|
|
|
+ it( 'should be created', () => {
|
|
|
+ expect( balloonPanel ).to.instanceOf( LinkBalloonPanel );
|
|
|
+ } );
|
|
|
|
|
|
- expect( executeSpy.calledOnce ).to.true;
|
|
|
- expect( executeSpy.calledWithExactly( 'link', 'http://cksource.com' ) ).to.true;
|
|
|
+ it( 'should be appended to the document body', () => {
|
|
|
+ expect( document.body.contains( balloonPanel.view.element ) );
|
|
|
} );
|
|
|
|
|
|
- it( 'should hide balloon panel on balloonPanel#model execute event', () => {
|
|
|
- const hideSpy = testUtils.sinon.spy( balloonPanel.view, 'hide' );
|
|
|
+ it( 'should open with selected url input on `CTRL+L` keystroke', () => {
|
|
|
+ const selectUrlInputSpy = testUtils.sinon.spy( balloonPanel.urlInput.view, 'select' );
|
|
|
|
|
|
- balloonPanel.model.fire( 'executeLink' );
|
|
|
+ editor.keystrokes.press( { keyCode: keyCodes.l, ctrlKey: true } );
|
|
|
|
|
|
- expect( hideSpy.calledOnce ).to.true;
|
|
|
+ expect( balloonPanel.view.model.isVisible ).to.true;
|
|
|
+ expect( selectUrlInputSpy.calledOnce ).to.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'should execute unlink command on balloonPanel#model executeUnlink event', () => {
|
|
|
- const executeSpy = testUtils.sinon.spy( editor, 'execute' );
|
|
|
+ describe( 'binding', () => {
|
|
|
+ it( 'should bind balloonPanel#model to link command', () => {
|
|
|
+ const model = balloonPanel.model;
|
|
|
+ const command = editor.commands.get( 'link' );
|
|
|
|
|
|
- balloonPanel.model.fire( 'executeUnlink' );
|
|
|
+ expect( model.url ).to.undefined;
|
|
|
|
|
|
- expect( executeSpy.calledOnce ).to.true;
|
|
|
- expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
|
|
|
- } );
|
|
|
+ command.value = 'http://cksource.com';
|
|
|
|
|
|
- it( 'should hide balloon panel on balloonPanel#model executeUnlink event', () => {
|
|
|
- const hideSpy = testUtils.sinon.spy( balloonPanel.view, 'hide' );
|
|
|
+ expect( model.url ).to.equal( 'http://cksource.com' );
|
|
|
+ } );
|
|
|
|
|
|
- balloonPanel.model.fire( 'executeUnlink' );
|
|
|
+ it( 'should execute link command on balloonPanel#model executeLink event', () => {
|
|
|
+ const executeSpy = testUtils.sinon.spy( editor, 'execute' );
|
|
|
|
|
|
- expect( hideSpy.calledOnce ).to.true;
|
|
|
- } );
|
|
|
+ balloonPanel.model.url = 'http://cksource.com';
|
|
|
+ balloonPanel.model.fire( 'executeLink' );
|
|
|
|
|
|
- it( 'should append panel element to the body', () => {
|
|
|
- expect( document.body.contains( balloonPanel.view.element ) );
|
|
|
- } );
|
|
|
+ expect( executeSpy.calledOnce ).to.true;
|
|
|
+ expect( executeSpy.calledWithExactly( 'link', 'http://cksource.com' ) ).to.true;
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should open panel on `CTRL+L` keystroke', () => {
|
|
|
- editor.keystrokes.press( { keyCode: keyCodes.l, ctrlKey: true } );
|
|
|
+ it( 'should hide and focus editable on balloonPanel#model executeLink event', () => {
|
|
|
+ balloonPanel.model.fire( 'executeLink' );
|
|
|
|
|
|
- expect( balloonPanel.view.model.isVisible ).to.true;
|
|
|
- } );
|
|
|
+ expect( hidePanelSpy.calledOnce ).to.true;
|
|
|
+ expect( focusEditableSpy.calledOnce ).to.true;
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should focus editor on balloonPanel hide', () => {
|
|
|
- const focusSpy = sinon.spy( editor.editing.view, 'focus' );
|
|
|
+ it( 'should execute unlink command on balloonPanel#model executeUnlink event', () => {
|
|
|
+ const executeSpy = testUtils.sinon.spy( editor, 'execute' );
|
|
|
|
|
|
- balloonPanel.view.model.isVisible = true;
|
|
|
+ balloonPanel.model.fire( 'executeUnlink' );
|
|
|
|
|
|
- balloonPanel.view.model.isVisible = false;
|
|
|
+ expect( executeSpy.calledOnce ).to.true;
|
|
|
+ expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
|
|
|
+ } );
|
|
|
|
|
|
- expect( focusSpy.calledOnce ).to.true;
|
|
|
- } );
|
|
|
+ it( 'should hide and focus editable on balloonPanel#model executeUnlink event', () => {
|
|
|
+ balloonPanel.model.fire( 'executeUnlink' );
|
|
|
|
|
|
- it( 'should hide panel on editor focus event', () => {
|
|
|
- balloonPanel.view.model.isVisible = true;
|
|
|
+ expect( hidePanelSpy.calledOnce ).to.true;
|
|
|
+ expect( focusEditableSpy.calledOnce ).to.true;
|
|
|
+ } );
|
|
|
|
|
|
- editor.editing.view.fire( 'focus' );
|
|
|
+ it( 'should hide and focus editable on balloonPanel#model executeCancel event', () => {
|
|
|
+ balloonPanel.model.fire( 'executeCancel' );
|
|
|
|
|
|
- expect( balloonPanel.view.model.isVisible ).to.false;
|
|
|
+ expect( hidePanelSpy.calledOnce ).to.true;
|
|
|
+ expect( focusEditableSpy.calledOnce ).to.true;
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
- it( 'should open panel on editor click, when selection is inside link element', () => {
|
|
|
- const observer = editor.editing.view.getObserver( ClickObserver );
|
|
|
+ describe( 'click on editable', () => {
|
|
|
+ it( 'should open with not selected url input when selection is inside link element', () => {
|
|
|
+ const selectUrlInputSpy = testUtils.sinon.spy( balloonPanel.urlInput.view, 'select' );
|
|
|
+ const observer = editor.editing.view.getObserver( ClickObserver );
|
|
|
|
|
|
- editor.document.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
- setModelData( editor.document, '<$text linkHref="url">some[] url</$text>' );
|
|
|
+ editor.document.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
+ setModelData( editor.document, '<$text linkHref="url">some[] url</$text>' );
|
|
|
|
|
|
- observer.fire( 'click', { target: document.body } );
|
|
|
+ observer.fire( 'click', { target: document.body } );
|
|
|
|
|
|
- expect( balloonPanel.view.model.isVisible ).to.true;
|
|
|
- } );
|
|
|
+ expect( balloonPanel.view.model.isVisible ).to.true;
|
|
|
+ expect( selectUrlInputSpy.notCalled ).to.true;
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should not open panel on editor click, when selection is not inside link element', () => {
|
|
|
- const observer = editor.editing.view.getObserver( ClickObserver );
|
|
|
+ it( 'should not open panel when selection is not inside link element', () => {
|
|
|
+ const observer = editor.editing.view.getObserver( ClickObserver );
|
|
|
|
|
|
- setModelData( editor.document, '[]' );
|
|
|
+ setModelData( editor.document, '[]' );
|
|
|
|
|
|
- observer.fire( 'click', { target: document.body } );
|
|
|
+ observer.fire( 'click', { target: document.body } );
|
|
|
|
|
|
- expect( balloonPanel.view.model.isVisible ).to.false;
|
|
|
+ expect( balloonPanel.view.model.isVisible ).to.false;
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|
|
|
} );
|