| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* globals document, Event */
- import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
- import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
- import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
- import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- import Link from '../src/link';
- import LinkEngine from '../src/linkengine';
- import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
- import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
- import Range from '@ckeditor/ckeditor5-engine/src/view/range';
- import ClickObserver from '@ckeditor/ckeditor5-engine/src/view/observer/clickobserver';
- testUtils.createSinonSandbox();
- describe( 'Link', () => {
- let editor, linkFeature, linkButton, unlinkButton, balloon, formView, editorElement;
- beforeEach( () => {
- editorElement = document.createElement( 'div' );
- document.body.appendChild( editorElement );
- return ClassicTestEditor
- .create( editorElement, {
- plugins: [ Link, Paragraph ]
- } )
- .then( newEditor => {
- newEditor.editing.view.attachDomRoot( editorElement );
- editor = newEditor;
- linkFeature = editor.plugins.get( Link );
- linkButton = editor.ui.componentFactory.create( 'link' );
- unlinkButton = editor.ui.componentFactory.create( 'unlink' );
- balloon = editor.plugins.get( ContextualBalloon );
- formView = linkFeature.formView;
- // There is no point to execute BalloonPanelView attachTo and pin methods so lets override it.
- testUtils.sinon.stub( balloon.view, 'attachTo' ).returns( {} );
- testUtils.sinon.stub( balloon.view, 'pin' ).returns( {} );
- formView.init();
- } );
- } );
- afterEach( () => {
- editorElement.remove();
- return editor.destroy();
- } );
- it( 'should be loaded', () => {
- expect( linkFeature ).to.instanceOf( Link );
- } );
- it( 'should load LinkEngine', () => {
- expect( editor.plugins.get( LinkEngine ) ).to.instanceOf( LinkEngine );
- } );
- it( 'should load ContextualBalloon', () => {
- expect( editor.plugins.get( ContextualBalloon ) ).to.instanceOf( ContextualBalloon );
- } );
- it( 'should register click observer', () => {
- expect( editor.editing.view.getObserver( ClickObserver ) ).to.instanceOf( ClickObserver );
- } );
- describe( '_showPanel()', () => {
- let balloonAddSpy;
- beforeEach( () => {
- balloonAddSpy = testUtils.sinon.spy( balloon, 'add' );
- editor.editing.view.isFocused = true;
- } );
- it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when text fragment is selected', () => {
- setModelData( editor.document, '<paragraph>f[o]o</paragraph>' );
- const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
- linkFeature._showPanel();
- expect( balloon.visibleView ).to.equal( formView );
- sinon.assert.calledWithExactly( balloonAddSpy, {
- view: formView,
- position: {
- target: selectedRange,
- limiter: editorElement
- }
- } );
- } );
- it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when selection is collapsed', () => {
- setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
- const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
- linkFeature._showPanel();
- expect( balloon.visibleView ).to.equal( formView );
- sinon.assert.calledWithExactly( balloonAddSpy, {
- view: formView,
- position: {
- target: selectedRange,
- limiter: editorElement
- }
- } );
- } );
- it( 'should add #formView to the #_balloon and attach the #_balloon to the link element when collapsed selection is inside ' +
- 'that link',
- () => {
- setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
- const linkElement = editorElement.querySelector( 'a' );
- linkFeature._showPanel();
- expect( balloon.visibleView ).to.equal( formView );
- sinon.assert.calledWithExactly( balloonAddSpy, {
- view: formView,
- position: {
- target: linkElement,
- limiter: editorElement
- }
- } );
- } );
- it( 'should not focus the #formView at default', () => {
- const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
- linkFeature._showPanel();
- sinon.assert.notCalled( spy );
- } );
- it( 'should not focus the #formView when called with a `false` parameter', () => {
- const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
- linkFeature._showPanel( false );
- sinon.assert.notCalled( spy );
- } );
- it( 'should not focus the #formView when called with a `true` parameter while the balloon is opened but link ' +
- 'form is not visible', () => {
- const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
- const viewMock = {
- ready: true,
- init: () => {},
- destroy: () => {}
- };
- linkFeature._showPanel( false );
- balloon.add( { view: viewMock } );
- linkFeature._showPanel( true );
- sinon.assert.notCalled( spy );
- } );
- it( 'should focus the #formView when called with a `true` parameter', () => {
- const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
- linkFeature._showPanel( true );
- sinon.assert.calledOnce( spy );
- } );
- it( 'should focus the #formView when called with a `true` parameter while the balloon is open and the #formView is visible', () => {
- const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
- linkFeature._showPanel( false );
- linkFeature._showPanel( true );
- sinon.assert.calledOnce( spy );
- } );
- it( 'should disable #formView elements when link and unlink commands are disabled', () => {
- setModelData( editor.document, '<paragraph>f[o]o</paragraph>' );
- linkFeature._showPanel();
- editor.commands.get( 'link' ).isEnabled = true;
- editor.commands.get( 'unlink' ).isEnabled = true;
- expect( formView.urlInputView.isReadOnly ).to.false;
- expect( formView.saveButtonView.isEnabled ).to.true;
- expect( formView.unlinkButtonView.isEnabled ).to.true;
- expect( formView.cancelButtonView.isEnabled ).to.true;
- editor.commands.get( 'link' ).isEnabled = false;
- editor.commands.get( 'unlink' ).isEnabled = false;
- expect( formView.urlInputView.isReadOnly ).to.true;
- expect( formView.saveButtonView.isEnabled ).to.false;
- expect( formView.unlinkButtonView.isEnabled ).to.false;
- expect( formView.cancelButtonView.isEnabled ).to.true;
- } );
- // https://github.com/ckeditor/ckeditor5-link/issues/53
- it( 'should set formView.unlinkButtonView#isVisible depending on the selection in a link or not', () => {
- setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
- linkFeature._showPanel();
- expect( formView.unlinkButtonView.isVisible ).to.be.false;
- setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
- linkFeature._showPanel();
- expect( formView.unlinkButtonView.isVisible ).to.be.true;
- setModelData( editor.document, '<paragraph><$text linkHref="url">[fo]o</$text></paragraph>' );
- linkFeature._showPanel();
- expect( formView.unlinkButtonView.isVisible ).to.be.true;
- } );
- // https://github.com/ckeditor/ckeditor5-link/issues/78
- it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (selected link)', () => {
- setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
- // Mock some leftover value **in DOM**, e.g. after previous editing.
- formView.urlInputView.inputView.element.value = 'leftover';
- linkFeature._showPanel();
- expect( formView.urlInputView.inputView.element.value ).to.equal( 'url' );
- } );
- // https://github.com/ckeditor/ckeditor5-link/issues/123
- it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (no link selected)', () => {
- setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
- linkFeature._showPanel();
- expect( formView.urlInputView.inputView.element.value ).to.equal( '' );
- } );
- describe( 'when the document is rendering', () => {
- it( 'should not duplicate #render listeners', () => {
- const viewDocument = editor.editing.view;
- setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
- const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
- linkFeature._showPanel();
- viewDocument.render();
- linkFeature._hidePanel();
- linkFeature._showPanel();
- viewDocument.render();
- sinon.assert.calledTwice( spy );
- } );
- // https://github.com/ckeditor/ckeditor5-link/issues/113
- it( 'updates the position of the panel – editing a link, then the selection remains in the link upon #render', () => {
- const viewDocument = editor.editing.view;
- setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
- linkFeature._showPanel();
- const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
- const root = viewDocument.getRoot();
- const text = root.getChild( 0 ).getChild( 0 ).getChild( 0 );
- // Move selection to foo[].
- viewDocument.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 3, text, 3 ) ], true );
- viewDocument.render();
- sinon.assert.calledOnce( spy );
- sinon.assert.calledWithExactly( spy );
- } );
- // https://github.com/ckeditor/ckeditor5-link/issues/113
- it( 'updates the position of the panel – creating a new link, then the selection moved upon #render', () => {
- const viewDocument = editor.editing.view;
- setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
- linkFeature._showPanel();
- const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
- // Fires #render.
- const root = viewDocument.getRoot();
- const text = root.getChild( 0 ).getChild( 0 );
- viewDocument.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 3, text, 3 ) ], true );
- viewDocument.render();
- sinon.assert.calledOnce( spy );
- sinon.assert.calledWithExactly( spy, {
- target: editorElement.ownerDocument.getSelection().getRangeAt( 0 ),
- limiter: editorElement
- } );
- } );
- // https://github.com/ckeditor/ckeditor5-link/issues/113
- it( 'hides of the panel – editing a link, then the selection moved out of the link upon #render', () => {
- const viewDocument = editor.editing.view;
- setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text>bar</paragraph>' );
- linkFeature._showPanel();
- const spyUpdate = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
- const spyHide = testUtils.sinon.spy( linkFeature, '_hidePanel' );
- const root = viewDocument.getRoot();
- const text = root.getChild( 0 ).getChild( 1 );
- // Move selection to b[]ar.
- viewDocument.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 1, text, 1 ) ], true );
- viewDocument.render();
- sinon.assert.calledOnce( spyHide );
- sinon.assert.notCalled( spyUpdate );
- } );
- // https://github.com/ckeditor/ckeditor5-link/issues/113
- it( 'hides of the panel – editing a link, then the selection moved to another link upon #render', () => {
- const viewDocument = editor.editing.view;
- setModelData(
- editor.document,
- '<paragraph><$text linkHref="url">f[]oo</$text>bar<$text linkHref="url">b[]az</$text></paragraph>'
- );
- linkFeature._showPanel();
- const spyUpdate = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
- const spyHide = testUtils.sinon.spy( linkFeature, '_hidePanel' );
- const root = viewDocument.getRoot();
- const text = root.getChild( 0 ).getChild( 2 ).getChild( 0 );
- // Move selection to b[]az.
- viewDocument.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 1, text, 1 ) ], true );
- viewDocument.render();
- sinon.assert.calledOnce( spyHide );
- sinon.assert.notCalled( spyUpdate );
- } );
- // https://github.com/ckeditor/ckeditor5-link/issues/113
- it( 'hides the panel – editing a link, then the selection expands upon #render', () => {
- const viewDocument = editor.editing.view;
- setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
- linkFeature._showPanel();
- const spyUpdate = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
- const spyHide = testUtils.sinon.spy( linkFeature, '_hidePanel' );
- const root = viewDocument.getRoot();
- const text = root.getChild( 0 ).getChild( 0 ).getChild( 0 );
- // Move selection to f[o]o.
- viewDocument.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 1, text, 2 ) ], true );
- viewDocument.render();
- sinon.assert.calledOnce( spyHide );
- sinon.assert.notCalled( spyUpdate );
- } );
- } );
- } );
- describe( '_hidePanel()', () => {
- beforeEach( () => {
- return balloon.add( { view: formView } );
- } );
- it( 'should remove #formView from the #_balloon', () => {
- linkFeature._hidePanel();
- expect( balloon.hasView( formView ) ).to.false;
- } );
- it( 'should not focus the `editable` by default', () => {
- const spy = testUtils.sinon.spy( editor.editing.view, 'focus' );
- linkFeature._hidePanel();
- sinon.assert.notCalled( spy );
- } );
- it( 'should not focus the `editable` when called with a `false` parameter', () => {
- const spy = testUtils.sinon.spy( editor.editing.view, 'focus' );
- linkFeature._hidePanel( false );
- sinon.assert.notCalled( spy );
- } );
- it( 'should focus the `editable` when called with a `true` parameter', () => {
- const spy = testUtils.sinon.spy( editor.editing.view, 'focus' );
- linkFeature._hidePanel( true );
- sinon.assert.calledOnce( spy );
- } );
- it( 'should not throw an error when #formView is not added to the `balloon`', () => {
- linkFeature._hidePanel( true );
- expect( () => {
- linkFeature._hidePanel( true );
- } ).to.not.throw();
- } );
- it( 'should clear `render` listener from ViewDocument', () => {
- const spy = sinon.spy();
- linkFeature.listenTo( editor.editing.view, 'render', spy );
- linkFeature._hidePanel();
- editor.editing.view.render();
- sinon.assert.notCalled( spy );
- } );
- } );
- describe( 'link toolbar button', () => {
- it( 'should register link button', () => {
- expect( linkButton ).to.instanceOf( ButtonView );
- } );
- it( 'should bind linkButtonView to link command', () => {
- const command = editor.commands.get( 'link' );
- command.isEnabled = true;
- expect( linkButton.isEnabled ).to.be.true;
- command.isEnabled = false;
- expect( linkButton.isEnabled ).to.be.false;
- } );
- it( 'should show the #_balloon on execute event with the selected #formView', () => {
- const spy = testUtils.sinon.stub( linkFeature, '_showPanel' ).returns( {} );
- linkButton.fire( 'execute' );
- sinon.assert.calledWithExactly( spy, true );
- } );
- } );
- describe( 'unlink toolbar button', () => {
- it( 'should register unlink button', () => {
- expect( unlinkButton ).to.instanceOf( ButtonView );
- } );
- it( 'should bind unlinkButtonView to unlink command', () => {
- const command = editor.commands.get( 'unlink' );
- command.isEnabled = true;
- expect( unlinkButton.isEnabled ).to.be.true;
- command.isEnabled = false;
- expect( unlinkButton.isEnabled ).to.be.false;
- } );
- it( 'should execute unlink command on unlinkButtonView execute event', () => {
- const executeSpy = testUtils.sinon.spy( editor, 'execute' );
- unlinkButton.fire( 'execute' );
- expect( executeSpy.calledOnce ).to.true;
- expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
- } );
- } );
- describe( 'keyboard support', () => {
- it( 'should show the #_balloon with selected #formView on Ctrl+K keystroke', () => {
- const spy = testUtils.sinon.stub( linkFeature, '_showPanel' ).returns( {} );
- const command = editor.commands.get( 'link' );
- command.isEnabled = false;
- editor.keystrokes.press( { keyCode: keyCodes.k, ctrlKey: true } );
- sinon.assert.notCalled( spy );
- command.isEnabled = true;
- editor.keystrokes.press( { keyCode: keyCodes.k, ctrlKey: true } );
- sinon.assert.calledWithExactly( spy, true );
- } );
- it( 'should focus the the #formView on `Tab` key press when the #_balloon is open', () => {
- const keyEvtData = {
- keyCode: keyCodes.tab,
- preventDefault: sinon.spy(),
- stopPropagation: sinon.spy()
- };
- // Balloon is invisible, form not focused.
- formView.focusTracker.isFocused = false;
- const spy = sinon.spy( formView, 'focus' );
- editor.keystrokes.press( keyEvtData );
- sinon.assert.notCalled( keyEvtData.preventDefault );
- sinon.assert.notCalled( keyEvtData.stopPropagation );
- sinon.assert.notCalled( spy );
- // Balloon is visible, form focused.
- linkFeature._showPanel( true );
- formView.focusTracker.isFocused = true;
- editor.keystrokes.press( keyEvtData );
- sinon.assert.notCalled( keyEvtData.preventDefault );
- sinon.assert.notCalled( keyEvtData.stopPropagation );
- sinon.assert.notCalled( spy );
- // Balloon is still visible, form not focused.
- formView.focusTracker.isFocused = false;
- editor.keystrokes.press( keyEvtData );
- sinon.assert.calledOnce( keyEvtData.preventDefault );
- sinon.assert.calledOnce( keyEvtData.stopPropagation );
- sinon.assert.calledOnce( spy );
- } );
- it( 'should hide the #_balloon after Esc key press (from editor) and not focus the editable', () => {
- const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
- const keyEvtData = {
- keyCode: keyCodes.esc,
- preventDefault: sinon.spy(),
- stopPropagation: sinon.spy()
- };
- // Balloon is visible.
- linkFeature._showPanel( false );
- editor.keystrokes.press( keyEvtData );
- sinon.assert.calledWithExactly( spy );
- } );
- it( 'should not hide #_balloon after Esc key press (from editor) when #_balloon is open but is not visible', () => {
- const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
- const keyEvtData = {
- keyCode: keyCodes.esc,
- preventDefault: () => {},
- stopPropagation: () => {}
- };
- const viewMock = {
- ready: true,
- init: () => {},
- destroy: () => {}
- };
- linkFeature._showPanel( false );
- balloon.add( { view: viewMock } );
- editor.keystrokes.press( keyEvtData );
- sinon.assert.notCalled( spy );
- } );
- it( 'should hide the #_balloon after Esc key press (from the form) and focus the editable', () => {
- const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
- const keyEvtData = {
- keyCode: keyCodes.esc,
- preventDefault: sinon.spy(),
- stopPropagation: sinon.spy()
- };
- linkFeature._showPanel( true );
- formView.keystrokes.press( keyEvtData );
- sinon.assert.calledWithExactly( spy, true );
- } );
- } );
- describe( 'mouse support', () => {
- it( 'should hide #_balloon and not focus editable on click outside the #_balloon', () => {
- const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
- linkFeature._showPanel( true );
- document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
- sinon.assert.calledWithExactly( spy );
- } );
- it( 'should not hide #_balloon on click inside the #_balloon', () => {
- const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
- linkFeature._showPanel( true );
- balloon.view.element.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
- sinon.assert.notCalled( spy );
- } );
- describe( 'clicking on editable', () => {
- let observer, spy;
- beforeEach( () => {
- observer = editor.editing.view.getObserver( ClickObserver );
- editor.document.schema.allow( { name: '$text', inside: '$root' } );
- spy = testUtils.sinon.stub( linkFeature, '_showPanel' ).returns( {} );
- } );
- it( 'should open with not selected formView when collapsed selection is inside link element', () => {
- setModelData( editor.document, '<$text linkHref="url">fo[]o</$text>' );
- observer.fire( 'click', { target: document.body } );
- sinon.assert.calledWithExactly( spy );
- } );
- it( 'should open when selection exclusively encloses a LinkElement (#1)', () => {
- setModelData( editor.document, '[<$text linkHref="url">foo</$text>]' );
- observer.fire( 'click', { target: {} } );
- sinon.assert.calledWithExactly( spy );
- } );
- it( 'should open when selection exclusively encloses a LinkElement (#2)', () => {
- setModelData( editor.document, '<$text linkHref="url">[foo]</$text>' );
- observer.fire( 'click', { target: {} } );
- sinon.assert.calledWithExactly( spy );
- } );
- it( 'should not open when selection is not inside link element', () => {
- setModelData( editor.document, '[]' );
- observer.fire( 'click', { target: {} } );
- sinon.assert.notCalled( spy );
- } );
- it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#1)', () => {
- setModelData( editor.document, '<$text linkHref="url">f[o]o</$text>' );
- observer.fire( 'click', { target: {} } );
- sinon.assert.notCalled( spy );
- } );
- it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#2)', () => {
- setModelData( editor.document, '<$text linkHref="url">[fo]o</$text>' );
- observer.fire( 'click', { target: {} } );
- sinon.assert.notCalled( spy );
- } );
- it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#3)', () => {
- setModelData( editor.document, '<$text linkHref="url">f[oo]</$text>' );
- observer.fire( 'click', { target: {} } );
- sinon.assert.notCalled( spy );
- } );
- it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#4)', () => {
- setModelData( editor.document, 'ba[r<$text linkHref="url">foo]</$text>' );
- observer.fire( 'click', { target: {} } );
- sinon.assert.notCalled( spy );
- } );
- it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#5)', () => {
- setModelData( editor.document, 'ba[r<$text linkHref="url">foo</$text>]' );
- observer.fire( 'click', { target: {} } );
- sinon.assert.notCalled( spy );
- } );
- } );
- } );
- describe( 'link form', () => {
- let focusEditableSpy;
- beforeEach( () => {
- focusEditableSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
- } );
- it( 'should mark the editor ui as focused when the #formView is focused', () => {
- linkFeature._showPanel();
- editor.ui.focusTracker.isFocused = false;
- formView.element.dispatchEvent( new Event( 'focus' ) );
- expect( editor.ui.focusTracker.isFocused ).to.true;
- } );
- describe( 'binding', () => {
- it( 'should bind formView.urlInputView#value to link command value', () => {
- const command = editor.commands.get( 'link' );
- expect( formView.urlInputView.value ).to.undefined;
- command.value = 'http://cksource.com';
- expect( formView.urlInputView.value ).to.equal( 'http://cksource.com' );
- } );
- it( 'should execute link command on formView#submit event', () => {
- const executeSpy = testUtils.sinon.spy( editor, 'execute' );
- formView.urlInputView.value = 'http://ckeditor.com';
- expect( formView.urlInputView.inputView.element.value ).to.equal( 'http://ckeditor.com' );
- formView.urlInputView.inputView.element.value = 'http://cksource.com';
- formView.fire( 'submit' );
- expect( executeSpy.calledOnce ).to.true;
- expect( executeSpy.calledWithExactly( 'link', 'http://cksource.com' ) ).to.true;
- } );
- it( 'should hide and focus editable on formView#submit event', () => {
- linkFeature._showPanel();
- formView.fire( 'submit' );
- expect( balloon.visibleView ).to.null;
- expect( focusEditableSpy.calledOnce ).to.true;
- } );
- it( 'should execute unlink command on formView#unlink event', () => {
- const executeSpy = testUtils.sinon.spy( editor, 'execute' );
- formView.fire( 'unlink' );
- expect( executeSpy.calledOnce ).to.true;
- expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
- } );
- it( 'should hide and focus editable on formView#unlink event', () => {
- linkFeature._showPanel();
- formView.fire( 'unlink' );
- expect( balloon.visibleView ).to.null;
- expect( focusEditableSpy.calledOnce ).to.true;
- } );
- it( 'should hide and focus editable on formView#cancel event', () => {
- linkFeature._showPanel();
- formView.fire( 'cancel' );
- expect( balloon.visibleView ).to.null;
- expect( focusEditableSpy.calledOnce ).to.true;
- } );
- } );
- } );
- } );
|