listitemview.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals Event */
  6. import ListItemView from '../../src/list/listitemview';
  7. describe( 'ListItemView', () => {
  8. let view;
  9. beforeEach( () => {
  10. view = new ListItemView();
  11. view.set( {
  12. style: 'foo',
  13. label: 'bar'
  14. } );
  15. return view.init();
  16. } );
  17. describe( 'constructor()', () => {
  18. it( 'creates element from template', () => {
  19. expect( view.element.classList.contains( 'ck-list__item' ) ).to.be.true;
  20. } );
  21. } );
  22. describe( 'DOM bindings', () => {
  23. describe( '"style" attribute', () => {
  24. it( 'reacts on view#style', () => {
  25. expect( view.element.attributes.getNamedItem( 'style' ).value ).to.equal( 'foo' );
  26. view.style = 'color: red';
  27. expect( view.element.attributes.getNamedItem( 'style' ).value ).to.equal( 'color: red' );
  28. } );
  29. } );
  30. describe( 'text content', () => {
  31. it( 'reacts on view#label', () => {
  32. expect( view.element.innerHTML ).to.equal( 'bar' );
  33. view.label = 'baz';
  34. expect( view.element.innerHTML ).to.equal( 'baz' );
  35. } );
  36. } );
  37. describe( 'tabindex', () => {
  38. it( 'is initially set ', () => {
  39. expect( view.element.attributes.tabindex.value ).to.equal( '-1' );
  40. } );
  41. it( 'reacts on view#tabindex', () => {
  42. view.tabindex = 3;
  43. expect( view.element.attributes.tabindex.value ).to.equal( '3' );
  44. } );
  45. } );
  46. describe( 'view#execute event', () => {
  47. it( 'triggers view#execute event when "click" is fired in DOM', () => {
  48. const spy = sinon.spy();
  49. view.on( 'execute', spy );
  50. view.element.dispatchEvent( new Event( 'click' ) );
  51. expect( spy.calledOnce ).to.be.true;
  52. } );
  53. } );
  54. } );
  55. describe( 'focus()', () => {
  56. it( 'focuses the item in DOM', () => {
  57. const spy = sinon.spy( view.element, 'focus' );
  58. view.focus();
  59. sinon.assert.calledOnce( spy );
  60. } );
  61. } );
  62. } );