8
0

link.js 21 KB

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