tablecellpropertiesview.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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', () => {
  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 change the #horizontalAlignment value', () => {
  398. toolbar.items.last.fire( 'execute' );
  399. expect( view.horizontalAlignment ).to.equal( 'justify' );
  400. expect( toolbar.items.last.isOn ).to.be.true;
  401. toolbar.items.first.fire( 'execute' );
  402. expect( view.horizontalAlignment ).to.equal( '' );
  403. expect( toolbar.items.last.isOn ).to.be.false;
  404. expect( toolbar.items.first.isOn ).to.be.true;
  405. } );
  406. } );
  407. describe( 'vertical text alignment toolbar', () => {
  408. let toolbar;
  409. beforeEach( () => {
  410. toolbar = view.verticalAlignmentToolbar;
  411. } );
  412. it( 'should be defined', () => {
  413. expect( toolbar ).to.be.instanceOf( ToolbarView );
  414. } );
  415. it( 'should have an ARIA label', () => {
  416. expect( toolbar.ariaLabel ).to.equal( 'Vertical text alignment toolbar' );
  417. } );
  418. it( 'should bring alignment buttons', () => {
  419. expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
  420. 'Align cell text to the top',
  421. 'Align cell text to the middle',
  422. 'Align cell text to the bottom'
  423. ] );
  424. expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
  425. false, true, false
  426. ] );
  427. } );
  428. it( 'should change the #verticalAlignment value', () => {
  429. toolbar.items.last.fire( 'execute' );
  430. expect( view.verticalAlignment ).to.equal( 'bottom' );
  431. expect( toolbar.items.last.isOn ).to.be.true;
  432. toolbar.items.first.fire( 'execute' );
  433. expect( view.verticalAlignment ).to.equal( 'top' );
  434. expect( toolbar.items.last.isOn ).to.be.false;
  435. expect( toolbar.items.first.isOn ).to.be.true;
  436. } );
  437. } );
  438. } );
  439. describe( 'action row', () => {
  440. it( 'should be defined', () => {
  441. const row = view.element.childNodes[ 5 ];
  442. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  443. expect( row.classList.contains( 'ck-table-form__action-row' ) ).to.be.true;
  444. expect( row.childNodes[ 0 ] ).to.equal( view.saveButtonView.element );
  445. expect( row.childNodes[ 1 ] ).to.equal( view.cancelButtonView.element );
  446. } );
  447. it( 'should have buttons with right properties', () => {
  448. expect( view.saveButtonView.label ).to.equal( 'Save' );
  449. expect( view.saveButtonView.type ).to.equal( 'submit' );
  450. expect( view.saveButtonView.withText ).to.be.true;
  451. expect( view.saveButtonView.class ).to.equal( 'ck-button-save' );
  452. expect( view.cancelButtonView.label ).to.equal( 'Cancel' );
  453. expect( view.cancelButtonView.withText ).to.be.true;
  454. expect( view.cancelButtonView.class ).to.equal( 'ck-button-cancel' );
  455. } );
  456. it( 'should make the cancel button fire the #cancel event when executed', () => {
  457. const spy = sinon.spy();
  458. view.on( 'cancel', spy );
  459. view.cancelButtonView.fire( 'execute' );
  460. expect( spy.calledOnce ).to.be.true;
  461. } );
  462. it( 'should make sure the #saveButtonView is disabled until text fields are without errors', () => {
  463. view.borderWidthInput.errorText = 'foo';
  464. view.borderColorInput.errorText = 'foo';
  465. view.backgroundInput.errorText = 'foo';
  466. view.paddingInput.errorText = 'foo';
  467. expect( view.saveButtonView.isEnabled ).to.be.false;
  468. view.borderWidthInput.errorText = 'foo';
  469. view.borderColorInput.errorText = 'foo';
  470. view.backgroundInput.errorText = 'foo';
  471. view.paddingInput.errorText = null;
  472. expect( view.saveButtonView.isEnabled ).to.be.false;
  473. view.borderWidthInput.errorText = 'foo';
  474. view.borderColorInput.errorText = 'foo';
  475. view.backgroundInput.errorText = null;
  476. view.paddingInput.errorText = null;
  477. expect( view.saveButtonView.isEnabled ).to.be.false;
  478. view.borderWidthInput.errorText = 'foo';
  479. view.borderColorInput.errorText = null;
  480. view.backgroundInput.errorText = null;
  481. view.paddingInput.errorText = null;
  482. expect( view.saveButtonView.isEnabled ).to.be.false;
  483. view.borderWidthInput.errorText = null;
  484. view.borderColorInput.errorText = null;
  485. view.backgroundInput.errorText = null;
  486. view.paddingInput.errorText = null;
  487. expect( view.saveButtonView.isEnabled ).to.be.true;
  488. } );
  489. } );
  490. } );
  491. it( 'should create #focusTracker instance', () => {
  492. expect( view.focusTracker ).to.be.instanceOf( FocusTracker );
  493. } );
  494. it( 'should create #keystrokes instance', () => {
  495. expect( view.keystrokes ).to.be.instanceOf( KeystrokeHandler );
  496. } );
  497. it( 'should create #_focusCycler instance', () => {
  498. expect( view._focusCycler ).to.be.instanceOf( FocusCycler );
  499. } );
  500. it( 'should create #_focusables view collection', () => {
  501. expect( view._focusables ).to.be.instanceOf( ViewCollection );
  502. } );
  503. } );
  504. describe( 'render()', () => {
  505. it( 'should register child views in #_focusables', () => {
  506. expect( view._focusables.map( f => f ) ).to.have.members( [
  507. view.borderStyleDropdown,
  508. view.borderColorInput,
  509. view.borderWidthInput,
  510. view.backgroundInput,
  511. view.widthInput,
  512. view.heightInput,
  513. view.paddingInput,
  514. view.horizontalAlignmentToolbar,
  515. view.verticalAlignmentToolbar,
  516. view.saveButtonView,
  517. view.cancelButtonView
  518. ] );
  519. } );
  520. it( 'should register child views\' #element in #focusTracker', () => {
  521. const spy = testUtils.sinon.spy( FocusTracker.prototype, 'add' );
  522. const view = new TableCellPropertiesView( { t: val => val }, VIEW_OPTIONS );
  523. view.render();
  524. sinon.assert.calledWith( spy, view.borderStyleDropdown.element );
  525. sinon.assert.calledWith( spy, view.borderColorInput.element );
  526. sinon.assert.calledWith( spy, view.borderWidthInput.element );
  527. sinon.assert.calledWith( spy, view.backgroundInput.element );
  528. sinon.assert.calledWith( spy, view.paddingInput.element );
  529. sinon.assert.calledWith( spy, view.horizontalAlignmentToolbar.element );
  530. sinon.assert.calledWith( spy, view.verticalAlignmentToolbar.element );
  531. sinon.assert.calledWith( spy, view.saveButtonView.element );
  532. sinon.assert.calledWith( spy, view.cancelButtonView.element );
  533. view.destroy();
  534. } );
  535. it( 'starts listening for #keystrokes coming from #element', () => {
  536. const view = new TableCellPropertiesView( { t: val => val }, VIEW_OPTIONS );
  537. const spy = sinon.spy( view.keystrokes, 'listenTo' );
  538. view.render();
  539. sinon.assert.calledOnce( spy );
  540. sinon.assert.calledWithExactly( spy, view.element );
  541. } );
  542. describe( 'activates keyboard navigation for the form', () => {
  543. it( 'so "tab" focuses the next focusable item', () => {
  544. const keyEvtData = {
  545. keyCode: keyCodes.tab,
  546. preventDefault: sinon.spy(),
  547. stopPropagation: sinon.spy()
  548. };
  549. // Mock the border style dropdown button is focused.
  550. view.focusTracker.isFocused = true;
  551. view.focusTracker.focusedElement = view.borderStyleDropdown.element;
  552. const spy = sinon.spy( view.borderColorInput, 'focus' );
  553. view.keystrokes.press( keyEvtData );
  554. sinon.assert.calledOnce( keyEvtData.preventDefault );
  555. sinon.assert.calledOnce( keyEvtData.stopPropagation );
  556. sinon.assert.calledOnce( spy );
  557. } );
  558. it( 'so "shift + tab" focuses the previous focusable item', () => {
  559. const keyEvtData = {
  560. keyCode: keyCodes.tab,
  561. shiftKey: true,
  562. preventDefault: sinon.spy(),
  563. stopPropagation: sinon.spy()
  564. };
  565. // Mock the border style dropdown button is focused.
  566. view.focusTracker.isFocused = true;
  567. view.focusTracker.focusedElement = view.borderStyleDropdown.element;
  568. const spy = sinon.spy( view.cancelButtonView, 'focus' );
  569. view.keystrokes.press( keyEvtData );
  570. sinon.assert.calledOnce( keyEvtData.preventDefault );
  571. sinon.assert.calledOnce( keyEvtData.stopPropagation );
  572. sinon.assert.calledOnce( spy );
  573. } );
  574. } );
  575. } );
  576. describe( 'DOM bindings', () => {
  577. describe( 'submit event', () => {
  578. it( 'should trigger submit event', () => {
  579. const spy = sinon.spy();
  580. view.on( 'submit', spy );
  581. view.element.dispatchEvent( new Event( 'submit' ) );
  582. expect( spy.calledOnce ).to.be.true;
  583. } );
  584. } );
  585. } );
  586. describe( 'focus()', () => {
  587. it( 'focuses the #borderStyleDropdown', () => {
  588. const spy = sinon.spy( view.borderStyleDropdown, 'focus' );
  589. view.focus();
  590. sinon.assert.calledOnce( spy );
  591. } );
  592. } );
  593. } );
  594. } );