tablecellpropertiesui.js 22 KB

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