tablecellpropertiesview.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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: 'none',
  39. borderWidth: '',
  40. borderColor: '',
  41. padding: '',
  42. backgroundColor: '',
  43. horizontalAlignment: 'left',
  44. verticalAlignment: 'middle'
  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( 'none' );
  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. } );
  116. describe( 'border width input', () => {
  117. let labeledInput;
  118. beforeEach( () => {
  119. labeledInput = view.borderWidthInput;
  120. } );
  121. it( 'should be created', () => {
  122. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  123. expect( labeledInput.label ).to.equal( 'Width' );
  124. expect( labeledInput.class ).to.equal( 'ck-table-form__border-width' );
  125. } );
  126. it( 'should reflect #borderWidth property', () => {
  127. view.borderWidth = 'foo';
  128. expect( labeledInput.view.value ).to.equal( 'foo' );
  129. view.borderWidth = 'bar';
  130. expect( labeledInput.view.value ).to.equal( 'bar' );
  131. } );
  132. it( 'should be enabled only when #borderStyle is different than "none"', () => {
  133. view.borderStyle = 'none';
  134. expect( labeledInput.isEnabled ).to.be.false;
  135. view.borderStyle = 'dotted';
  136. expect( labeledInput.isEnabled ).to.be.true;
  137. } );
  138. it( 'should update #borderWidth on DOM "input" event', () => {
  139. labeledInput.view.element.value = 'foo';
  140. labeledInput.view.fire( 'input' );
  141. expect( view.borderWidth ).to.equal( 'foo' );
  142. labeledInput.view.element.value = 'bar';
  143. labeledInput.view.fire( 'input' );
  144. expect( view.borderWidth ).to.equal( 'bar' );
  145. } );
  146. } );
  147. describe( 'border color input', () => {
  148. let labeledInput;
  149. beforeEach( () => {
  150. labeledInput = view.borderColorInput;
  151. } );
  152. it( 'should be created', () => {
  153. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  154. expect( labeledInput.label ).to.equal( 'Color' );
  155. } );
  156. it( 'should reflect #borderColor property', () => {
  157. view.borderColor = 'foo';
  158. expect( labeledInput.view.value ).to.equal( 'foo' );
  159. view.borderColor = 'bar';
  160. expect( labeledInput.view.value ).to.equal( 'bar' );
  161. } );
  162. it( 'should be enabled only when #borderStyle is different than "none"', () => {
  163. view.borderStyle = 'none';
  164. expect( labeledInput.isEnabled ).to.be.false;
  165. view.borderStyle = 'dotted';
  166. expect( labeledInput.isEnabled ).to.be.true;
  167. } );
  168. it( 'should update #borderColor on DOM "input" event', () => {
  169. labeledInput.view.element.value = 'foo';
  170. labeledInput.view.fire( 'input' );
  171. expect( view.borderColor ).to.equal( 'foo' );
  172. labeledInput.view.element.value = 'bar';
  173. labeledInput.view.fire( 'input' );
  174. expect( view.borderColor ).to.equal( 'bar' );
  175. } );
  176. } );
  177. } );
  178. describe( 'background row', () => {
  179. it( 'should be defined', () => {
  180. const row = view.element.childNodes[ 2 ];
  181. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  182. expect( row.childNodes[ 0 ] ).to.equal( view.backgroundInput.element );
  183. } );
  184. describe( 'background color input', () => {
  185. let labeledInput;
  186. beforeEach( () => {
  187. labeledInput = view.backgroundInput;
  188. } );
  189. it( 'should be created', () => {
  190. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  191. expect( labeledInput.label ).to.equal( 'Background' );
  192. expect( labeledInput.class ).to.equal( 'ck-table-cell-properties-form__background' );
  193. } );
  194. it( 'should reflect #backgroundColor property', () => {
  195. view.backgroundColor = 'foo';
  196. expect( labeledInput.view.value ).to.equal( 'foo' );
  197. view.backgroundColor = 'bar';
  198. expect( labeledInput.view.value ).to.equal( 'bar' );
  199. } );
  200. it( 'should update #backgroundColor on DOM "input" event', () => {
  201. labeledInput.view.element.value = 'foo';
  202. labeledInput.view.fire( 'input' );
  203. expect( view.backgroundColor ).to.equal( 'foo' );
  204. labeledInput.view.element.value = 'bar';
  205. labeledInput.view.fire( 'input' );
  206. expect( view.backgroundColor ).to.equal( 'bar' );
  207. } );
  208. } );
  209. } );
  210. describe( 'dimensions row', () => {
  211. it( 'should be defined', () => {
  212. const row = view.element.childNodes[ 3 ].childNodes[ 0 ];
  213. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  214. expect( row.classList.contains( 'ck-table-cell-properties-form__dimensions-row' ) ).to.be.true;
  215. expect( row.childNodes[ 0 ].textContent ).to.equal( 'Dimensions' );
  216. expect( row.childNodes[ 1 ] ).to.equal( view.widthInput.element );
  217. expect( row.childNodes[ 2 ].textContent ).to.equal( '×' );
  218. expect( row.childNodes[ 3 ] ).to.equal( view.heightInput.element );
  219. } );
  220. describe( 'width input', () => {
  221. let labeledInput;
  222. beforeEach( () => {
  223. labeledInput = view.widthInput;
  224. } );
  225. it( 'should be created', () => {
  226. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  227. expect( labeledInput.label ).to.equal( 'Width' );
  228. expect( labeledInput.class ).to.equal( 'ck-table-cell-properties-form__width' );
  229. } );
  230. it( 'should reflect #width property', () => {
  231. view.width = 'foo';
  232. expect( labeledInput.view.value ).to.equal( 'foo' );
  233. view.width = 'bar';
  234. expect( labeledInput.view.value ).to.equal( 'bar' );
  235. } );
  236. it( 'should update #width on DOM "input" event', () => {
  237. labeledInput.view.element.value = 'foo';
  238. labeledInput.view.fire( 'input' );
  239. expect( view.width ).to.equal( 'foo' );
  240. labeledInput.view.element.value = 'bar';
  241. labeledInput.view.fire( 'input' );
  242. expect( view.width ).to.equal( 'bar' );
  243. } );
  244. } );
  245. describe( 'height input', () => {
  246. let labeledInput;
  247. beforeEach( () => {
  248. labeledInput = view.heightInput;
  249. } );
  250. it( 'should be created', () => {
  251. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  252. expect( labeledInput.label ).to.equal( 'Height' );
  253. expect( labeledInput.class ).to.equal( 'ck-table-cell-properties-form__height' );
  254. } );
  255. it( 'should reflect #height property', () => {
  256. view.height = 'foo';
  257. expect( labeledInput.view.value ).to.equal( 'foo' );
  258. view.height = 'bar';
  259. expect( labeledInput.view.value ).to.equal( 'bar' );
  260. } );
  261. it( 'should update #height on DOM "input" event', () => {
  262. labeledInput.view.element.value = 'foo';
  263. labeledInput.view.fire( 'input' );
  264. expect( view.height ).to.equal( 'foo' );
  265. labeledInput.view.element.value = 'bar';
  266. labeledInput.view.fire( 'input' );
  267. expect( view.height ).to.equal( 'bar' );
  268. } );
  269. } );
  270. } );
  271. describe( 'padding row', () => {
  272. it( 'should be defined', () => {
  273. const row = view.element.childNodes[ 3 ].childNodes[ 1 ];
  274. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  275. expect( row.classList.contains( 'ck-table-cell-properties-form__padding-row' ) ).to.be.true;
  276. expect( row.childNodes[ 0 ] ).to.equal( view.paddingInput.element );
  277. } );
  278. describe( 'padding input', () => {
  279. let labeledInput;
  280. beforeEach( () => {
  281. labeledInput = view.paddingInput;
  282. } );
  283. it( 'should be created', () => {
  284. expect( labeledInput.view ).to.be.instanceOf( InputTextView );
  285. expect( labeledInput.label ).to.equal( 'Padding' );
  286. expect( labeledInput.class ).to.equal( 'ck-table-cell-properties-form__padding' );
  287. } );
  288. it( 'should reflect #padding property', () => {
  289. view.padding = 'foo';
  290. expect( labeledInput.view.value ).to.equal( 'foo' );
  291. view.padding = 'bar';
  292. expect( labeledInput.view.value ).to.equal( 'bar' );
  293. } );
  294. it( 'should update #padding on DOM "input" event', () => {
  295. labeledInput.view.element.value = 'foo';
  296. labeledInput.view.fire( 'input' );
  297. expect( view.padding ).to.equal( 'foo' );
  298. labeledInput.view.element.value = 'bar';
  299. labeledInput.view.fire( 'input' );
  300. expect( view.padding ).to.equal( 'bar' );
  301. } );
  302. } );
  303. } );
  304. describe( 'text alignment row', () => {
  305. it( 'should be defined', () => {
  306. const row = view.element.childNodes[ 4 ];
  307. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  308. expect( row.classList.contains( 'ck-table-cell-properties-form__alignment-row' ) ).to.be.true;
  309. expect( row.childNodes[ 0 ].textContent ).to.equal( 'Text alignment' );
  310. expect( row.childNodes[ 1 ] ).to.equal( view.horizontalAlignmentToolbar.element );
  311. expect( row.childNodes[ 2 ] ).to.equal( view.verticalAlignmentToolbar.element );
  312. } );
  313. describe( 'horizontal text alignment toolbar', () => {
  314. let toolbar;
  315. beforeEach( () => {
  316. toolbar = view.horizontalAlignmentToolbar;
  317. } );
  318. it( 'should be defined', () => {
  319. expect( toolbar ).to.be.instanceOf( ToolbarView );
  320. } );
  321. it( 'should have an ARIA label', () => {
  322. expect( toolbar.ariaLabel ).to.equal( 'Horizontal text alignment toolbar' );
  323. } );
  324. it( 'should bring alignment buttons', () => {
  325. expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
  326. 'Align cell text to the left',
  327. 'Align cell text to the center',
  328. 'Align cell text to the right',
  329. 'Justify cell text',
  330. ] );
  331. expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
  332. true, false, false, false
  333. ] );
  334. } );
  335. it( 'should change the #horizontalAlignment value', () => {
  336. toolbar.items.last.fire( 'execute' );
  337. expect( view.horizontalAlignment ).to.equal( 'justify' );
  338. expect( toolbar.items.last.isOn ).to.be.true;
  339. toolbar.items.first.fire( 'execute' );
  340. expect( view.horizontalAlignment ).to.equal( 'left' );
  341. expect( toolbar.items.last.isOn ).to.be.false;
  342. expect( toolbar.items.first.isOn ).to.be.true;
  343. } );
  344. } );
  345. describe( 'vertical text alignment toolbar', () => {
  346. let toolbar;
  347. beforeEach( () => {
  348. toolbar = view.verticalAlignmentToolbar;
  349. } );
  350. it( 'should be defined', () => {
  351. expect( toolbar ).to.be.instanceOf( ToolbarView );
  352. } );
  353. it( 'should have an ARIA label', () => {
  354. expect( toolbar.ariaLabel ).to.equal( 'Vertical text alignment toolbar' );
  355. } );
  356. it( 'should bring alignment buttons', () => {
  357. expect( toolbar.items.map( ( { label } ) => label ) ).to.have.ordered.members( [
  358. 'Align cell text to the top',
  359. 'Align cell text to the middle',
  360. 'Align cell text to the bottom',
  361. ] );
  362. expect( toolbar.items.map( ( { isOn } ) => isOn ) ).to.have.ordered.members( [
  363. false, true, false
  364. ] );
  365. } );
  366. it( 'should change the #verticalAlignment value', () => {
  367. toolbar.items.last.fire( 'execute' );
  368. expect( view.verticalAlignment ).to.equal( 'bottom' );
  369. expect( toolbar.items.last.isOn ).to.be.true;
  370. toolbar.items.first.fire( 'execute' );
  371. expect( view.verticalAlignment ).to.equal( 'top' );
  372. expect( toolbar.items.last.isOn ).to.be.false;
  373. expect( toolbar.items.first.isOn ).to.be.true;
  374. } );
  375. } );
  376. } );
  377. describe( 'action row', () => {
  378. it( 'should be defined', () => {
  379. const row = view.element.childNodes[ 5 ];
  380. expect( row.classList.contains( 'ck-form__row' ) ).to.be.true;
  381. expect( row.classList.contains( 'ck-table-form__action-row' ) ).to.be.true;
  382. expect( row.childNodes[ 0 ] ).to.equal( view.saveButtonView.element );
  383. expect( row.childNodes[ 1 ] ).to.equal( view.cancelButtonView.element );
  384. } );
  385. it( 'should have buttons with right properties', () => {
  386. expect( view.saveButtonView.label ).to.equal( 'Save' );
  387. expect( view.saveButtonView.type ).to.equal( 'submit' );
  388. expect( view.saveButtonView.withText ).to.be.true;
  389. expect( view.saveButtonView.class ).to.equal( 'ck-button-save' );
  390. expect( view.cancelButtonView.label ).to.equal( 'Cancel' );
  391. expect( view.cancelButtonView.withText ).to.be.true;
  392. expect( view.cancelButtonView.class ).to.equal( 'ck-button-cancel' );
  393. } );
  394. it( 'should make the cancel button fire the #cancel event when executed', () => {
  395. const spy = sinon.spy();
  396. view.on( 'cancel', spy );
  397. view.cancelButtonView.fire( 'execute' );
  398. expect( spy.calledOnce ).to.be.true;
  399. } );
  400. } );
  401. } );
  402. it( 'should create #focusTracker instance', () => {
  403. expect( view.focusTracker ).to.be.instanceOf( FocusTracker );
  404. } );
  405. it( 'should create #keystrokes instance', () => {
  406. expect( view.keystrokes ).to.be.instanceOf( KeystrokeHandler );
  407. } );
  408. it( 'should create #_focusCycler instance', () => {
  409. expect( view._focusCycler ).to.be.instanceOf( FocusCycler );
  410. } );
  411. it( 'should create #_focusables view collection', () => {
  412. expect( view._focusables ).to.be.instanceOf( ViewCollection );
  413. } );
  414. } );
  415. describe( 'render()', () => {
  416. it( 'should register child views in #_focusables', () => {
  417. expect( view._focusables.map( f => f ) ).to.have.members( [
  418. view.borderStyleDropdown,
  419. view.borderColorInput,
  420. view.borderWidthInput,
  421. view.backgroundInput,
  422. view.widthInput,
  423. view.heightInput,
  424. view.paddingInput,
  425. view.horizontalAlignmentToolbar,
  426. view.verticalAlignmentToolbar,
  427. view.saveButtonView,
  428. view.cancelButtonView
  429. ] );
  430. } );
  431. it( 'should register child views\' #element in #focusTracker', () => {
  432. const spy = testUtils.sinon.spy( FocusTracker.prototype, 'add' );
  433. const view = new TableCellPropertiesView( { t: val => val } );
  434. view.render();
  435. sinon.assert.calledWith( spy, view.borderStyleDropdown.element );
  436. sinon.assert.calledWith( spy, view.borderColorInput.element );
  437. sinon.assert.calledWith( spy, view.borderWidthInput.element );
  438. sinon.assert.calledWith( spy, view.backgroundInput.element );
  439. sinon.assert.calledWith( spy, view.paddingInput.element );
  440. sinon.assert.calledWith( spy, view.horizontalAlignmentToolbar.element );
  441. sinon.assert.calledWith( spy, view.verticalAlignmentToolbar.element );
  442. sinon.assert.calledWith( spy, view.saveButtonView.element );
  443. sinon.assert.calledWith( spy, view.cancelButtonView.element );
  444. view.destroy();
  445. } );
  446. it( 'starts listening for #keystrokes coming from #element', () => {
  447. const view = new TableCellPropertiesView( { t: val => val } );
  448. const spy = sinon.spy( view.keystrokes, 'listenTo' );
  449. view.render();
  450. sinon.assert.calledOnce( spy );
  451. sinon.assert.calledWithExactly( spy, view.element );
  452. } );
  453. describe( 'activates keyboard navigation for the form', () => {
  454. it( 'so "tab" focuses the next focusable item', () => {
  455. const keyEvtData = {
  456. keyCode: keyCodes.tab,
  457. preventDefault: sinon.spy(),
  458. stopPropagation: sinon.spy()
  459. };
  460. // Mock the border style dropdown button is focused.
  461. view.focusTracker.isFocused = true;
  462. view.focusTracker.focusedElement = view.borderStyleDropdown.element;
  463. const spy = sinon.spy( view.borderColorInput, 'focus' );
  464. view.keystrokes.press( keyEvtData );
  465. sinon.assert.calledOnce( keyEvtData.preventDefault );
  466. sinon.assert.calledOnce( keyEvtData.stopPropagation );
  467. sinon.assert.calledOnce( spy );
  468. } );
  469. it( 'so "shift + tab" focuses the previous focusable item', () => {
  470. const keyEvtData = {
  471. keyCode: keyCodes.tab,
  472. shiftKey: true,
  473. preventDefault: sinon.spy(),
  474. stopPropagation: sinon.spy()
  475. };
  476. // Mock the border style dropdown button is focused.
  477. view.focusTracker.isFocused = true;
  478. view.focusTracker.focusedElement = view.borderStyleDropdown.element;
  479. const spy = sinon.spy( view.cancelButtonView, 'focus' );
  480. view.keystrokes.press( keyEvtData );
  481. sinon.assert.calledOnce( keyEvtData.preventDefault );
  482. sinon.assert.calledOnce( keyEvtData.stopPropagation );
  483. sinon.assert.calledOnce( spy );
  484. } );
  485. } );
  486. } );
  487. describe( 'DOM bindings', () => {
  488. describe( 'submit event', () => {
  489. it( 'should trigger submit event', () => {
  490. const spy = sinon.spy();
  491. view.on( 'submit', spy );
  492. view.element.dispatchEvent( new Event( 'submit' ) );
  493. expect( spy.calledOnce ).to.be.true;
  494. } );
  495. } );
  496. } );
  497. describe( 'focus()', () => {
  498. it( 'focuses the #borderStyleDropdown', () => {
  499. const spy = sinon.spy( view.borderStyleDropdown, 'focus' );
  500. view.focus();
  501. sinon.assert.calledOnce( spy );
  502. } );
  503. } );
  504. } );
  505. } );