region.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. /* bender-tags: core, ui */
  7. 'use strict';
  8. var modules = bender.amd.require( 'ckeditor', 'ui/region', 'ui/view', 'collection' );
  9. describe( 'Region', function() {
  10. var region;
  11. var el;
  12. beforeEach( 'Create a test region instance', function() {
  13. var Region = modules[ 'ui/region' ];
  14. el = document.createElement( 'div' );
  15. region = new Region( 'foo', el );
  16. } );
  17. it( 'accepts constructor paramaters', function() {
  18. expect( region ).to.have.property( 'name', 'foo' );
  19. expect( region ).to.have.property( 'el', el );
  20. } );
  21. it( 'has views collection', function() {
  22. var Collection = modules.collection;
  23. expect( region.views ).to.be.an.instanceof( Collection );
  24. } );
  25. it( 'adds views to collection', function() {
  26. var View = modules[ 'ui/view' ];
  27. class TestView extends View {
  28. constructor() {
  29. super();
  30. this.template = { tag: 'b' };
  31. }
  32. }
  33. expect( region.el.childNodes.length ).to.be.equal( 0 );
  34. region.views.add( new TestView() );
  35. expect( region.el.childNodes.length ).to.be.equal( 1 );
  36. region.views.add( new TestView() );
  37. expect( region.el.childNodes.length ).to.be.equal( 2 );
  38. } );
  39. it( 'removes views from collection', function() {
  40. var View = modules[ 'ui/view' ];
  41. class TestViewA extends View {
  42. constructor() {
  43. super();
  44. this.template = { tag: 'a' };
  45. }
  46. }
  47. class TestViewB extends View {
  48. constructor() {
  49. super();
  50. this.template = { tag: 'b' };
  51. }
  52. }
  53. var tva = new TestViewA();
  54. var tvb = new TestViewB();
  55. region.views.add( tva );
  56. region.views.add( tvb );
  57. var childNodes = region.el.childNodes;
  58. expect( [].map.call( childNodes, n => n.nodeName ).join( ',' ) ).to.be.equal( 'A,B' );
  59. region.views.remove( tva );
  60. expect( [].map.call( childNodes, n => n.nodeName ).join( ',' ) ).to.be.equal( 'B' );
  61. region.views.remove( tvb );
  62. expect( childNodes.length ).to.be.equal( 0 );
  63. } );
  64. } );