tablecellpropertiesui.js 22 KB

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