rooteditableelement.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: view */
  6. 'use strict';
  7. import ContainerElement from '/ckeditor5/engine/view/containerelement.js';
  8. import EditableElement from '/ckeditor5/engine/view/editableelement.js';
  9. import RootEditableElement from '/ckeditor5/engine/view/rooteditableelement.js';
  10. describe( 'RootEditableElement', () => {
  11. describe( 'constructor', () => {
  12. it( 'should create an element with default root name', () => {
  13. const root = new RootEditableElement( {}, 'div' );
  14. expect( root ).to.be.instanceof( EditableElement );
  15. expect( root ).to.be.instanceof( ContainerElement );
  16. expect( root.rootName ).to.equal( 'main' );
  17. expect( root.name ).to.equal( 'div' );
  18. expect( root.isFocused ).to.be.false;
  19. expect( root.isReadOnly ).to.be.false;
  20. } );
  21. it( 'should create an element with custom root name', () => {
  22. const root = new RootEditableElement( {}, 'h1', 'header' );
  23. expect( root.rootName ).to.equal( 'header' );
  24. expect( root.name ).to.equal( 'h1' );
  25. expect( root.isFocused ).to.be.false;
  26. expect( root.isReadOnly ).to.be.false;
  27. } );
  28. } );
  29. describe( 'isFocused', () => {
  30. it( 'should be observable', () => {
  31. const root = new RootEditableElement( {}, 'div' );
  32. expect( root.isFocused ).to.be.false;
  33. const isFocusedSpy = sinon.spy();
  34. root.on( 'change:isFocused', isFocusedSpy );
  35. root.isFocused = true;
  36. expect( root.isFocused ).to.be.true;
  37. expect( isFocusedSpy.calledOnce ).to.be.true;
  38. } );
  39. } );
  40. describe( 'isReadOnly', () => {
  41. it( 'should be observable', () => {
  42. const root = new RootEditableElement( {}, 'div' );
  43. expect( root.isReadOnly ).to.be.false;
  44. const isReadOnlySpy = sinon.spy();
  45. root.on( 'change:isReadOnly', isReadOnlySpy );
  46. root.isReadOnly = true;
  47. expect( root.isReadOnly ).to.be.true;
  48. expect( isReadOnlySpy.calledOnce ).to.be.true;
  49. } );
  50. } );
  51. describe( 'getDocument', ()=> {
  52. it( 'should return document', () => {
  53. const docMock = {};
  54. const root = new RootEditableElement( docMock, 'div' );
  55. expect( root.getDocument() ).to.equal( docMock );
  56. } );
  57. } );
  58. } );