rooteditableelement.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import ContainerElement from '../../src/view/containerelement';
  6. import EditableElement from '../../src/view/editableelement';
  7. import RootEditableElement from '../../src/view/rooteditableelement';
  8. import createDocumentMock from '../../tests/view/_utils/createdocumentmock';
  9. describe( 'RootEditableElement', () => {
  10. describe( 'constructor()', () => {
  11. it( 'should create an element with default root name', () => {
  12. const root = new RootEditableElement( 'div' );
  13. root.document = createDocumentMock();
  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' );
  23. root.document = createDocumentMock();
  24. root.rootName = 'header';
  25. expect( root.rootName ).to.equal( 'header' );
  26. expect( root.name ).to.equal( 'h1' );
  27. expect( root.isFocused ).to.be.false;
  28. expect( root.isReadOnly ).to.be.false;
  29. } );
  30. } );
  31. describe( 'is', () => {
  32. let el;
  33. before( () => {
  34. el = new RootEditableElement( 'div' );
  35. } );
  36. it( 'should return true for rootElement/containerElement/element, also with correct name and element name', () => {
  37. expect( el.is( 'rootElement' ) ).to.be.true;
  38. expect( el.is( 'rootElement', 'div' ) ).to.be.true;
  39. expect( el.is( 'containerElement' ) ).to.be.true;
  40. expect( el.is( 'containerElement', 'div' ) ).to.be.true;
  41. expect( el.is( 'element' ) ).to.be.true;
  42. expect( el.is( 'element', 'div' ) ).to.be.true;
  43. expect( el.is( 'div' ) ).to.be.true;
  44. } );
  45. it( 'should return false for other accept values', () => {
  46. expect( el.is( 'rootElement', 'p' ) ).to.be.false;
  47. expect( el.is( 'containerElement', 'p' ) ).to.be.false;
  48. expect( el.is( 'element', 'p' ) ).to.be.false;
  49. expect( el.is( 'p' ) ).to.be.false;
  50. expect( el.is( 'text' ) ).to.be.false;
  51. expect( el.is( 'textProxy' ) ).to.be.false;
  52. expect( el.is( 'attributeElement' ) ).to.be.false;
  53. expect( el.is( 'uiElement' ) ).to.be.false;
  54. expect( el.is( 'emptyElement' ) ).to.be.false;
  55. expect( el.is( 'documentFragment' ) ).to.be.false;
  56. } );
  57. } );
  58. it( 'should be cloned properly', () => {
  59. const root = new RootEditableElement( 'h1' );
  60. root.document = createDocumentMock();
  61. root.rootName = 'header';
  62. const newRoot = root.clone();
  63. expect( newRoot.document ).to.equal( root.document );
  64. expect( newRoot.rootName ).to.equal( root.rootName );
  65. } );
  66. } );