tablecellpropertiesui.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals document, Event */
  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 { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import Undo from '@ckeditor/ckeditor5-undo/src/undo';
  11. import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
  12. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  13. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  14. import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
  15. import Table from '../../src/table';
  16. import TableCellPropertiesEditing from '../../src/tablecellproperties/tablecellpropertiesediting';
  17. import TableCellPropertiesUI from '../../src/tablecellproperties/tablecellpropertiesui';
  18. import TableCellPropertiesUIView from '../../src/tablecellproperties/ui/tablecellpropertiesview';
  19. describe( 'table cell properties', () => {
  20. describe( 'TableCellPropertiesUI', () => {
  21. let editor, editorElement, contextualBalloon,
  22. tableCellPropertiesUI, tableCellPropertiesView, tableCellPropertiesButton,
  23. clock;
  24. testUtils.createSinonSandbox();
  25. beforeEach( () => {
  26. clock = sinon.useFakeTimers();
  27. editorElement = document.createElement( 'div' );
  28. document.body.appendChild( editorElement );
  29. return ClassicTestEditor
  30. .create( editorElement, {
  31. plugins: [ Table, TableCellPropertiesEditing, TableCellPropertiesUI, Paragraph, Undo ],
  32. initialData: '<table><tr><td>foo</td></tr></table><p>bar</p>'
  33. } )
  34. .then( newEditor => {
  35. editor = newEditor;
  36. tableCellPropertiesUI = editor.plugins.get( TableCellPropertiesUI );
  37. tableCellPropertiesButton = editor.ui.componentFactory.create( 'tableCellProperties' );
  38. contextualBalloon = editor.plugins.get( ContextualBalloon );
  39. tableCellPropertiesView = tableCellPropertiesUI.view;
  40. // There is no point to execute BalloonPanelView attachTo and pin methods so lets override it.
  41. testUtils.sinon.stub( contextualBalloon.view, 'attachTo' ).returns( {} );
  42. testUtils.sinon.stub( contextualBalloon.view, 'pin' ).returns( {} );
  43. } );
  44. } );
  45. afterEach( () => {
  46. clock.restore();
  47. editorElement.remove();
  48. return editor.destroy();
  49. } );
  50. it( 'should be named', () => {
  51. expect( TableCellPropertiesUI.pluginName ).to.equal( 'TableCellPropertiesUI' );
  52. } );
  53. it( 'should load ContextualBalloon', () => {
  54. expect( editor.plugins.get( ContextualBalloon ) ).to.be.instanceOf( ContextualBalloon );
  55. } );
  56. describe( 'init()', () => {
  57. it( 'should set a batch', () => {
  58. expect( tableCellPropertiesUI._undoStepBatch ).to.be.null;
  59. } );
  60. describe( '#view', () => {
  61. it( 'should be created', () => {
  62. expect( tableCellPropertiesUI.view ).to.be.instanceOf( TableCellPropertiesUIView );
  63. } );
  64. it( 'should be rendered', () => {
  65. expect( tableCellPropertiesUI.view.isRendered ).to.be.true;
  66. } );
  67. } );
  68. describe( 'toolbar button', () => {
  69. it( 'should be registered', () => {
  70. expect( tableCellPropertiesButton ).to.be.instanceOf( ButtonView );
  71. } );
  72. it( 'should have a label', () => {
  73. expect( tableCellPropertiesButton.label ).to.equal( 'Cell properties' );
  74. } );
  75. it( 'should have a tooltip', () => {
  76. expect( tableCellPropertiesButton.tooltip ).to.be.true;
  77. } );
  78. it( 'should call #_showView upon #execute', () => {
  79. const spy = testUtils.sinon.stub( tableCellPropertiesUI, '_showView' ).returns( {} );
  80. tableCellPropertiesButton.fire( 'execute' );
  81. sinon.assert.calledOnce( spy );
  82. } );
  83. } );
  84. } );
  85. describe( 'destroy()', () => {
  86. it( 'should destroy the #view', () => {
  87. const spy = sinon.spy( tableCellPropertiesView, 'destroy' );
  88. tableCellPropertiesUI.destroy();
  89. sinon.assert.calledOnce( spy );
  90. } );
  91. } );
  92. describe( 'Properties #view', () => {
  93. beforeEach( () => {
  94. editor.model.change( writer => {
  95. writer.setSelection( editor.model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ), 0 );
  96. } );
  97. } );
  98. it( 'should hide on #submit', () => {
  99. tableCellPropertiesButton.fire( 'execute' );
  100. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  101. tableCellPropertiesView.fire( 'submit' );
  102. expect( contextualBalloon.visibleView ).to.be.null;
  103. } );
  104. describe( '#cancel event', () => {
  105. // https://github.com/ckeditor/ckeditor5/issues/6180
  106. it( 'should not undo if it there were no changes made to the property fields', () => {
  107. const spy = sinon.spy( editor, 'execute' );
  108. // Show the view. New batch will be created.
  109. tableCellPropertiesButton.fire( 'execute' );
  110. // Cancel the view immediately.
  111. tableCellPropertiesView.fire( 'cancel' );
  112. sinon.assert.notCalled( spy );
  113. } );
  114. it( 'should undo the entire batch of changes if there were some', () => {
  115. const spy = sinon.spy( editor, 'execute' );
  116. // Show the view. New batch will be created.
  117. tableCellPropertiesButton.fire( 'execute' );
  118. // Do the changes like a user.
  119. tableCellPropertiesView.borderStyle = 'dotted';
  120. tableCellPropertiesView.backgroundColor = 'red';
  121. expect( getModelData( editor.model ) ).to.equal(
  122. '<table>' +
  123. '<tableRow>' +
  124. '<tableCell backgroundColor="red" borderStyle="dotted">' +
  125. '<paragraph>[]foo</paragraph>' +
  126. '</tableCell>' +
  127. '</tableRow>' +
  128. '</table>' +
  129. '<paragraph>bar</paragraph>'
  130. );
  131. tableCellPropertiesView.fire( 'cancel' );
  132. expect( getModelData( editor.model ) ).to.equal(
  133. '<table>' +
  134. '<tableRow>' +
  135. '<tableCell>' +
  136. '<paragraph>[]foo</paragraph>' +
  137. '</tableCell>' +
  138. '</tableRow>' +
  139. '</table>' +
  140. '<paragraph>bar</paragraph>'
  141. );
  142. sinon.assert.calledWith( spy, 'undo', tableCellPropertiesUI._undoStepBatch );
  143. } );
  144. it( 'should hide the view', () => {
  145. tableCellPropertiesButton.fire( 'execute' );
  146. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  147. tableCellPropertiesView.fire( 'cancel' );
  148. expect( contextualBalloon.visibleView ).to.be.null;
  149. } );
  150. } );
  151. it( 'should hide on the Esc key press', () => {
  152. const keyEvtData = {
  153. keyCode: keyCodes.esc,
  154. preventDefault: sinon.spy(),
  155. stopPropagation: sinon.spy()
  156. };
  157. tableCellPropertiesButton.fire( 'execute' );
  158. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  159. tableCellPropertiesView.keystrokes.press( keyEvtData );
  160. expect( contextualBalloon.visibleView ).to.be.null;
  161. } );
  162. it( 'should hide if the table cell is no longer selected on EditorUI#update', () => {
  163. tableCellPropertiesButton.fire( 'execute' );
  164. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  165. editor.model.change( writer => {
  166. // Set selection in the paragraph.
  167. writer.setSelection( editor.model.document.getRoot().getChild( 1 ), 0 );
  168. } );
  169. expect( contextualBalloon.visibleView ).to.be.null;
  170. } );
  171. it( 'should reposition if table cell is still selected on on EditorUI#update', () => {
  172. tableCellPropertiesButton.fire( 'execute' );
  173. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  174. editor.model.change( writer => {
  175. writer.insertText( 'qux', editor.model.document.selection.getFirstPosition() );
  176. } );
  177. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  178. } );
  179. it( 'should hide if clicked outside the balloon', () => {
  180. tableCellPropertiesButton.fire( 'execute' );
  181. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  182. document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
  183. expect( contextualBalloon.visibleView ).to.be.null;
  184. } );
  185. describe( 'property changes', () => {
  186. beforeEach( () => {
  187. tableCellPropertiesUI._undoStepBatch = 'foo';
  188. } );
  189. describe( '#borderStyle', () => {
  190. it( 'should affect the editor state', () => {
  191. const spy = testUtils.sinon.stub( editor, 'execute' );
  192. tableCellPropertiesView.borderStyle = 'dotted';
  193. sinon.assert.calledOnce( spy );
  194. sinon.assert.calledWithExactly( spy, 'tableCellBorderStyle', { value: 'dotted', batch: 'foo' } );
  195. } );
  196. } );
  197. describe( '#borderColor', () => {
  198. it( 'should affect the editor state', () => {
  199. const spy = testUtils.sinon.stub( editor, 'execute' );
  200. tableCellPropertiesView.borderColor = '#FFAAFF';
  201. sinon.assert.calledOnce( spy );
  202. sinon.assert.calledWithExactly( spy, 'tableCellBorderColor', { value: '#FFAAFF', batch: 'foo' } );
  203. } );
  204. it( 'should display an error message if value is invalid', () => {
  205. const spy = testUtils.sinon.stub( editor, 'execute' );
  206. // First, let's pass an invalid value and check what happens.
  207. tableCellPropertiesView.borderColor = '42';
  208. clock.tick( 500 );
  209. expect( tableCellPropertiesView.borderColorInput.errorText ).to.match( /^The color is invalid/ );
  210. sinon.assert.notCalled( spy );
  211. // And now let's pass a valid value and check if the error text will be gone.
  212. tableCellPropertiesView.borderColor = '#AAA';
  213. clock.tick( 500 );
  214. expect( tableCellPropertiesView.borderColorInput.errorText ).to.be.null;
  215. sinon.assert.calledWithExactly( spy, 'tableCellBorderColor', { value: '#AAA', batch: 'foo' } );
  216. } );
  217. } );
  218. describe( '#borderWidth', () => {
  219. it( 'should affect the editor state', () => {
  220. const spy = testUtils.sinon.stub( editor, 'execute' );
  221. tableCellPropertiesView.borderWidth = '12px';
  222. sinon.assert.calledOnce( spy );
  223. sinon.assert.calledWithExactly( spy, 'tableCellBorderWidth', { value: '12px', batch: 'foo' } );
  224. } );
  225. it( 'should display an error message if value is invalid', () => {
  226. const spy = testUtils.sinon.stub( editor, 'execute' );
  227. // First, let's pass an invalid value and check what happens.
  228. tableCellPropertiesView.borderWidth = 'wrong';
  229. clock.tick( 500 );
  230. expect( tableCellPropertiesView.borderWidthInput.errorText ).to.match( /^The value is invalid/ );
  231. sinon.assert.notCalled( spy );
  232. // And now let's pass a valid value and check if the error text will be gone.
  233. tableCellPropertiesView.borderWidth = '3em';
  234. clock.tick( 500 );
  235. expect( tableCellPropertiesView.backgroundInput.errorText ).to.be.null;
  236. sinon.assert.calledWithExactly( spy, 'tableCellBorderWidth', { value: '3em', batch: 'foo' } );
  237. } );
  238. } );
  239. describe( '#width', () => {
  240. it( 'should affect the editor state', () => {
  241. const spy = testUtils.sinon.stub( editor, 'execute' );
  242. tableCellPropertiesView.width = '12px';
  243. sinon.assert.calledOnce( spy );
  244. sinon.assert.calledWithExactly( spy, 'tableCellWidth', { value: '12px', batch: 'foo' } );
  245. } );
  246. it( 'should display an error message if value is invalid', () => {
  247. const spy = testUtils.sinon.stub( editor, 'execute' );
  248. // First, let's pass an invalid value and check what happens.
  249. tableCellPropertiesView.width = 'wrong';
  250. clock.tick( 500 );
  251. expect( tableCellPropertiesView.widthInput.errorText ).to.match( /^The value is invalid/ );
  252. sinon.assert.notCalled( spy );
  253. // And now let's pass a valid value and check if the error text will be gone.
  254. tableCellPropertiesView.width = '3em';
  255. clock.tick( 500 );
  256. expect( tableCellPropertiesView.backgroundInput.errorText ).to.be.null;
  257. sinon.assert.calledWithExactly( spy, 'tableCellWidth', { value: '3em', batch: 'foo' } );
  258. } );
  259. } );
  260. describe( '#height', () => {
  261. it( 'should affect the editor state', () => {
  262. const spy = testUtils.sinon.stub( editor, 'execute' );
  263. tableCellPropertiesView.height = '12px';
  264. sinon.assert.calledOnce( spy );
  265. sinon.assert.calledWithExactly( spy, 'tableCellHeight', { value: '12px', batch: 'foo' } );
  266. } );
  267. it( 'should display an error message if value is invalid', () => {
  268. const spy = testUtils.sinon.stub( editor, 'execute' );
  269. // First, let's pass an invalid value and check what happens.
  270. tableCellPropertiesView.height = 'wrong';
  271. clock.tick( 500 );
  272. expect( tableCellPropertiesView.heightInput.errorText ).to.match( /^The value is invalid/ );
  273. sinon.assert.notCalled( spy );
  274. // And now let's pass a valid value and check if the error text will be gone.
  275. tableCellPropertiesView.height = '3em';
  276. clock.tick( 500 );
  277. expect( tableCellPropertiesView.backgroundInput.errorText ).to.be.null;
  278. sinon.assert.calledWithExactly( spy, 'tableCellHeight', { value: '3em', batch: 'foo' } );
  279. } );
  280. } );
  281. describe( '#padding', () => {
  282. it( 'should affect the editor state', () => {
  283. const spy = testUtils.sinon.stub( editor, 'execute' );
  284. tableCellPropertiesView.padding = '12px';
  285. sinon.assert.calledOnce( spy );
  286. sinon.assert.calledWithExactly( spy, 'tableCellPadding', { value: '12px', batch: 'foo' } );
  287. } );
  288. it( 'should display an error message if value is invalid', () => {
  289. const spy = testUtils.sinon.stub( editor, 'execute' );
  290. // First, let's pass an invalid value and check what happens.
  291. tableCellPropertiesView.padding = 'wrong';
  292. clock.tick( 500 );
  293. expect( tableCellPropertiesView.paddingInput.errorText ).to.match( /^The value is invalid/ );
  294. sinon.assert.notCalled( spy );
  295. // And now let's pass a valid value and check if the error text will be gone.
  296. tableCellPropertiesView.padding = '3em';
  297. clock.tick( 500 );
  298. expect( tableCellPropertiesView.backgroundInput.errorText ).to.be.null;
  299. sinon.assert.calledWithExactly( spy, 'tableCellPadding', { value: '3em', batch: 'foo' } );
  300. } );
  301. } );
  302. describe( '#backgroundColor', () => {
  303. it( 'should affect the editor state', () => {
  304. const spy = testUtils.sinon.stub( editor, 'execute' );
  305. tableCellPropertiesView.backgroundColor = '#FFAAFF';
  306. sinon.assert.calledOnce( spy );
  307. sinon.assert.calledWithExactly( spy, 'tableCellBackgroundColor', { value: '#FFAAFF', batch: 'foo' } );
  308. } );
  309. it( 'should display an error message if value is invalid', () => {
  310. const spy = testUtils.sinon.stub( editor, 'execute' );
  311. // First, let's pass an invalid value and check what happens.
  312. tableCellPropertiesView.backgroundColor = '42';
  313. clock.tick( 500 );
  314. expect( tableCellPropertiesView.backgroundInput.errorText ).to.match( /^The color is invalid/ );
  315. sinon.assert.notCalled( spy );
  316. // And now let's pass a valid value and check if the error text will be gone.
  317. tableCellPropertiesView.backgroundColor = '#AAA';
  318. clock.tick( 500 );
  319. expect( tableCellPropertiesView.backgroundInput.errorText ).to.be.null;
  320. sinon.assert.calledWithExactly( spy, 'tableCellBackgroundColor', { value: '#AAA', batch: 'foo' } );
  321. } );
  322. } );
  323. describe( '#horizontalAlignment', () => {
  324. it( 'should affect the editor state', () => {
  325. const spy = testUtils.sinon.stub( editor, 'execute' );
  326. tableCellPropertiesView.horizontalAlignment = 'right';
  327. sinon.assert.calledOnce( spy );
  328. sinon.assert.calledWithExactly( spy, 'tableCellHorizontalAlignment', { value: 'right', batch: 'foo' } );
  329. } );
  330. } );
  331. describe( '#verticalAlignment', () => {
  332. it( 'should affect the editor state', () => {
  333. const spy = testUtils.sinon.stub( editor, 'execute' );
  334. tableCellPropertiesView.verticalAlignment = 'right';
  335. sinon.assert.calledOnce( spy );
  336. sinon.assert.calledWithExactly( spy, 'tableCellVerticalAlignment', { value: 'right', batch: 'foo' } );
  337. } );
  338. } );
  339. it( 'should not display an error text if user managed to fix the value before the UI timeout', () => {
  340. // First, let's pass an invalid value.
  341. tableCellPropertiesView.borderColor = '#';
  342. clock.tick( 100 );
  343. // Then the user managed to quickly type the correct value.
  344. tableCellPropertiesView.borderColor = '#aaa';
  345. clock.tick( 400 );
  346. // Because they were quick, they should see no error
  347. expect( tableCellPropertiesView.borderColorInput.errorText ).to.be.null;
  348. } );
  349. it( 'should not affect the editor state if internal property has changed', () => {
  350. const spy = testUtils.sinon.stub( editor, 'execute' );
  351. tableCellPropertiesView.set( 'internalProp', 'foo' );
  352. tableCellPropertiesView.internalProp = 'bar';
  353. sinon.assert.notCalled( spy );
  354. } );
  355. } );
  356. } );
  357. describe( 'Showing the #view', () => {
  358. beforeEach( () => {
  359. editor.model.change( writer => {
  360. writer.setSelection( editor.model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ), 0 );
  361. } );
  362. } );
  363. it( 'should create a new undoable batch for further #view cancel', () => {
  364. tableCellPropertiesButton.fire( 'execute' );
  365. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  366. const firstBatch = tableCellPropertiesUI._undoStepBatch;
  367. expect( firstBatch ).to.be.instanceOf( Batch );
  368. tableCellPropertiesView.fire( 'submit' );
  369. expect( contextualBalloon.visibleView ).to.be.null;
  370. tableCellPropertiesButton.fire( 'execute' );
  371. const secondBatch = tableCellPropertiesUI._undoStepBatch;
  372. expect( secondBatch ).to.be.instanceOf( Batch );
  373. expect( firstBatch ).to.not.equal( secondBatch );
  374. } );
  375. describe( 'initial data', () => {
  376. it( 'should be set from the command values', () => {
  377. editor.commands.get( 'tableCellBorderStyle' ).value = 'a';
  378. editor.commands.get( 'tableCellBorderColor' ).value = 'b';
  379. editor.commands.get( 'tableCellBorderWidth' ).value = 'c';
  380. editor.commands.get( 'tableCellWidth' ).value = 'd';
  381. editor.commands.get( 'tableCellHeight' ).value = 'e';
  382. editor.commands.get( 'tableCellPadding' ).value = 'f';
  383. editor.commands.get( 'tableCellBackgroundColor' ).value = 'g';
  384. editor.commands.get( 'tableCellHorizontalAlignment' ).value = 'h';
  385. editor.commands.get( 'tableCellVerticalAlignment' ).value = 'i';
  386. tableCellPropertiesButton.fire( 'execute' );
  387. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  388. expect( tableCellPropertiesView ).to.include( {
  389. borderStyle: 'a',
  390. borderColor: 'b',
  391. borderWidth: 'c',
  392. width: 'd',
  393. height: 'e',
  394. padding: 'f',
  395. backgroundColor: 'g',
  396. horizontalAlignment: 'h',
  397. verticalAlignment: 'i'
  398. } );
  399. } );
  400. it( 'should use default values when command has no value', () => {
  401. editor.commands.get( 'tableCellBorderStyle' ).value = null;
  402. editor.commands.get( 'tableCellBorderColor' ).value = null;
  403. editor.commands.get( 'tableCellBorderWidth' ).value = null;
  404. editor.commands.get( 'tableCellWidth' ).value = null;
  405. editor.commands.get( 'tableCellHeight' ).value = null;
  406. editor.commands.get( 'tableCellPadding' ).value = null;
  407. editor.commands.get( 'tableCellBackgroundColor' ).value = null;
  408. editor.commands.get( 'tableCellHorizontalAlignment' ).value = null;
  409. editor.commands.get( 'tableCellVerticalAlignment' ).value = null;
  410. tableCellPropertiesButton.fire( 'execute' );
  411. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  412. expect( tableCellPropertiesView ).to.include( {
  413. borderStyle: '',
  414. borderColor: '',
  415. borderWidth: '',
  416. width: '',
  417. height: '',
  418. padding: '',
  419. backgroundColor: '',
  420. horizontalAlignment: '',
  421. verticalAlignment: ''
  422. } );
  423. } );
  424. } );
  425. it( 'should focus the form view', () => {
  426. const spy = testUtils.sinon.spy( tableCellPropertiesView, 'focus' );
  427. tableCellPropertiesButton.fire( 'execute' );
  428. sinon.assert.calledOnce( spy );
  429. } );
  430. } );
  431. describe( 'Hiding the #view', () => {
  432. beforeEach( () => {
  433. editor.model.change( writer => {
  434. writer.setSelection( editor.model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ), 0 );
  435. } );
  436. } );
  437. it( 'should stop listening to EditorUI#update', () => {
  438. const spy = testUtils.sinon.spy( tableCellPropertiesUI, 'stopListening' );
  439. tableCellPropertiesButton.fire( 'execute' );
  440. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  441. tableCellPropertiesView.fire( 'submit' );
  442. expect( contextualBalloon.visibleView ).to.be.null;
  443. sinon.assert.calledOnce( spy );
  444. sinon.assert.calledWithExactly( spy, editor.ui, 'update' );
  445. } );
  446. it( 'should focus the editing view so the focus is not lost', () => {
  447. const spy = testUtils.sinon.spy( editor.editing.view, 'focus' );
  448. tableCellPropertiesButton.fire( 'execute' );
  449. expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
  450. tableCellPropertiesView.fire( 'submit' );
  451. sinon.assert.calledOnce( spy );
  452. } );
  453. } );
  454. } );
  455. } );