tablecellpropertiesui.js 23 KB

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