|
|
@@ -13,7 +13,7 @@ import { setData as setModelData } from '/ckeditor5/engine/dev-utils/model.js';
|
|
|
import Link from '/ckeditor5/link/link.js';
|
|
|
import LinkEngine from '/ckeditor5/link/linkengine.js';
|
|
|
import Button from '/ckeditor5/ui/button/button.js';
|
|
|
-import LinkBalloonPanel from '/ckeditor5/link/ui/linkballoonpanel.js';
|
|
|
+import BalloonPanel from '/ckeditor5/ui/balloonpanel/balloonpanel.js';
|
|
|
|
|
|
import Range from '/ckeditor5/engine/view/range.js';
|
|
|
import ClickObserver from '/ckeditor5/engine/view/observer/clickobserver.js';
|
|
|
@@ -21,7 +21,7 @@ import ClickObserver from '/ckeditor5/engine/view/observer/clickobserver.js';
|
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
describe( 'Link', () => {
|
|
|
- let editor, linkFeature, linkButton, unlinkButton, balloonPanel, editorElement;
|
|
|
+ let editor, linkFeature, linkButton, unlinkButton, balloonPanel, form, editorElement;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
editorElement = document.createElement( 'div' );
|
|
|
@@ -39,6 +39,7 @@ describe( 'Link', () => {
|
|
|
linkButton = editor.ui.featureComponents.create( 'link' );
|
|
|
unlinkButton = editor.ui.featureComponents.create( 'unlink' );
|
|
|
balloonPanel = linkFeature.balloonPanel;
|
|
|
+ form = linkFeature.form;
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -108,7 +109,7 @@ describe( 'Link', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should select panel input value when panel is opened', () => {
|
|
|
- const selectUrlInputSpy = testUtils.sinon.spy( balloonPanel.urlInput.view, 'select' );
|
|
|
+ const selectUrlInputSpy = testUtils.sinon.spy( linkFeature._urlInput.view, 'select' );
|
|
|
|
|
|
editor.editing.view.isFocused = true;
|
|
|
|
|
|
@@ -152,7 +153,7 @@ describe( 'Link', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should be created', () => {
|
|
|
- expect( balloonPanel ).to.instanceOf( LinkBalloonPanel );
|
|
|
+ expect( balloonPanel ).to.instanceOf( BalloonPanel );
|
|
|
} );
|
|
|
|
|
|
it( 'should be appended to the document body', () => {
|
|
|
@@ -160,7 +161,7 @@ describe( 'Link', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should open with selected url input on `CTRL+K` keystroke', () => {
|
|
|
- const selectUrlInputSpy = testUtils.sinon.spy( balloonPanel.urlInput.view, 'select' );
|
|
|
+ const selectUrlInputSpy = testUtils.sinon.spy( linkFeature._urlInput.view, 'select' );
|
|
|
|
|
|
editor.keystrokes.press( { keyCode: keyCodes.k, ctrlKey: true } );
|
|
|
|
|
|
@@ -176,59 +177,6 @@ describe( 'Link', () => {
|
|
|
expect( editor.focusTracker.isFocused ).to.true;
|
|
|
} );
|
|
|
|
|
|
- describe( 'binding', () => {
|
|
|
- it( 'should bind balloonPanel#model to link command', () => {
|
|
|
- const model = balloonPanel.model;
|
|
|
- const command = editor.commands.get( 'link' );
|
|
|
-
|
|
|
- expect( model.url ).to.undefined;
|
|
|
-
|
|
|
- command.value = 'http://cksource.com';
|
|
|
-
|
|
|
- expect( model.url ).to.equal( 'http://cksource.com' );
|
|
|
- } );
|
|
|
-
|
|
|
- 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' );
|
|
|
-
|
|
|
- expect( executeSpy.calledOnce ).to.true;
|
|
|
- expect( executeSpy.calledWithExactly( 'link', 'http://cksource.com' ) ).to.true;
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should hide and focus editable on balloonPanel#model executeLink event', () => {
|
|
|
- balloonPanel.model.fire( 'executeLink' );
|
|
|
-
|
|
|
- expect( hidePanelSpy.calledOnce ).to.true;
|
|
|
- expect( focusEditableSpy.calledOnce ).to.true;
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should execute unlink command on balloonPanel#model executeUnlink event', () => {
|
|
|
- const executeSpy = testUtils.sinon.spy( editor, 'execute' );
|
|
|
-
|
|
|
- balloonPanel.model.fire( 'executeUnlink' );
|
|
|
-
|
|
|
- expect( executeSpy.calledOnce ).to.true;
|
|
|
- expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should hide and focus editable on balloonPanel#model executeUnlink event', () => {
|
|
|
- balloonPanel.model.fire( 'executeUnlink' );
|
|
|
-
|
|
|
- expect( hidePanelSpy.calledOnce ).to.true;
|
|
|
- expect( focusEditableSpy.calledOnce ).to.true;
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should hide and focus editable on balloonPanel#model executeCancel event', () => {
|
|
|
- balloonPanel.model.fire( 'executeCancel' );
|
|
|
-
|
|
|
- expect( hidePanelSpy.calledOnce ).to.true;
|
|
|
- expect( focusEditableSpy.calledOnce ).to.true;
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
describe( 'close listeners', () => {
|
|
|
describe( 'keyboard', () => {
|
|
|
it( 'should close after `ESC` press', () => {
|
|
|
@@ -261,7 +209,7 @@ describe( 'Link', () => {
|
|
|
|
|
|
describe( 'click on editable', () => {
|
|
|
it( 'should open with not selected url input when collapsed selection is inside link element', () => {
|
|
|
- const selectUrlInputSpy = testUtils.sinon.spy( balloonPanel.urlInput.view, 'select' );
|
|
|
+ const selectUrlInputSpy = testUtils.sinon.spy( linkFeature._urlInput.view, 'select' );
|
|
|
const observer = editor.editing.view.getObserver( ClickObserver );
|
|
|
|
|
|
editor.document.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
@@ -397,6 +345,68 @@ describe( 'Link', () => {
|
|
|
} );
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'link form', () => {
|
|
|
+ let hidePanelSpy, focusEditableSpy;
|
|
|
+
|
|
|
+ beforeEach( () => {
|
|
|
+ hidePanelSpy = testUtils.sinon.spy( balloonPanel.view, 'hide' );
|
|
|
+ focusEditableSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'binding', () => {
|
|
|
+ it( 'should bind _urlInput#model to link command', () => {
|
|
|
+ const model = linkFeature._urlInput.model;
|
|
|
+ const command = editor.commands.get( 'link' );
|
|
|
+
|
|
|
+ expect( model.value ).to.undefined;
|
|
|
+
|
|
|
+ command.value = 'http://cksource.com';
|
|
|
+
|
|
|
+ expect( model.value ).to.equal( 'http://cksource.com' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should execute link command on _saveButton#model submit event', () => {
|
|
|
+ const executeSpy = testUtils.sinon.spy( editor, 'execute' );
|
|
|
+
|
|
|
+ linkFeature._urlInput.model.value = 'http://cksource.com';
|
|
|
+ form.model.fire( 'submit' );
|
|
|
+
|
|
|
+ expect( executeSpy.calledOnce ).to.true;
|
|
|
+ expect( executeSpy.calledWithExactly( 'link', 'http://cksource.com' ) ).to.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should hide and focus editable on form#model submit event', () => {
|
|
|
+ form.model.fire( 'submit' );
|
|
|
+
|
|
|
+ expect( hidePanelSpy.calledOnce ).to.true;
|
|
|
+ expect( focusEditableSpy.calledOnce ).to.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should execute unlink command on _unlinkButton#model execute event', () => {
|
|
|
+ const executeSpy = testUtils.sinon.spy( editor, 'execute' );
|
|
|
+
|
|
|
+ linkFeature._unlinkButton.model.fire( 'execute' );
|
|
|
+
|
|
|
+ expect( executeSpy.calledOnce ).to.true;
|
|
|
+ expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should hide and focus editable on _unlinkButton#model execute event', () => {
|
|
|
+ linkFeature._unlinkButton.model.fire( 'execute' );
|
|
|
+
|
|
|
+ expect( hidePanelSpy.calledOnce ).to.true;
|
|
|
+ expect( focusEditableSpy.calledOnce ).to.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should hide and focus editable on _cancelButton#model cancel event', () => {
|
|
|
+ linkFeature._cancelButton.model.fire( 'execute' );
|
|
|
+
|
|
|
+ expect( hidePanelSpy.calledOnce ).to.true;
|
|
|
+ expect( focusEditableSpy.calledOnce ).to.true;
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
// Creates and dispatches keyboard event with specified keyCode.
|