tablecellpropertiesui.js 22 KB

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