|
@@ -3,7 +3,7 @@
|
|
|
* For licensing, see LICENSE.md.
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-/* globals document */
|
|
|
|
|
|
|
+/* globals document, Event */
|
|
|
|
|
|
|
|
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
|
|
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
|
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
@@ -162,7 +162,8 @@ describe( 'Link', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should not focus the #formView when called with a `true` parameter while the balloon is opened but link form is not visible', () => {
|
|
|
|
|
|
|
+ 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 spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
|
|
|
const viewMock = {
|
|
const viewMock = {
|
|
|
ready: true,
|
|
ready: true,
|
|
@@ -214,6 +215,19 @@ describe( 'Link', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ // 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', () => {
|
|
|
|
|
+ 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';
|
|
|
|
|
+
|
|
|
|
|
+ return linkFeature._showPanel()
|
|
|
|
|
+ .then( () => {
|
|
|
|
|
+ expect( formView.urlInputView.inputView.element.value ).to.equal( 'url' );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
describe( 'when the document is rendering', () => {
|
|
describe( 'when the document is rendering', () => {
|
|
|
it( 'should not duplicate #render listeners', () => {
|
|
it( 'should not duplicate #render listeners', () => {
|
|
|
const viewDocument = editor.editing.view;
|
|
const viewDocument = editor.editing.view;
|
|
@@ -235,7 +249,7 @@ describe( 'Link', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- //https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
|
|
|
|
+ // 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', () => {
|
|
it( 'updates the position of the panel – editing a link, then the selection remains in the link upon #render', () => {
|
|
|
const viewDocument = editor.editing.view;
|
|
const viewDocument = editor.editing.view;
|
|
|
|
|
|
|
@@ -257,7 +271,7 @@ describe( 'Link', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- //https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
|
|
|
|
+ // 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', () => {
|
|
it( 'updates the position of the panel – creating a new link, then the selection moved upon #render', () => {
|
|
|
const viewDocument = editor.editing.view;
|
|
const viewDocument = editor.editing.view;
|
|
|
|
|
|
|
@@ -282,7 +296,7 @@ describe( 'Link', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- //https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
|
|
|
|
+ // 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', () => {
|
|
it( 'hides of the panel – editing a link, then the selection moved out of the link upon #render', () => {
|
|
|
const viewDocument = editor.editing.view;
|
|
const viewDocument = editor.editing.view;
|
|
|
|
|
|
|
@@ -305,11 +319,14 @@ describe( 'Link', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- //https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
|
|
|
|
+ // 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', () => {
|
|
it( 'hides of the panel – editing a link, then the selection moved to another link upon #render', () => {
|
|
|
const viewDocument = editor.editing.view;
|
|
const viewDocument = editor.editing.view;
|
|
|
|
|
|
|
|
- setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text>bar<$text linkHref="url">b[]az</$text></paragraph>' );
|
|
|
|
|
|
|
+ setModelData(
|
|
|
|
|
+ editor.document,
|
|
|
|
|
+ '<paragraph><$text linkHref="url">f[]oo</$text>bar<$text linkHref="url">b[]az</$text></paragraph>'
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
return linkFeature._showPanel()
|
|
return linkFeature._showPanel()
|
|
|
.then( () => {
|
|
.then( () => {
|
|
@@ -328,7 +345,7 @@ describe( 'Link', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- //https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
|
|
|
|
+ // https://github.com/ckeditor/ckeditor5-link/issues/113
|
|
|
it( 'hides the panel – editing a link, then the selection expands upon #render', () => {
|
|
it( 'hides the panel – editing a link, then the selection expands upon #render', () => {
|
|
|
const viewDocument = editor.editing.view;
|
|
const viewDocument = editor.editing.view;
|
|
|
|
|
|
|
@@ -582,43 +599,77 @@ describe( 'Link', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'clicking on editable', () => {
|
|
describe( 'clicking on editable', () => {
|
|
|
- let observer;
|
|
|
|
|
|
|
+ let observer, spy;
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
observer = editor.editing.view.getObserver( ClickObserver );
|
|
observer = editor.editing.view.getObserver( ClickObserver );
|
|
|
- } );
|
|
|
|
|
|
|
+ editor.document.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
|
|
|
|
|
- it( 'should open with not selected formView when collapsed selection is inside link element', () => {
|
|
|
|
|
// Method is stubbed because it returns internal promise which can't be returned in test.
|
|
// Method is stubbed because it returns internal promise which can't be returned in test.
|
|
|
- const spy = testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
|
|
|
|
|
|
|
+ spy = testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- editor.document.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
|
|
|
|
+ it( 'should open with not selected formView when collapsed selection is inside link element', () => {
|
|
|
setModelData( editor.document, '<$text linkHref="url">fo[]o</$text>' );
|
|
setModelData( editor.document, '<$text linkHref="url">fo[]o</$text>' );
|
|
|
|
|
|
|
|
observer.fire( 'click', { target: document.body } );
|
|
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 );
|
|
sinon.assert.calledWithExactly( spy );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should not open when selection is not inside link element', () => {
|
|
|
|
|
- const showSpy = testUtils.sinon.stub( linkFeature, '_showPanel' );
|
|
|
|
|
|
|
+ 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, '[]' );
|
|
setModelData( editor.document, '[]' );
|
|
|
|
|
|
|
|
observer.fire( 'click', { target: {} } );
|
|
observer.fire( 'click', { target: {} } );
|
|
|
|
|
+ sinon.assert.notCalled( spy );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- sinon.assert.notCalled( showSpy );
|
|
|
|
|
|
|
+ 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', () => {
|
|
|
|
|
- const showSpy = testUtils.sinon.stub( linkFeature, '_showPanel' );
|
|
|
|
|
|
|
+ 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>' );
|
|
|
|
|
|
|
|
- editor.document.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
|
|
- 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 (#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: {} } );
|
|
observer.fire( 'click', { target: {} } );
|
|
|
|
|
+ sinon.assert.notCalled( spy );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- sinon.assert.notCalled( showSpy );
|
|
|
|
|
|
|
+ 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 );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|