link.js 21 KB

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