tablecellpropertiesview.js 25 KB

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