formheaderview.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. import View from '../../src/view';
  6. import ViewCollection from '../../src/viewcollection';
  7. import FormHeaderView from '../../src/formheader/formheaderview';
  8. describe( 'FormHeaderView', () => {
  9. let view, locale;
  10. beforeEach( () => {
  11. locale = { t: val => val };
  12. view = new FormHeaderView( locale );
  13. view.render();
  14. } );
  15. afterEach( () => {
  16. view.element.remove();
  17. } );
  18. describe( 'constructor()', () => {
  19. it( 'should set view#locale', () => {
  20. expect( view.locale ).to.equal( locale );
  21. } );
  22. it( 'should create view#children collection', () => {
  23. expect( view.children ).to.be.instanceOf( ViewCollection );
  24. expect( view.children ).to.have.length( 1 );
  25. } );
  26. it( 'should set view#label', () => {
  27. expect( view.label ).to.equal( '' );
  28. } );
  29. it( 'should set view#class', () => {
  30. expect( view.class ).to.be.null;
  31. } );
  32. it( 'should set the template', () => {
  33. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  34. expect( view.element.classList.contains( 'ck-form__header' ) ).to.be.true;
  35. } );
  36. describe( 'options', () => {
  37. it( 'should set view#class when class was passed', () => {
  38. const view = new FormHeaderView( locale, {
  39. class: 'foo'
  40. } );
  41. expect( view.class ).to.equal( 'foo' );
  42. view.destroy();
  43. } );
  44. it( 'should use a label text when passed', () => {
  45. const view = new FormHeaderView( locale, {
  46. label: 'foo'
  47. } );
  48. view.render();
  49. expect( view.element.firstChild.classList.contains( 'ck' ) ).to.be.true;
  50. expect( view.element.firstChild.classList.contains( 'ck-form__header__label' ) ).to.be.true;
  51. expect( view.element.firstChild.textContent ).to.equal( 'foo' );
  52. view.destroy();
  53. } );
  54. } );
  55. describe( 'template bindings', () => {
  56. it( 'should bind #class to the template', () => {
  57. view.class = 'foo';
  58. expect( view.element.classList.contains( 'foo' ) ).to.be.true;
  59. } );
  60. it( 'should bind #label to the template', () => {
  61. view.label = 'bar';
  62. expect( view.element.firstChild.textContent ).to.equal( 'bar' );
  63. view.label = 'baz';
  64. expect( view.element.firstChild.textContent ).to.equal( 'baz' );
  65. } );
  66. it( 'should bind #children to the template', () => {
  67. const child = new View();
  68. child.setTemplate( { tag: 'div' } );
  69. view.children.add( child );
  70. expect( view.element.childNodes[ 1 ] ).to.equal( child.element );
  71. view.destroy();
  72. } );
  73. } );
  74. } );
  75. } );