dropdownpanelview.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global Event */
  6. import ViewCollection from '../../src/viewcollection';
  7. import DropdownPanelView from '../../src/dropdown/dropdownpanelview';
  8. import View from '../../src/view';
  9. describe( 'DropdownPanelView', () => {
  10. let view, locale;
  11. beforeEach( () => {
  12. locale = { t() {} };
  13. view = new DropdownPanelView( locale );
  14. view.render();
  15. } );
  16. describe( 'constructor()', () => {
  17. it( 'sets view#locale', () => {
  18. expect( view.locale ).to.equal( locale );
  19. } );
  20. it( 'sets view#isVisible false', () => {
  21. expect( view.isVisible ).to.be.false;
  22. } );
  23. it( 'creates view#children collection', () => {
  24. expect( view.children ).to.be.instanceOf( ViewCollection );
  25. } );
  26. it( 'creates element from template', () => {
  27. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  28. expect( view.element.classList.contains( 'ck-reset' ) ).to.be.true;
  29. expect( view.element.classList.contains( 'ck-dropdown__panel' ) ).to.be.true;
  30. } );
  31. describe( 'template bindings', () => {
  32. describe( 'class', () => {
  33. it( 'reacts on view#isVisible', () => {
  34. expect( view.element.classList.contains( 'ck-dropdown__panel-visible' ) ).to.be.false;
  35. view.isVisible = true;
  36. expect( view.element.classList.contains( 'ck-dropdown__panel-visible' ) ).to.be.true;
  37. view.isVisible = false;
  38. expect( view.element.classList.contains( 'ck-dropdown__panel-visible' ) ).to.be.false;
  39. } );
  40. } );
  41. describe( 'listeners', () => {
  42. describe( 'selectstart', () => {
  43. // https://github.com/ckeditor/ckeditor5-ui/issues/228
  44. it( 'gets preventDefault called', () => {
  45. const event = new Event( 'selectstart' );
  46. const spy = sinon.spy( event, 'preventDefault' );
  47. view.element.dispatchEvent( event );
  48. sinon.assert.calledOnce( spy );
  49. } );
  50. } );
  51. } );
  52. } );
  53. } );
  54. describe( 'focus()', () => {
  55. it( 'does nothing for empty panel', () => {
  56. expect( () => view.focus() ).to.not.throw();
  57. } );
  58. it( 'focuses first child view', () => {
  59. const firstChildView = new View();
  60. firstChildView.focus = sinon.spy();
  61. view.children.add( firstChildView );
  62. view.children.add( new View() );
  63. view.focus();
  64. sinon.assert.calledOnce( firstChildView.focus );
  65. } );
  66. } );
  67. describe( 'focusLast()', () => {
  68. it( 'does nothing for empty panel', () => {
  69. expect( () => view.focusLast() ).to.not.throw();
  70. } );
  71. it( 'focuses last child view', () => {
  72. const lastChildView = new View();
  73. lastChildView.focusLast = sinon.spy();
  74. view.children.add( new View() );
  75. view.children.add( lastChildView );
  76. view.focusLast();
  77. sinon.assert.calledOnce( lastChildView.focusLast );
  78. } );
  79. it( 'focuses last child view even if it does not have focusLast() method', () => {
  80. const lastChildView = new View();
  81. lastChildView.focus = sinon.spy();
  82. view.children.add( new View() );
  83. view.children.add( lastChildView );
  84. view.focusLast();
  85. sinon.assert.calledOnce( lastChildView.focus );
  86. } );
  87. } );
  88. } );