8
0

tablecellpropertiesview.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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 Event */
  6. import TableCellPropertiesView from '../../../src/tablecellproperties/ui/tablecellpropertiesview';
  7. import LabeledView from '@ckeditor/ckeditor5-ui/src/labeledview/labeledview';
  8. import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
  9. import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
  10. import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
  11. import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
  12. import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection';
  13. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  14. import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview';
  15. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  16. import InputTextView from '@ckeditor/ckeditor5-ui/src/inputtext/inputtextview';
  17. describe( 'table cell properties', () => {
  18. describe( 'TableCellPropertiesView', () => {
  19. let view, locale;
  20. testUtils.createSinonSandbox();
  21. beforeEach( () => {
  22. locale = { t: val => val };
  23. view = new TableCellPropertiesView( locale );
  24. view.render();
  25. } );
  26. afterEach( () => {
  27. view.destroy();
  28. } );
  29. describe( 'constructor()', () => {
  30. it( 'should set view#locale', () => {
  31. expect( view.locale ).to.equal( locale );
  32. } );
  33. it( 'should create view#children collection', () => {
  34. expect( view.children ).to.be.instanceOf( ViewCollection );
  35. } );
  36. it( 'should define the public data interface (observable properties)', () => {
  37. expect( view ).to.include( {
  38. borderStyle: '',
  39. borderWidth: '',
  40. borderColor: '',
  41. padding: '',
  42. backgroundColor: '',
  43. horizontalAlignment: '',
  44. verticalAlignment: ''
  45. } );
  46. } );
  47. it( 'should create element from template', () => {
  48. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  49. expect( view.element.classList.contains( 'ck-form' ) ).to.be.true;
  50. expect( view.element.classList.contains( 'ck-table-form' ) ).to.be.true;
  51. expect( view.element.classList.contains( 'ck-table-cell-properties-form' ) ).to.be.true;
  52. expect( view.element.getAttribute( 'tabindex' ) ).to.equal( '-1' );
  53. } );
  54. it( 'should create child views (and references)', () => {
  55. expect( view.borderStyleDropdown ).to.be.instanceOf( LabeledView );
  56. expect( view.borderWidthInput ).to.be.instanceOf( LabeledView );
  57. expect( view.borderColorInput ).to.be.instanceOf( LabeledView );
  58. expect( view.backgroundInput ).to.be.instanceOf( LabeledView );
  59. expect( view.paddingInput ).to.be.instanceOf( LabeledView );
  60. expect( view.horizontalAlignmentToolbar ).to.be.instanceOf( ToolbarView );
  61. expect( view.verticalAlignmentToolbar ).to.be.instanceOf( ToolbarView );
  62. expect( view.saveButtonView ).to.be.instanceOf( ButtonView );
  63. expect( view.cancelButtonView ).to.be.instanceOf( ButtonView );
  64. } );
  65. it( 'should have a header', () => {
  66. const header = view.element.firstChild;
  67. expect( header.classList.contains( 'ck' ) ).to.be.true;
  68. expect( header.classList.contains( 'ck-form__header' ) ).to.be.true;
  69. expect( header.textContent ).to.equal( 'Cell properties' );
  70. } );
  71. describe( 'form rows', () => {
  72. describe( 'border row', () => {
  73. it( 'should be defined', () => {
  74. const row = view.element.childNodes[ 1 ];
  75. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  76. expect( row.classList.contains( 'ck-table-form__border-row' ) ).to.be.true;
  77. expect( row.childNodes[ 0 ].textContent ).to.equal( 'Border' );
  78. expect( row.childNodes[ 1 ] ).to.equal( view.borderStyleDropdown.element );
  79. expect( row.childNodes[ 2 ] ).to.equal( view.borderColorInput.element );
  80. expect( row.childNodes[ 3 ] ).to.equal( view.borderWidthInput.element );
  81. } );
  82. describe( 'border style labeled dropdown', () => {
  83. let labeledDropdown;
  84. beforeEach( () => {
  85. labeledDropdown = view.borderStyleDropdown;
  86. } );
  87. it( 'should have properties set', () => {
  88. expect( labeledDropdown.label ).to.equal( 'Style' );
  89. expect( labeledDropdown.class ).to.equal( 'ck-table-form__border-style' );
  90. } );
  91. it( 'should have a button with properties set', () => {
  92. expect( labeledDropdown.view.buttonView.isOn ).to.be.false;
  93. expect( labeledDropdown.view.buttonView.withText ).to.be.true;
  94. expect( labeledDropdown.view.buttonView.tooltip ).to.equal( 'Style' );
  95. } );
  96. it( 'should bind button\'s label to #borderStyle property', () => {
  97. view.borderStyle = 'dotted';
  98. expect( labeledDropdown.view.buttonView.label ).to.equal( 'Dotted' );
  99. view.borderStyle = 'dashed';
  100. expect( labeledDropdown.view.buttonView.label ).to.equal( 'Dashed' );
  101. } );
  102. it( 'should change #borderStyle when executed', () => {
  103. labeledDropdown.view.listView.items.first.children.first.fire( 'execute' );
  104. expect( view.borderStyle ).to.equal( '' );
  105. labeledDropdown.view.listView.items.last.children.first.fire( 'execute' );
  106. expect( view.borderStyle ).to.equal( 'outset' );
  107. } );
  108. it( 'should come with a set of pre–defined border styles', () => {
  109. expect( labeledDropdown.view.listView.items.map( item => {
  110. return item.children.first.label;
  111. } ) ).to.have.ordered.members( [
  112. 'None', 'Solid', 'Dotted', 'Dashed', 'Double', 'Groove', 'Ridge', 'Inset', 'Outset'
  113. ] );
  114. } );
  115. it( 'should reset border width and color inputs when setting style to none', () => {
  116. view.borderStyle = 'dotted';
  117. view.borderWidth = '1px';
  118. view.borderColor = 'red';
  119. view.borderStyle = '';
  120. expect( view.borderColor ).to.equal( '' );
  121. expect( view.borderWidth ).to.equal( '' );
  122. } );
  123. } );
  124. describe( 'border width input', () => {
  125. let labeledInput;
  126. beforeEach( () => {
  127. labeledInput = view.borderWidthInput;
  128. } );
  129. it( 'should be created', () => {
  130. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  131. expect( labeledInput.label ).to.equal( 'Width' );
  132. expect( labeledInput.class ).to.equal( 'ck-table-form__border-width' );
  133. } );
  134. it( 'should reflect #borderWidth property', () => {
  135. view.borderWidth = 'foo';
  136. expect( labeledInput.view.value ).to.equal( 'foo' );
  137. view.borderWidth = 'bar';
  138. expect( labeledInput.view.value ).to.equal( 'bar' );
  139. } );
  140. it( 'should be enabled only when #borderStyle is different than "none"', () => {
  141. view.borderStyle = '';
  142. expect( labeledInput.isEnabled ).to.be.false;
  143. view.borderStyle = 'dotted';
  144. expect( labeledInput.isEnabled ).to.be.true;
  145. } );
  146. it( 'should update #borderWidth on DOM "input" event', () => {
  147. labeledInput.view.element.value = 'foo';
  148. labeledInput.view.fire( 'input' );
  149. expect( view.borderWidth ).to.equal( 'foo' );
  150. labeledInput.view.element.value = 'bar';
  151. labeledInput.view.fire( 'input' );
  152. expect( view.borderWidth ).to.equal( 'bar' );
  153. } );
  154. } );
  155. describe( 'border color input', () => {
  156. let labeledInput;
  157. beforeEach( () => {
  158. labeledInput = view.borderColorInput;
  159. } );
  160. it( 'should be created', () => {
  161. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  162. expect( labeledInput.label ).to.equal( 'Color' );
  163. } );
  164. it( 'should reflect #borderColor property', () => {
  165. view.borderColor = 'foo';
  166. expect( labeledInput.view.value ).to.equal( 'foo' );
  167. view.borderColor = 'bar';
  168. expect( labeledInput.view.value ).to.equal( 'bar' );
  169. } );
  170. it( 'should be enabled only when #borderStyle is different than "none"', () => {
  171. view.borderStyle = '';
  172. expect( labeledInput.isEnabled ).to.be.false;
  173. view.borderStyle = 'dotted';
  174. expect( labeledInput.isEnabled ).to.be.true;
  175. } );
  176. it( 'should update #borderColor on DOM "input" event', () => {
  177. labeledInput.view.element.value = 'foo';
  178. labeledInput.view.fire( 'input' );
  179. expect( view.borderColor ).to.equal( 'foo' );
  180. labeledInput.view.element.value = 'bar';
  181. labeledInput.view.fire( 'input' );
  182. expect( view.borderColor ).to.equal( 'bar' );
  183. } );
  184. } );
  185. } );
  186. describe( 'background row', () => {
  187. it( 'should be defined', () => {
  188. const row = view.element.childNodes[ 2 ];
  189. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  190. expect( row.childNodes[ 0 ] ).to.equal( view.backgroundInput.element );
  191. } );
  192. describe( 'background color input', () => {
  193. let labeledInput;
  194. beforeEach( () => {
  195. labeledInput = view.backgroundInput;
  196. } );
  197. it( 'should be created', () => {
  198. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  199. expect( labeledInput.label ).to.equal( 'Background' );
  200. expect( labeledInput.class ).to.equal( 'ck-table-cell-properties-form__background' );
  201. } );
  202. it( 'should reflect #backgroundColor property', () => {
  203. view.backgroundColor = 'foo';
  204. expect( labeledInput.view.value ).to.equal( 'foo' );
  205. view.backgroundColor = 'bar';
  206. expect( labeledInput.view.value ).to.equal( 'bar' );
  207. } );
  208. it( 'should update #backgroundColor on DOM "input" event', () => {
  209. labeledInput.view.element.value = 'foo';
  210. labeledInput.view.fire( 'input' );
  211. expect( view.backgroundColor ).to.equal( 'foo' );
  212. labeledInput.view.element.value = 'bar';
  213. labeledInput.view.fire( 'input' );
  214. expect( view.backgroundColor ).to.equal( 'bar' );
  215. } );
  216. } );
  217. } );
  218. describe( 'dimensions row', () => {
  219. it( 'should be defined', () => {
  220. const row = view.element.childNodes[ 3 ].childNodes[ 0 ];
  221. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  222. expect( row.classList.contains( 'ck-table-cell-properties-form__dimensions-row' ) ).to.be.true;
  223. expect( row.childNodes[ 0 ].textContent ).to.equal( 'Dimensions' );
  224. expect( row.childNodes[ 1 ] ).to.equal( view.widthInput.element );
  225. expect( row.childNodes[ 2 ].textContent ).to.equal( '×' );
  226. expect( row.childNodes[ 3 ] ).to.equal( view.heightInput.element );
  227. } );
  228. describe( 'width input', () => {
  229. let labeledInput;
  230. beforeEach( () => {
  231. labeledInput = view.widthInput;
  232. } );
  233. it( 'should be created', () => {
  234. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  235. expect( labeledInput.label ).to.equal( 'Width' );
  236. expect( labeledInput.class ).to.equal( 'ck-table-cell-properties-form__width' );
  237. } );
  238. it( 'should reflect #width property', () => {
  239. view.width = 'foo';
  240. expect( labeledInput.view.value ).to.equal( 'foo' );
  241. view.width = 'bar';
  242. expect( labeledInput.view.value ).to.equal( 'bar' );
  243. } );
  244. it( 'should update #width on DOM "input" event', () => {
  245. labeledInput.view.element.value = 'foo';
  246. labeledInput.view.fire( 'input' );
  247. expect( view.width ).to.equal( 'foo' );
  248. labeledInput.view.element.value = 'bar';
  249. labeledInput.view.fire( 'input' );
  250. expect( view.width ).to.equal( 'bar' );
  251. } );
  252. } );
  253. describe( 'height input', () => {
  254. let labeledInput;
  255. beforeEach( () => {
  256. labeledInput = view.heightInput;
  257. } );
  258. it( 'should be created', () => {
  259. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  260. expect( labeledInput.label ).to.equal( 'Height' );
  261. expect( labeledInput.class ).to.equal( 'ck-table-cell-properties-form__height' );
  262. } );
  263. it( 'should reflect #height property', () => {
  264. view.height = 'foo';
  265. expect( labeledInput.view.value ).to.equal( 'foo' );
  266. view.height = 'bar';
  267. expect( labeledInput.view.value ).to.equal( 'bar' );
  268. } );
  269. it( 'should update #height on DOM "input" event', () => {
  270. labeledInput.view.element.value = 'foo';
  271. labeledInput.view.fire( 'input' );
  272. expect( view.height ).to.equal( 'foo' );
  273. labeledInput.view.element.value = 'bar';
  274. labeledInput.view.fire( 'input' );
  275. expect( view.height ).to.equal( 'bar' );
  276. } );
  277. } );
  278. } );
  279. describe( 'padding row', () => {
  280. it( 'should be defined', () => {
  281. const row = view.element.childNodes[ 3 ].childNodes[ 1 ];
  282. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  283. expect( row.classList.contains( 'ck-table-cell-properties-form__padding-row' ) ).to.be.true;
  284. expect( row.childNodes[ 0 ] ).to.equal( view.paddingInput.element );
  285. } );
  286. describe( 'padding input', () => {
  287. let labeledInput;
  288. beforeEach( () => {
  289. labeledInput = view.paddingInput;
  290. } );
  291. it( 'should be created', () => {
  292. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  293. expect( labeledInput.label ).to.equal( 'Padding' );
  294. expect( labeledInput.class ).to.equal( 'ck-table-cell-properties-form__padding' );
  295. } );
  296. it( 'should reflect #padding property', () => {
  297. view.padding = 'foo';
  298. expect( labeledInput.view.value ).to.equal( 'foo' );
  299. view.padding = 'bar';
  300. expect( labeledInput.view.value ).to.equal( 'bar' );
  301. } );
  302. it( 'should update #padding on DOM "input" event', () => {
  303. labeledInput.view.element.value = 'foo';
  304. labeledInput.view.fire( 'input' );
  305. expect( view.padding ).to.equal( 'foo' );
  306. labeledInput.view.element.value = 'bar';
  307. labeledInput.view.fire( 'input' );
  308. expect( view.padding ).to.equal( 'bar' );
  309. } );
  310. } );
  311. } );
  312. describe( 'text alignment row', () => {
  313. it( 'should be defined', () => {
  314. const row = view.element.childNodes[ 4 ];
  315. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  316. expect( row.classList.contains( 'ck-table-cell-properties-form__alignment-row' ) ).to.be.true;
  317. expect( row.childNodes[ 0 ].textContent ).to.equal( 'Table cell text alignment' );
  318. expect( row.childNodes[ 1 ] ).to.equal( view.horizontalAlignmentToolbar.element );
  319. expect( row.childNodes[ 2 ] ).to.equal( view.verticalAlignmentToolbar.element );
  320. } );
  321. describe( 'horizontal text alignment toolbar', () => {
  322. let toolbar;
  323. beforeEach( () => {
  324. toolbar = view.horizontalAlignmentToolbar;
  325. } );
  326. it( 'should be defined', () => {
  327. expect( toolbar ).to.be.instanceOf( ToolbarView );
  328. } );
  329. it( 'should have an ARIA label', () => {
  330. expect( toolbar.ariaLabel ).to.equal( 'Horizontal text alignment toolbar' );
  331. } );
  332. it( 'should bring alignment buttons', () => {
  333. expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
  334. 'Align cell text to the left',
  335. 'Align cell text to the center',
  336. 'Align cell text to the right',
  337. 'Justify cell text',
  338. ] );
  339. expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
  340. true, false, false, false
  341. ] );
  342. } );
  343. it( 'should change the #horizontalAlignment value', () => {
  344. toolbar.items.last.fire( 'execute' );
  345. expect( view.horizontalAlignment ).to.equal( 'justify' );
  346. expect( toolbar.items.last.isOn ).to.be.true;
  347. toolbar.items.first.fire( 'execute' );
  348. expect( view.horizontalAlignment ).to.equal( '' );
  349. expect( toolbar.items.last.isOn ).to.be.false;
  350. expect( toolbar.items.first.isOn ).to.be.true;
  351. } );
  352. } );
  353. describe( 'vertical text alignment toolbar', () => {
  354. let toolbar;
  355. beforeEach( () => {
  356. toolbar = view.verticalAlignmentToolbar;
  357. } );
  358. it( 'should be defined', () => {
  359. expect( toolbar ).to.be.instanceOf( ToolbarView );
  360. } );
  361. it( 'should have an ARIA label', () => {
  362. expect( toolbar.ariaLabel ).to.equal( 'Vertical text alignment toolbar' );
  363. } );
  364. it( 'should bring alignment buttons', () => {
  365. expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
  366. 'Align cell text to the top',
  367. 'Align cell text to the middle',
  368. 'Align cell text to the bottom',
  369. ] );
  370. expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
  371. false, true, false
  372. ] );
  373. } );
  374. it( 'should change the #verticalAlignment value', () => {
  375. toolbar.items.last.fire( 'execute' );
  376. expect( view.verticalAlignment ).to.equal( 'bottom' );
  377. expect( toolbar.items.last.isOn ).to.be.true;
  378. toolbar.items.first.fire( 'execute' );
  379. expect( view.verticalAlignment ).to.equal( 'top' );
  380. expect( toolbar.items.last.isOn ).to.be.false;
  381. expect( toolbar.items.first.isOn ).to.be.true;
  382. } );
  383. } );
  384. } );
  385. describe( 'action row', () => {
  386. it( 'should be defined', () => {
  387. const row = view.element.childNodes[ 5 ];
  388. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  389. expect( row.classList.contains( 'ck-table-form__action-row' ) ).to.be.true;
  390. expect( row.childNodes[ 0 ] ).to.equal( view.saveButtonView.element );
  391. expect( row.childNodes[ 1 ] ).to.equal( view.cancelButtonView.element );
  392. } );
  393. it( 'should have buttons with right properties', () => {
  394. expect( view.saveButtonView.label ).to.equal( 'Save' );
  395. expect( view.saveButtonView.type ).to.equal( 'submit' );
  396. expect( view.saveButtonView.withText ).to.be.true;
  397. expect( view.saveButtonView.class ).to.equal( 'ck-button-save' );
  398. expect( view.cancelButtonView.label ).to.equal( 'Cancel' );
  399. expect( view.cancelButtonView.withText ).to.be.true;
  400. expect( view.cancelButtonView.class ).to.equal( 'ck-button-cancel' );
  401. } );
  402. it( 'should make the cancel button fire the #cancel event when executed', () => {
  403. const spy = sinon.spy();
  404. view.on( 'cancel', spy );
  405. view.cancelButtonView.fire( 'execute' );
  406. expect( spy.calledOnce ).to.be.true;
  407. } );
  408. it( 'should make sure the #saveButtonView is disabled until text fields are without errors', () => {
  409. view.borderWidthInput.errorText = 'foo';
  410. view.borderColorInput.errorText = 'foo';
  411. view.backgroundInput.errorText = 'foo';
  412. view.paddingInput.errorText = 'foo';
  413. expect( view.saveButtonView.isEnabled ).to.be.false;
  414. view.borderWidthInput.errorText = 'foo';
  415. view.borderColorInput.errorText = 'foo';
  416. view.backgroundInput.errorText = 'foo';
  417. view.paddingInput.errorText = null;
  418. expect( view.saveButtonView.isEnabled ).to.be.false;
  419. view.borderWidthInput.errorText = 'foo';
  420. view.borderColorInput.errorText = 'foo';
  421. view.backgroundInput.errorText = null;
  422. view.paddingInput.errorText = null;
  423. expect( view.saveButtonView.isEnabled ).to.be.false;
  424. view.borderWidthInput.errorText = 'foo';
  425. view.borderColorInput.errorText = null;
  426. view.backgroundInput.errorText = null;
  427. view.paddingInput.errorText = null;
  428. expect( view.saveButtonView.isEnabled ).to.be.false;
  429. view.borderWidthInput.errorText = null;
  430. view.borderColorInput.errorText = null;
  431. view.backgroundInput.errorText = null;
  432. view.paddingInput.errorText = null;
  433. expect( view.saveButtonView.isEnabled ).to.be.true;
  434. } );
  435. } );
  436. } );
  437. it( 'should create #focusTracker instance', () => {
  438. expect( view.focusTracker ).to.be.instanceOf( FocusTracker );
  439. } );
  440. it( 'should create #keystrokes instance', () => {
  441. expect( view.keystrokes ).to.be.instanceOf( KeystrokeHandler );
  442. } );
  443. it( 'should create #_focusCycler instance', () => {
  444. expect( view._focusCycler ).to.be.instanceOf( FocusCycler );
  445. } );
  446. it( 'should create #_focusables view collection', () => {
  447. expect( view._focusables ).to.be.instanceOf( ViewCollection );
  448. } );
  449. } );
  450. describe( 'render()', () => {
  451. it( 'should register child views in #_focusables', () => {
  452. expect( view._focusables.map( f => f ) ).to.have.members( [
  453. view.borderStyleDropdown,
  454. view.borderColorInput,
  455. view.borderWidthInput,
  456. view.backgroundInput,
  457. view.widthInput,
  458. view.heightInput,
  459. view.paddingInput,
  460. view.horizontalAlignmentToolbar,
  461. view.verticalAlignmentToolbar,
  462. view.saveButtonView,
  463. view.cancelButtonView
  464. ] );
  465. } );
  466. it( 'should register child views\' #element in #focusTracker', () => {
  467. const spy = testUtils.sinon.spy( FocusTracker.prototype, 'add' );
  468. const view = new TableCellPropertiesView( { t: val => val } );
  469. view.render();
  470. sinon.assert.calledWith( spy, view.borderStyleDropdown.element );
  471. sinon.assert.calledWith( spy, view.borderColorInput.element );
  472. sinon.assert.calledWith( spy, view.borderWidthInput.element );
  473. sinon.assert.calledWith( spy, view.backgroundInput.element );
  474. sinon.assert.calledWith( spy, view.paddingInput.element );
  475. sinon.assert.calledWith( spy, view.horizontalAlignmentToolbar.element );
  476. sinon.assert.calledWith( spy, view.verticalAlignmentToolbar.element );
  477. sinon.assert.calledWith( spy, view.saveButtonView.element );
  478. sinon.assert.calledWith( spy, view.cancelButtonView.element );
  479. view.destroy();
  480. } );
  481. it( 'starts listening for #keystrokes coming from #element', () => {
  482. const view = new TableCellPropertiesView( { t: val => val } );
  483. const spy = sinon.spy( view.keystrokes, 'listenTo' );
  484. view.render();
  485. sinon.assert.calledOnce( spy );
  486. sinon.assert.calledWithExactly( spy, view.element );
  487. } );
  488. describe( 'activates keyboard navigation for the form', () => {
  489. it( 'so "tab" focuses the next focusable item', () => {
  490. const keyEvtData = {
  491. keyCode: keyCodes.tab,
  492. preventDefault: sinon.spy(),
  493. stopPropagation: sinon.spy()
  494. };
  495. // Mock the border style dropdown button is focused.
  496. view.focusTracker.isFocused = true;
  497. view.focusTracker.focusedElement = view.borderStyleDropdown.element;
  498. const spy = sinon.spy( view.borderColorInput, 'focus' );
  499. view.keystrokes.press( keyEvtData );
  500. sinon.assert.calledOnce( keyEvtData.preventDefault );
  501. sinon.assert.calledOnce( keyEvtData.stopPropagation );
  502. sinon.assert.calledOnce( spy );
  503. } );
  504. it( 'so "shift + tab" focuses the previous focusable item', () => {
  505. const keyEvtData = {
  506. keyCode: keyCodes.tab,
  507. shiftKey: true,
  508. preventDefault: sinon.spy(),
  509. stopPropagation: sinon.spy()
  510. };
  511. // Mock the border style dropdown button is focused.
  512. view.focusTracker.isFocused = true;
  513. view.focusTracker.focusedElement = view.borderStyleDropdown.element;
  514. const spy = sinon.spy( view.cancelButtonView, 'focus' );
  515. view.keystrokes.press( keyEvtData );
  516. sinon.assert.calledOnce( keyEvtData.preventDefault );
  517. sinon.assert.calledOnce( keyEvtData.stopPropagation );
  518. sinon.assert.calledOnce( spy );
  519. } );
  520. } );
  521. } );
  522. describe( 'DOM bindings', () => {
  523. describe( 'submit event', () => {
  524. it( 'should trigger submit event', () => {
  525. const spy = sinon.spy();
  526. view.on( 'submit', spy );
  527. view.element.dispatchEvent( new Event( 'submit' ) );
  528. expect( spy.calledOnce ).to.be.true;
  529. } );
  530. } );
  531. } );
  532. describe( 'focus()', () => {
  533. it( 'focuses the #borderStyleDropdown', () => {
  534. const spy = sinon.spy( view.borderStyleDropdown, 'focus' );
  535. view.focus();
  536. sinon.assert.calledOnce( spy );
  537. } );
  538. } );
  539. } );
  540. } );