formrowview.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 '@ckeditor/ckeditor5-ui/src/view';
  6. import FormRowView from '../../src/ui/formrowview';
  7. import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection';
  8. describe( 'FormRowView', () => {
  9. let view, locale;
  10. beforeEach( () => {
  11. locale = { t: val => val };
  12. view = new FormRowView( 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( 0 );
  25. } );
  26. it( 'should set view#class', () => {
  27. expect( view.class ).to.be.null;
  28. } );
  29. it( 'should set the template', () => {
  30. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  31. expect( view.element.classList.contains( 'ck-form__row' ) ).to.be.true;
  32. } );
  33. describe( 'options', () => {
  34. it( 'should set view#class when class was passed', () => {
  35. const view = new FormRowView( locale, {
  36. class: 'foo'
  37. } );
  38. expect( view.class ).to.equal( 'foo' );
  39. view.destroy();
  40. } );
  41. it( 'should fill view#children when children were passed', () => {
  42. const view = new FormRowView( locale, {
  43. children: [
  44. new View()
  45. ]
  46. } );
  47. expect( view.children ).to.have.length( 1 );
  48. view.destroy();
  49. } );
  50. it( 'should use a label view when passed', () => {
  51. const labelView = new View();
  52. labelView.id = '123';
  53. const view = new FormRowView( locale, {
  54. labelView
  55. } );
  56. view.render();
  57. expect( view.element.getAttribute( 'role' ) ).to.equal( 'group' );
  58. expect( view.element.getAttribute( 'aria-labelledby' ) ).to.equal( '123' );
  59. view.destroy();
  60. } );
  61. } );
  62. describe( 'template bindings', () => {
  63. it( 'should bind #class to the template', () => {
  64. view.class = 'foo';
  65. expect( view.element.classList.contains( 'foo' ) ).to.be.true;
  66. } );
  67. it( 'should bind #children to the template', () => {
  68. const child = new View();
  69. child.setTemplate( { tag: 'div' } );
  70. view.children.add( child );
  71. expect( view.element.firstChild ).to.equal( child.element );
  72. view.destroy();
  73. } );
  74. } );
  75. } );
  76. } );