link.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  8. import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
  9. import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  11. import Link from '../src/link';
  12. import LinkEngine from '../src/linkengine';
  13. import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
  14. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  15. import Range from '@ckeditor/ckeditor5-engine/src/view/range';
  16. import ClickObserver from '@ckeditor/ckeditor5-engine/src/view/observer/clickobserver';
  17. testUtils.createSinonSandbox();
  18. describe( 'Link', () => {
  19. let editor, linkFeature, linkButton, unlinkButton, balloon, formView, editorElement;
  20. beforeEach( () => {
  21. editorElement = document.createElement( 'div' );
  22. document.body.appendChild( editorElement );
  23. return ClassicTestEditor.create( editorElement, {
  24. plugins: [ Link, Paragraph ]
  25. } )
  26. .then( newEditor => {
  27. newEditor.editing.view.attachDomRoot( editorElement );
  28. editor = newEditor;
  29. linkFeature = editor.plugins.get( Link );
  30. linkButton = editor.ui.componentFactory.create( 'link' );
  31. unlinkButton = editor.ui.componentFactory.create( 'unlink' );
  32. balloon = editor.plugins.get( ContextualBalloon );
  33. formView = linkFeature.formView;
  34. // There is no point to execute BalloonPanelView attachTo and pin methods so lets override it.
  35. testUtils.sinon.stub( balloon.view, 'attachTo', () => {} );
  36. testUtils.sinon.stub( balloon.view, 'pin', () => {} );
  37. return formView.init();
  38. } );
  39. } );
  40. afterEach( () => {
  41. editorElement.remove();
  42. return editor.destroy();
  43. } );
  44. it( 'should be loaded', () => {
  45. expect( linkFeature ).to.instanceOf( Link );
  46. } );
  47. it( 'should load LinkEngine', () => {
  48. expect( editor.plugins.get( LinkEngine ) ).to.instanceOf( LinkEngine );
  49. } );
  50. it( 'should load ContextualBalloon', () => {
  51. expect( editor.plugins.get( ContextualBalloon ) ).to.instanceOf( ContextualBalloon );
  52. } );
  53. it( 'should register click observer', () => {
  54. expect( editor.editing.view.getObserver( ClickObserver ) ).to.instanceOf( ClickObserver );
  55. } );
  56. describe( '_showPanel()', () => {
  57. let balloonAddSpy;
  58. beforeEach( () => {
  59. balloonAddSpy = testUtils.sinon.spy( balloon, 'add' );
  60. editor.editing.view.isFocused = true;
  61. } );
  62. it( 'should return promise', () => {
  63. const returned = linkFeature._showPanel();
  64. expect( returned ).to.instanceof( Promise );
  65. return returned;
  66. } );
  67. it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when text fragment is selected', () => {
  68. setModelData( editor.document, '<paragraph>f[o]o</paragraph>' );
  69. const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
  70. return linkFeature._showPanel()
  71. .then( () => {
  72. expect( balloon.visibleView ).to.equal( formView );
  73. sinon.assert.calledWithExactly( balloonAddSpy, {
  74. view: formView,
  75. position: {
  76. target: selectedRange,
  77. limiter: editorElement
  78. }
  79. } );
  80. } );
  81. } );
  82. it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when selection is collapsed', () => {
  83. setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
  84. const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
  85. return linkFeature._showPanel()
  86. .then( () => {
  87. expect( balloon.visibleView ).to.equal( formView );
  88. sinon.assert.calledWithExactly( balloonAddSpy, {
  89. view: formView,
  90. position: {
  91. target: selectedRange,
  92. limiter: editorElement
  93. }
  94. } );
  95. } );
  96. } );
  97. it( 'should add #formView to the #_balloon and attach the #_balloon to the link element when collapsed selection is inside ' +
  98. 'that link',
  99. () => {
  100. setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
  101. const linkElement = editorElement.querySelector( 'a' );
  102. return linkFeature._showPanel()
  103. .then( () => {
  104. expect( balloon.visibleView ).to.equal( formView );
  105. sinon.assert.calledWithExactly( balloonAddSpy, {
  106. view: formView,
  107. position: {
  108. target: linkElement,
  109. limiter: editorElement
  110. }
  111. } );
  112. } );
  113. } );
  114. it( 'should not focus the #formView at default', () => {
  115. const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
  116. return linkFeature._showPanel()
  117. .then( () => {
  118. sinon.assert.notCalled( spy );
  119. } );
  120. } );
  121. it( 'should not focus the #formView when called with a `false` parameter', () => {
  122. const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
  123. return linkFeature._showPanel( false )
  124. .then( () => {
  125. sinon.assert.notCalled( spy );
  126. } );
  127. } );
  128. it( 'should not focus the #formView when called with a `true` parameter while the balloon is opened but link form is not visible', () => {
  129. const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
  130. const viewMock = {
  131. ready: true,
  132. init: () => {},
  133. destroy: () => {}
  134. };
  135. return linkFeature._showPanel( false )
  136. .then( () => balloon.add( { view: viewMock } ) )
  137. .then( () => linkFeature._showPanel( true ) )
  138. .then( () => {
  139. sinon.assert.notCalled( spy );
  140. } );
  141. } );
  142. it( 'should focus the #formView when called with a `true` parameter', () => {
  143. const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
  144. return linkFeature._showPanel( true )
  145. .then( () => {
  146. sinon.assert.calledOnce( spy );
  147. } );
  148. } );
  149. it( 'should focus the #formView when called with a `true` parameter while the balloon is open and the #formView is visible', () => {
  150. const spy = testUtils.sinon.spy( formView.urlInputView, 'select' );
  151. return linkFeature._showPanel( false )
  152. .then( () => linkFeature._showPanel( true ) )
  153. .then( () => {
  154. sinon.assert.calledOnce( spy );
  155. } );
  156. } );
  157. // https://github.com/ckeditor/ckeditor5-link/issues/53
  158. it( 'should set formView.unlinkButtonView#isVisible depending on the selection in a link or not', () => {
  159. setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
  160. return linkFeature._showPanel()
  161. .then( () => {
  162. expect( formView.unlinkButtonView.isVisible ).to.be.false;
  163. setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
  164. return linkFeature._showPanel()
  165. .then( () => {
  166. expect( formView.unlinkButtonView.isVisible ).to.be.true;
  167. } );
  168. } );
  169. } );
  170. } );
  171. describe( '_hidePanel()', () => {
  172. beforeEach( () => {
  173. return balloon.add( { view: formView } );
  174. } );
  175. it( 'should remove #formView from the #_balloon', () => {
  176. linkFeature._hidePanel();
  177. expect( balloon.hasView( formView ) ).to.false;
  178. } );
  179. it( 'should not focus the `editable` by default', () => {
  180. const spy = testUtils.sinon.spy( editor.editing.view, 'focus' );
  181. linkFeature._hidePanel();
  182. sinon.assert.notCalled( spy );
  183. } );
  184. it( 'should not focus the `editable` when called with a `false` parameter', () => {
  185. const spy = testUtils.sinon.spy( editor.editing.view, 'focus' );
  186. linkFeature._hidePanel( false );
  187. sinon.assert.notCalled( spy );
  188. } );
  189. it( 'should focus the `editable` when called with a `true` parameter', () => {
  190. const spy = testUtils.sinon.spy( editor.editing.view, 'focus' );
  191. linkFeature._hidePanel( true );
  192. sinon.assert.calledOnce( spy );
  193. } );
  194. it( 'should not throw an error when #formView is not added to the `balloon`', () => {
  195. linkFeature._hidePanel( true );
  196. expect( () => {
  197. linkFeature._hidePanel( true );
  198. } ).to.not.throw();
  199. } );
  200. it( 'should clear `render` listener from ViewDocument', () => {
  201. const spy = sinon.spy();
  202. linkFeature.listenTo( editor.editing.view, 'render', spy );
  203. linkFeature._hidePanel();
  204. editor.editing.view.render();
  205. sinon.assert.notCalled( spy );
  206. } );
  207. } );
  208. describe( 'link toolbar button', () => {
  209. it( 'should register link button', () => {
  210. expect( linkButton ).to.instanceOf( ButtonView );
  211. } );
  212. it( 'should bind linkButtonView to link command', () => {
  213. const command = editor.commands.get( 'link' );
  214. command.isEnabled = true;
  215. expect( linkButton.isEnabled ).to.be.true;
  216. command.isEnabled = false;
  217. expect( linkButton.isEnabled ).to.be.false;
  218. } );
  219. it( 'should show the #_balloon on execute event with the selected #formView', () => {
  220. // Method is stubbed because it returns internal promise which can't be returned in test.
  221. const spy = testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
  222. linkButton.fire( 'execute' );
  223. sinon.assert.calledWithExactly( spy, true );
  224. } );
  225. } );
  226. describe( 'unlink toolbar button', () => {
  227. it( 'should register unlink button', () => {
  228. expect( unlinkButton ).to.instanceOf( ButtonView );
  229. } );
  230. it( 'should bind unlinkButtonView to unlink command', () => {
  231. const command = editor.commands.get( 'unlink' );
  232. command.isEnabled = true;
  233. expect( unlinkButton.isEnabled ).to.be.true;
  234. command.isEnabled = false;
  235. expect( unlinkButton.isEnabled ).to.be.false;
  236. } );
  237. it( 'should execute unlink command on unlinkButtonView execute event', () => {
  238. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  239. unlinkButton.fire( 'execute' );
  240. expect( executeSpy.calledOnce ).to.true;
  241. expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
  242. } );
  243. } );
  244. describe( 'keyboard support', () => {
  245. it( 'should show the #_balloon with selected #formView on `CTRL+K` keystroke', () => {
  246. // Method is stubbed because it returns internal promise which can't be returned in test.
  247. const spy = testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
  248. editor.keystrokes.press( { keyCode: keyCodes.k, ctrlKey: true } );
  249. sinon.assert.calledWithExactly( spy, true );
  250. } );
  251. it( 'should focus the the #formView on `Tab` key press when the #_balloon is open', () => {
  252. const keyEvtData = {
  253. keyCode: keyCodes.tab,
  254. preventDefault: sinon.spy(),
  255. stopPropagation: sinon.spy()
  256. };
  257. // Balloon is invisible, form not focused.
  258. formView.focusTracker.isFocused = false;
  259. const spy = sinon.spy( formView, 'focus' );
  260. editor.keystrokes.press( keyEvtData );
  261. sinon.assert.notCalled( keyEvtData.preventDefault );
  262. sinon.assert.notCalled( keyEvtData.stopPropagation );
  263. sinon.assert.notCalled( spy );
  264. // Balloon is visible, form focused.
  265. return linkFeature._showPanel( true )
  266. .then( () => {
  267. formView.focusTracker.isFocused = true;
  268. editor.keystrokes.press( keyEvtData );
  269. sinon.assert.notCalled( keyEvtData.preventDefault );
  270. sinon.assert.notCalled( keyEvtData.stopPropagation );
  271. sinon.assert.notCalled( spy );
  272. // Balloon is still visible, form not focused.
  273. formView.focusTracker.isFocused = false;
  274. editor.keystrokes.press( keyEvtData );
  275. sinon.assert.calledOnce( keyEvtData.preventDefault );
  276. sinon.assert.calledOnce( keyEvtData.stopPropagation );
  277. sinon.assert.calledOnce( spy );
  278. } );
  279. } );
  280. it( 'should hide the #_balloon after Esc key press (from editor) and not focus the editable', () => {
  281. const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
  282. const keyEvtData = {
  283. keyCode: keyCodes.esc,
  284. preventDefault: sinon.spy(),
  285. stopPropagation: sinon.spy()
  286. };
  287. // Balloon is visible.
  288. return linkFeature._showPanel( false ).then( () => {
  289. editor.keystrokes.press( keyEvtData );
  290. sinon.assert.calledWithExactly( spy );
  291. } );
  292. } );
  293. it( 'should not hide #_balloon after Esc key press (from editor) when #_balloon is open but is not visible', () => {
  294. const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
  295. const keyEvtData = {
  296. keyCode: keyCodes.esc,
  297. preventDefault: () => {},
  298. stopPropagation: () => {}
  299. };
  300. const viewMock = {
  301. ready: true,
  302. init: () => {},
  303. destroy: () => {}
  304. };
  305. return linkFeature._showPanel( false )
  306. .then( () => balloon.add( { view: viewMock } ) )
  307. .then( () => {
  308. editor.keystrokes.press( keyEvtData );
  309. sinon.assert.notCalled( spy );
  310. } );
  311. } );
  312. it( 'should hide the #_balloon after Esc key press (from the form) and focus the editable', () => {
  313. const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
  314. const keyEvtData = {
  315. keyCode: keyCodes.esc,
  316. preventDefault: sinon.spy(),
  317. stopPropagation: sinon.spy()
  318. };
  319. return linkFeature._showPanel( true )
  320. .then( () => {
  321. formView.keystrokes.press( keyEvtData );
  322. sinon.assert.calledWithExactly( spy, true );
  323. } );
  324. } );
  325. } );
  326. describe( 'mouse support', () => {
  327. it( 'should hide #_balloon and not focus editable on click outside the #_balloon', () => {
  328. const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
  329. return linkFeature._showPanel( true )
  330. .then( () => {
  331. document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
  332. sinon.assert.calledWithExactly( spy );
  333. } );
  334. } );
  335. it( 'should not hide #_balloon on click inside the #_balloon', () => {
  336. const spy = testUtils.sinon.spy( linkFeature, '_hidePanel' );
  337. return linkFeature._showPanel( true )
  338. .then( () => {
  339. balloon.view.element.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
  340. sinon.assert.notCalled( spy );
  341. } );
  342. } );
  343. describe( 'clicking on editable', () => {
  344. let observer;
  345. beforeEach( () => {
  346. observer = editor.editing.view.getObserver( ClickObserver );
  347. } );
  348. it( 'should open with not selected formView when collapsed selection is inside link element', () => {
  349. // Method is stubbed because it returns internal promise which can't be returned in test.
  350. const spy = testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
  351. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  352. setModelData( editor.document, '<$text linkHref="url">fo[]o</$text>' );
  353. observer.fire( 'click', { target: document.body } );
  354. sinon.assert.calledWithExactly( spy );
  355. } );
  356. it( 'should keep open and update position until collapsed selection stay inside the same link element', () => {
  357. // Method is stubbed because it returns internal promise which can't be returned in test.
  358. const showSpy = testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
  359. const hideSpy = testUtils.sinon.stub( linkFeature, '_hidePanel' );
  360. const updatePositionSpy = testUtils.sinon.stub( balloon, 'updatePosition', () => {} );
  361. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  362. setModelData( editor.document, '<$text linkHref="url">b[]ar</$text>' );
  363. const root = editor.editing.view.getRoot();
  364. const text = root.getChild( 0 ).getChild( 0 );
  365. observer.fire( 'click', { target: document.body } );
  366. // Panel is shown.
  367. sinon.assert.calledOnce( showSpy );
  368. // Move selection.
  369. editor.editing.view.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 1, text, 1 ) ], true );
  370. editor.editing.view.render();
  371. // Check if balloon is still opened (wasn't hide).
  372. sinon.assert.notCalled( hideSpy );
  373. // And position was updated
  374. sinon.assert.calledOnce( updatePositionSpy );
  375. } );
  376. it( 'should not duplicate `render` listener on `ViewDocument`', () => {
  377. const updatePositionSpy = testUtils.sinon.stub( balloon, 'updatePosition', () => {} );
  378. // Method is stubbed because it returns internal promise which can't be returned in test.
  379. testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
  380. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  381. setModelData( editor.document, '<$text linkHref="url">b[]ar</$text>' );
  382. // Click at the same link more than once.
  383. observer.fire( 'click', { target: document.body } );
  384. observer.fire( 'click', { target: document.body } );
  385. observer.fire( 'click', { target: document.body } );
  386. sinon.assert.notCalled( updatePositionSpy );
  387. const root = editor.editing.view.getRoot();
  388. const text = root.getChild( 0 ).getChild( 0 );
  389. // Move selection.
  390. editor.editing.view.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 1, text, 1 ) ], true );
  391. editor.editing.view.render();
  392. // Position should be updated only once.
  393. sinon.assert.calledOnce( updatePositionSpy );
  394. } );
  395. it( 'should close when selection goes outside the link element', () => {
  396. const hideSpy = testUtils.sinon.stub( linkFeature, '_hidePanel' );
  397. // Method is stubbed because it returns internal promise which can't be returned in test.
  398. testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
  399. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  400. setModelData( editor.document, 'foo <$text linkHref="url">b[]ar</$text>' );
  401. const root = editor.editing.view.getRoot();
  402. const text = root.getChild( 0 );
  403. observer.fire( 'click', { target: document.body } );
  404. sinon.assert.notCalled( hideSpy );
  405. editor.editing.view.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 3, text, 3 ) ], true );
  406. editor.editing.view.render();
  407. sinon.assert.calledOnce( hideSpy );
  408. } );
  409. it( 'should close when selection goes to the other link element with the same href', () => {
  410. const hideSpy = testUtils.sinon.stub( linkFeature, '_hidePanel' );
  411. // Method is stubbed because it returns internal promise which can't be returned in test.
  412. testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
  413. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  414. setModelData( editor.document, '<$text linkHref="url">f[]oo</$text> bar <$text linkHref="url">biz</$text>' );
  415. const root = editor.editing.view.getRoot();
  416. const text = root.getChild( 2 ).getChild( 0 );
  417. observer.fire( 'click', { target: document.body } );
  418. sinon.assert.notCalled( hideSpy );
  419. editor.editing.view.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 1, text, 1 ) ], true );
  420. editor.editing.view.render();
  421. sinon.assert.calledOnce( hideSpy );
  422. } );
  423. it( 'should close when selection becomes non-collapsed', () => {
  424. const hideSpy = testUtils.sinon.stub( linkFeature, '_hidePanel' );
  425. // Method is stubbed because it returns internal promise which can't be returned in test.
  426. testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
  427. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  428. setModelData( editor.document, '<$text linkHref="url">f[]oo</$text>' );
  429. const root = editor.editing.view.getRoot();
  430. const text = root.getChild( 0 ).getChild( 0 );
  431. observer.fire( 'click', { target: {} } );
  432. editor.editing.view.selection.setRanges( [ Range.createFromParentsAndOffsets( text, 1, text, 2 ) ] );
  433. editor.editing.view.render();
  434. sinon.assert.calledOnce( hideSpy );
  435. } );
  436. it( 'should not open when selection is not inside link element', () => {
  437. const showSpy = testUtils.sinon.stub( linkFeature, '_showPanel' );
  438. setModelData( editor.document, '[]' );
  439. observer.fire( 'click', { target: {} } );
  440. sinon.assert.notCalled( showSpy );
  441. } );
  442. it( 'should not open when selection is non-collapsed', () => {
  443. const showSpy = testUtils.sinon.stub( linkFeature, '_showPanel' );
  444. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  445. setModelData( editor.document, '<$text linkHref="url">f[o]o</$text>' );
  446. observer.fire( 'click', { target: {} } );
  447. sinon.assert.notCalled( showSpy );
  448. } );
  449. } );
  450. } );
  451. describe( 'link form', () => {
  452. let focusEditableSpy;
  453. beforeEach( () => {
  454. focusEditableSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
  455. } );
  456. it( 'should mark the editor ui as focused when the #formView is focused', () => {
  457. return linkFeature._showPanel()
  458. .then( () => {
  459. editor.ui.focusTracker.isFocused = false;
  460. formView.element.dispatchEvent( new Event( 'focus' ) );
  461. expect( editor.ui.focusTracker.isFocused ).to.true;
  462. } );
  463. } );
  464. describe( 'binding', () => {
  465. it( 'should bind formView.urlInputView#value to link command value', () => {
  466. const command = editor.commands.get( 'link' );
  467. expect( formView.urlInputView.value ).to.undefined;
  468. command.value = 'http://cksource.com';
  469. expect( formView.urlInputView.value ).to.equal( 'http://cksource.com' );
  470. } );
  471. it( 'should execute link command on formView#submit event', () => {
  472. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  473. formView.urlInputView.value = 'http://ckeditor.com';
  474. expect( formView.urlInputView.inputView.element.value ).to.equal( 'http://ckeditor.com' );
  475. formView.urlInputView.inputView.element.value = 'http://cksource.com';
  476. formView.fire( 'submit' );
  477. expect( executeSpy.calledOnce ).to.true;
  478. expect( executeSpy.calledWithExactly( 'link', 'http://cksource.com' ) ).to.true;
  479. } );
  480. it( 'should hide and focus editable on formView#submit event', () => {
  481. return linkFeature._showPanel()
  482. .then( () => {
  483. formView.fire( 'submit' );
  484. expect( balloon.visibleView ).to.null;
  485. expect( focusEditableSpy.calledOnce ).to.true;
  486. } );
  487. } );
  488. it( 'should execute unlink command on formView#unlink event', () => {
  489. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  490. formView.fire( 'unlink' );
  491. expect( executeSpy.calledOnce ).to.true;
  492. expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
  493. } );
  494. it( 'should hide and focus editable on formView#unlink event', () => {
  495. return linkFeature._showPanel()
  496. .then( () => {
  497. formView.fire( 'unlink' );
  498. expect( balloon.visibleView ).to.null;
  499. expect( focusEditableSpy.calledOnce ).to.true;
  500. } );
  501. } );
  502. it( 'should hide and focus editable on formView#cancel event', () => {
  503. return linkFeature._showPanel()
  504. .then( () => {
  505. formView.fire( 'cancel' );
  506. expect( balloon.visibleView ).to.null;
  507. expect( focusEditableSpy.calledOnce ).to.true;
  508. } );
  509. } );
  510. } );
  511. } );
  512. } );