8
0

tablepropertiesview.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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 TablePropertiesView from '../../../src/tableproperties/ui/tablepropertiesview';
  7. import LabeledFieldView from '@ckeditor/ckeditor5-ui/src/labeledfield/labeledfieldview';
  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 properties', () => {
  40. describe( 'TablePropertiesView', () => {
  41. let view, locale;
  42. testUtils.createSinonSandbox();
  43. beforeEach( () => {
  44. locale = { t: val => val };
  45. view = new TablePropertiesView( 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. backgroundColor: '',
  67. width: '',
  68. height: '',
  69. alignment: ''
  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-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( LabeledFieldView );
  81. expect( view.borderWidthInput ).to.be.instanceOf( LabeledFieldView );
  82. expect( view.borderColorInput ).to.be.instanceOf( LabeledFieldView );
  83. expect( view.backgroundInput ).to.be.instanceOf( LabeledFieldView );
  84. expect( view.widthInput ).to.be.instanceOf( LabeledFieldView );
  85. expect( view.heightInput ).to.be.instanceOf( LabeledFieldView );
  86. expect( view.alignmentToolbar ).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( 'Table 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.fieldView.buttonView.isOn ).to.be.false;
  118. expect( labeledDropdown.fieldView.buttonView.withText ).to.be.true;
  119. expect( labeledDropdown.fieldView.buttonView.tooltip ).to.equal( 'Style' );
  120. } );
  121. it( 'should bind button\'s label to #borderStyle property', () => {
  122. view.borderStyle = 'dotted';
  123. expect( labeledDropdown.fieldView.buttonView.label ).to.equal( 'Dotted' );
  124. view.borderStyle = 'dashed';
  125. expect( labeledDropdown.fieldView.buttonView.label ).to.equal( 'Dashed' );
  126. } );
  127. it( 'should change #borderStyle when executed', () => {
  128. labeledDropdown.fieldView.listView.items.first.children.first.fire( 'execute' );
  129. expect( view.borderStyle ).to.equal( '' );
  130. labeledDropdown.fieldView.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.fieldView.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.fieldView ).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.fieldView.value ).to.equal( 'foo' );
  162. view.borderWidth = 'bar';
  163. expect( labeledInput.fieldView.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.fieldView.element.value = 'foo';
  173. labeledInput.fieldView.fire( 'input' );
  174. expect( view.borderWidth ).to.equal( 'foo' );
  175. labeledInput.fieldView.element.value = 'bar';
  176. labeledInput.fieldView.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.fieldView ).to.be.instanceOf( ColorInputView );
  187. expect( labeledInput.label ).to.equal( 'Color' );
  188. } );
  189. it( 'should get the color configuration', () => {
  190. expect( labeledInput.fieldView.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 obtain the columns configuration', () => {
  208. expect( labeledInput.fieldView.options.columns ).to.equal( 5 );
  209. } );
  210. it( 'should reflect #borderColor property', () => {
  211. view.borderColor = 'foo';
  212. expect( labeledInput.fieldView.value ).to.equal( 'foo' );
  213. view.borderColor = 'bar';
  214. expect( labeledInput.fieldView.value ).to.equal( 'bar' );
  215. } );
  216. it( 'should be enabled only when #borderStyle is different than "none"', () => {
  217. view.borderStyle = '';
  218. expect( labeledInput.isEnabled ).to.be.false;
  219. view.borderStyle = 'dotted';
  220. expect( labeledInput.isEnabled ).to.be.true;
  221. } );
  222. it( 'should update #borderColor on DOM "input" event', () => {
  223. labeledInput.fieldView.value = 'foo';
  224. labeledInput.fieldView.fire( 'input' );
  225. expect( view.borderColor ).to.equal( 'foo' );
  226. labeledInput.fieldView.value = 'bar';
  227. labeledInput.fieldView.fire( 'input' );
  228. expect( view.borderColor ).to.equal( 'bar' );
  229. } );
  230. } );
  231. } );
  232. describe( 'background row', () => {
  233. it( 'should be defined', () => {
  234. const row = view.element.childNodes[ 2 ];
  235. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  236. expect( row.childNodes[ 0 ] ).to.equal( view.backgroundInput.element );
  237. } );
  238. describe( 'background color input', () => {
  239. let labeledInput;
  240. beforeEach( () => {
  241. labeledInput = view.backgroundInput;
  242. } );
  243. it( 'should be created', () => {
  244. expect( labeledInput.fieldView ).to.be.instanceOf( ColorInputView );
  245. expect( labeledInput.label ).to.equal( 'Background' );
  246. expect( labeledInput.class ).to.equal( 'ck-table-properties-form__background' );
  247. } );
  248. it( 'should get the color configuration', () => {
  249. expect( labeledInput.fieldView.options.colorDefinitions ).to.deep.equal( [
  250. {
  251. color: 'rgb(0,255,0)',
  252. label: 'Green',
  253. options: {
  254. hasBorder: false
  255. }
  256. }
  257. ] );
  258. } );
  259. it( 'should obtain the columns configuration', () => {
  260. expect( labeledInput.fieldView.options.columns ).to.equal( 5 );
  261. } );
  262. it( 'should reflect #backgroundColor property', () => {
  263. view.backgroundColor = 'foo';
  264. expect( labeledInput.fieldView.value ).to.equal( 'foo' );
  265. view.backgroundColor = 'bar';
  266. expect( labeledInput.fieldView.value ).to.equal( 'bar' );
  267. } );
  268. it( 'should update #backgroundColor on DOM "input" event', () => {
  269. labeledInput.fieldView.value = 'foo';
  270. labeledInput.fieldView.fire( 'input' );
  271. expect( view.backgroundColor ).to.equal( 'foo' );
  272. labeledInput.fieldView.value = 'bar';
  273. labeledInput.fieldView.fire( 'input' );
  274. expect( view.backgroundColor ).to.equal( 'bar' );
  275. } );
  276. } );
  277. } );
  278. describe( 'dimensions row', () => {
  279. it( 'should be defined', () => {
  280. const row = view.element.childNodes[ 3 ].childNodes[ 0 ];
  281. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  282. expect( row.classList.contains( 'ck-table-form__dimensions-row' ) ).to.be.true;
  283. expect( row.childNodes[ 0 ].textContent ).to.equal( 'Dimensions' );
  284. expect( row.childNodes[ 1 ] ).to.equal( view.widthInput.element );
  285. expect( row.childNodes[ 2 ].textContent ).to.equal( '×' );
  286. expect( row.childNodes[ 3 ] ).to.equal( view.heightInput.element );
  287. } );
  288. describe( 'width input', () => {
  289. let labeledInput;
  290. beforeEach( () => {
  291. labeledInput = view.widthInput;
  292. } );
  293. it( 'should be created', () => {
  294. expect( labeledInput.fieldView ).to.be.instanceOf( InputTextView );
  295. expect( labeledInput.label ).to.equal( 'Width' );
  296. expect( labeledInput.class ).to.equal( 'ck-table-form__dimensions-row__width' );
  297. } );
  298. it( 'should reflect #width property', () => {
  299. view.width = 'foo';
  300. expect( labeledInput.fieldView.value ).to.equal( 'foo' );
  301. view.width = 'bar';
  302. expect( labeledInput.fieldView.value ).to.equal( 'bar' );
  303. } );
  304. it( 'should update #width on DOM "input" event', () => {
  305. labeledInput.fieldView.element.value = 'foo';
  306. labeledInput.fieldView.fire( 'input' );
  307. expect( view.width ).to.equal( 'foo' );
  308. labeledInput.fieldView.element.value = 'bar';
  309. labeledInput.fieldView.fire( 'input' );
  310. expect( view.width ).to.equal( 'bar' );
  311. } );
  312. } );
  313. describe( 'height input', () => {
  314. let labeledInput;
  315. beforeEach( () => {
  316. labeledInput = view.heightInput;
  317. } );
  318. it( 'should be created', () => {
  319. expect( labeledInput.fieldView ).to.be.instanceOf( InputTextView );
  320. expect( labeledInput.label ).to.equal( 'Height' );
  321. expect( labeledInput.class ).to.equal( 'ck-table-form__dimensions-row__height' );
  322. } );
  323. it( 'should reflect #height property', () => {
  324. view.height = 'foo';
  325. expect( labeledInput.fieldView.value ).to.equal( 'foo' );
  326. view.height = 'bar';
  327. expect( labeledInput.fieldView.value ).to.equal( 'bar' );
  328. } );
  329. it( 'should update #height on DOM "input" event', () => {
  330. labeledInput.fieldView.element.value = 'foo';
  331. labeledInput.fieldView.fire( 'input' );
  332. expect( view.height ).to.equal( 'foo' );
  333. labeledInput.fieldView.element.value = 'bar';
  334. labeledInput.fieldView.fire( 'input' );
  335. expect( view.height ).to.equal( 'bar' );
  336. } );
  337. } );
  338. } );
  339. describe( 'dimensions alignment row', () => {
  340. it( 'should be defined', () => {
  341. const row = view.element.childNodes[ 3 ].childNodes[ 1 ];
  342. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  343. expect( row.classList.contains( 'ck-table-properties-form__alignment-row' ) ).to.be.true;
  344. expect( row.childNodes[ 0 ].textContent ).to.equal( 'Alignment' );
  345. expect( row.childNodes[ 1 ] ).to.equal( view.alignmentToolbar.element );
  346. } );
  347. describe( 'alignment toolbar', () => {
  348. let toolbar;
  349. beforeEach( () => {
  350. toolbar = view.alignmentToolbar;
  351. } );
  352. it( 'should be defined', () => {
  353. expect( toolbar ).to.be.instanceOf( ToolbarView );
  354. } );
  355. it( 'should have an ARIA label', () => {
  356. expect( toolbar.ariaLabel ).to.equal( 'Table alignment toolbar' );
  357. } );
  358. it( 'should bring alignment buttons in the right order (left-to-right UI)', () => {
  359. expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
  360. 'Align table to the left',
  361. 'Center table',
  362. 'Align table to the right'
  363. ] );
  364. expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
  365. false, true, false
  366. ] );
  367. } );
  368. it( 'should bring alignment buttons in the right order (right-to-left UI)', () => {
  369. // Creates its own local instances of locale, view and toolbar.
  370. const locale = {
  371. t: val => val,
  372. uiLanguageDirection: 'rtl',
  373. contentLanguageDirection: 'rtl'
  374. };
  375. const view = new TablePropertiesView( locale, VIEW_OPTIONS );
  376. const toolbar = view.alignmentToolbar;
  377. expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
  378. 'Align table to the right',
  379. 'Center table',
  380. 'Align table to the left'
  381. ] );
  382. expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
  383. false, true, false
  384. ] );
  385. view.destroy();
  386. } );
  387. it( 'should change the #horizontalAlignment value', () => {
  388. toolbar.items.last.fire( 'execute' );
  389. expect( view.alignment ).to.equal( 'right' );
  390. expect( toolbar.items.last.isOn ).to.be.true;
  391. toolbar.items.first.fire( 'execute' );
  392. expect( view.alignment ).to.equal( 'left' );
  393. expect( toolbar.items.last.isOn ).to.be.false;
  394. expect( toolbar.items.first.isOn ).to.be.true;
  395. } );
  396. } );
  397. } );
  398. describe( 'action row', () => {
  399. it( 'should be defined', () => {
  400. const row = view.element.childNodes[ 4 ];
  401. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  402. expect( row.classList.contains( 'ck-table-form__action-row' ) ).to.be.true;
  403. expect( row.childNodes[ 0 ] ).to.equal( view.saveButtonView.element );
  404. expect( row.childNodes[ 1 ] ).to.equal( view.cancelButtonView.element );
  405. } );
  406. it( 'should have buttons with right properties', () => {
  407. expect( view.saveButtonView.label ).to.equal( 'Save' );
  408. expect( view.saveButtonView.type ).to.equal( 'submit' );
  409. expect( view.saveButtonView.withText ).to.be.true;
  410. expect( view.saveButtonView.class ).to.equal( 'ck-button-save' );
  411. expect( view.cancelButtonView.label ).to.equal( 'Cancel' );
  412. expect( view.cancelButtonView.withText ).to.be.true;
  413. expect( view.cancelButtonView.class ).to.equal( 'ck-button-cancel' );
  414. } );
  415. it( 'should make the cancel button fire the #cancel event when executed', () => {
  416. const spy = sinon.spy();
  417. view.on( 'cancel', spy );
  418. view.cancelButtonView.fire( 'execute' );
  419. expect( spy.calledOnce ).to.be.true;
  420. } );
  421. it( 'should make sure the #saveButtonView is disabled until text fields are without errors', () => {
  422. view.borderWidthInput.errorText = 'foo';
  423. view.borderColorInput.errorText = 'foo';
  424. view.backgroundInput.errorText = 'foo';
  425. view.widthInput.errorText = 'foo';
  426. view.heightInput.errorText = 'foo';
  427. expect( view.saveButtonView.isEnabled ).to.be.false;
  428. view.borderWidthInput.errorText = 'foo';
  429. view.borderColorInput.errorText = 'foo';
  430. view.backgroundInput.errorText = 'foo';
  431. view.widthInput.errorText = 'foo';
  432. view.heightInput.errorText = null;
  433. expect( view.saveButtonView.isEnabled ).to.be.false;
  434. view.borderWidthInput.errorText = 'foo';
  435. view.borderColorInput.errorText = 'foo';
  436. view.backgroundInput.errorText = 'foo';
  437. view.widthInput.errorText = null;
  438. view.heightInput.errorText = null;
  439. expect( view.saveButtonView.isEnabled ).to.be.false;
  440. view.borderWidthInput.errorText = 'foo';
  441. view.borderColorInput.errorText = 'foo';
  442. view.backgroundInput.errorText = null;
  443. view.widthInput.errorText = null;
  444. view.heightInput.errorText = null;
  445. expect( view.saveButtonView.isEnabled ).to.be.false;
  446. view.borderWidthInput.errorText = 'foo';
  447. view.borderColorInput.errorText = null;
  448. view.backgroundInput.errorText = null;
  449. view.widthInput.errorText = null;
  450. view.heightInput.errorText = null;
  451. expect( view.saveButtonView.isEnabled ).to.be.false;
  452. view.borderWidthInput.errorText = null;
  453. view.borderColorInput.errorText = null;
  454. view.backgroundInput.errorText = null;
  455. view.widthInput.errorText = null;
  456. view.heightInput.errorText = null;
  457. expect( view.saveButtonView.isEnabled ).to.be.true;
  458. } );
  459. } );
  460. } );
  461. it( 'should create #focusTracker instance', () => {
  462. expect( view.focusTracker ).to.be.instanceOf( FocusTracker );
  463. } );
  464. it( 'should create #keystrokes instance', () => {
  465. expect( view.keystrokes ).to.be.instanceOf( KeystrokeHandler );
  466. } );
  467. it( 'should create #_focusCycler instance', () => {
  468. expect( view._focusCycler ).to.be.instanceOf( FocusCycler );
  469. } );
  470. it( 'should create #_focusables view collection', () => {
  471. expect( view._focusables ).to.be.instanceOf( ViewCollection );
  472. } );
  473. } );
  474. describe( 'render()', () => {
  475. it( 'should register child views in #_focusables', () => {
  476. expect( view._focusables.map( f => f ) ).to.have.members( [
  477. view.borderStyleDropdown,
  478. view.borderColorInput,
  479. view.borderWidthInput,
  480. view.backgroundInput,
  481. view.widthInput,
  482. view.heightInput,
  483. view.alignmentToolbar,
  484. view.saveButtonView,
  485. view.cancelButtonView
  486. ] );
  487. } );
  488. it( 'should register child views\' #element in #focusTracker', () => {
  489. const spy = testUtils.sinon.spy( FocusTracker.prototype, 'add' );
  490. const view = new TablePropertiesView( { t: val => val }, VIEW_OPTIONS );
  491. view.render();
  492. sinon.assert.calledWith( spy, view.borderStyleDropdown.element );
  493. sinon.assert.calledWith( spy, view.borderColorInput.element );
  494. sinon.assert.calledWith( spy, view.borderWidthInput.element );
  495. sinon.assert.calledWith( spy, view.backgroundInput.element );
  496. sinon.assert.calledWith( spy, view.widthInput.element );
  497. sinon.assert.calledWith( spy, view.heightInput.element );
  498. sinon.assert.calledWith( spy, view.alignmentToolbar.element );
  499. sinon.assert.calledWith( spy, view.saveButtonView.element );
  500. sinon.assert.calledWith( spy, view.cancelButtonView.element );
  501. view.destroy();
  502. } );
  503. it( 'starts listening for #keystrokes coming from #element', () => {
  504. const view = new TablePropertiesView( { t: val => val }, VIEW_OPTIONS );
  505. const spy = sinon.spy( view.keystrokes, 'listenTo' );
  506. view.render();
  507. sinon.assert.calledOnce( spy );
  508. sinon.assert.calledWithExactly( spy, view.element );
  509. } );
  510. describe( 'activates keyboard navigation for the form', () => {
  511. it( 'so "tab" focuses the next focusable item', () => {
  512. const keyEvtData = {
  513. keyCode: keyCodes.tab,
  514. preventDefault: sinon.spy(),
  515. stopPropagation: sinon.spy()
  516. };
  517. // Mock the border style dropdown button is focused.
  518. view.focusTracker.isFocused = true;
  519. view.focusTracker.focusedElement = view.borderStyleDropdown.element;
  520. const spy = sinon.spy( view.borderColorInput, 'focus' );
  521. view.keystrokes.press( keyEvtData );
  522. sinon.assert.calledOnce( keyEvtData.preventDefault );
  523. sinon.assert.calledOnce( keyEvtData.stopPropagation );
  524. sinon.assert.calledOnce( spy );
  525. } );
  526. it( 'so "shift + tab" focuses the previous focusable item', () => {
  527. const keyEvtData = {
  528. keyCode: keyCodes.tab,
  529. shiftKey: true,
  530. preventDefault: sinon.spy(),
  531. stopPropagation: sinon.spy()
  532. };
  533. // Mock the border style dropdown button is focused.
  534. view.focusTracker.isFocused = true;
  535. view.focusTracker.focusedElement = view.borderStyleDropdown.element;
  536. const spy = sinon.spy( view.cancelButtonView, 'focus' );
  537. view.keystrokes.press( keyEvtData );
  538. sinon.assert.calledOnce( keyEvtData.preventDefault );
  539. sinon.assert.calledOnce( keyEvtData.stopPropagation );
  540. sinon.assert.calledOnce( spy );
  541. } );
  542. } );
  543. } );
  544. describe( 'DOM bindings', () => {
  545. describe( 'submit event', () => {
  546. it( 'should trigger submit event', () => {
  547. const spy = sinon.spy();
  548. view.on( 'submit', spy );
  549. view.element.dispatchEvent( new Event( 'submit' ) );
  550. expect( spy.calledOnce ).to.be.true;
  551. } );
  552. } );
  553. } );
  554. describe( 'focus()', () => {
  555. it( 'focuses the #borderStyleDropdown', () => {
  556. const spy = sinon.spy( view.borderStyleDropdown, 'focus' );
  557. view.focus();
  558. sinon.assert.calledOnce( spy );
  559. } );
  560. } );
  561. } );
  562. } );