listitemview.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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( '"class" attribute', () => {
  24. it( 'reacts on view#class', () => {
  25. expect( view.element.classList ).to.have.length( 1 );
  26. view.set( 'class', 'foo' );
  27. expect( view.element.classList.contains( 'foo' ) ).to.be.true;
  28. } );
  29. } );
  30. describe( '"style" attribute', () => {
  31. it( 'reacts on view#style', () => {
  32. expect( view.element.attributes.getNamedItem( 'style' ).value ).to.equal( 'foo' );
  33. view.style = 'color: red';
  34. expect( view.element.attributes.getNamedItem( 'style' ).value ).to.equal( 'color: red' );
  35. } );
  36. } );
  37. describe( 'text content', () => {
  38. it( 'reacts on view#label', () => {
  39. expect( view.element.innerHTML ).to.equal( 'bar' );
  40. view.label = 'baz';
  41. expect( view.element.innerHTML ).to.equal( 'baz' );
  42. } );
  43. } );
  44. describe( 'tabindex', () => {
  45. it( 'is initially set ', () => {
  46. expect( view.element.attributes.tabindex.value ).to.equal( '-1' );
  47. } );
  48. it( 'reacts on view#tabindex', () => {
  49. view.tabindex = 3;
  50. expect( view.element.attributes.tabindex.value ).to.equal( '3' );
  51. } );
  52. } );
  53. describe( 'view#execute event', () => {
  54. it( 'triggers view#execute event when "click" is fired in DOM', () => {
  55. const spy = sinon.spy();
  56. view.on( 'execute', spy );
  57. view.element.dispatchEvent( new Event( 'click' ) );
  58. expect( spy.calledOnce ).to.be.true;
  59. } );
  60. } );
  61. } );
  62. describe( 'focus()', () => {
  63. it( 'focuses the item in DOM', () => {
  64. const spy = sinon.spy( view.element, 'focus' );
  65. view.focus();
  66. sinon.assert.calledOnce( spy );
  67. } );
  68. } );
  69. } );