rootelement.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Model from '../../src/model/model';
  6. import Element from '../../src/model/element';
  7. import RootElement from '../../src/model/rootelement';
  8. import count from '@ckeditor/ckeditor5-utils/src/count';
  9. describe( 'RootElement', () => {
  10. describe( 'constructor()', () => {
  11. it( 'should create root element without attributes', () => {
  12. const model = new Model();
  13. const doc = model.document;
  14. const root = new RootElement( doc );
  15. expect( root ).to.be.an.instanceof( Element );
  16. expect( root ).to.have.property( 'document' ).that.equals( doc );
  17. expect( count( root.getAttributes() ) ).to.equal( 0 );
  18. expect( root.childCount ).to.equal( 0 );
  19. } );
  20. } );
  21. describe( 'is', () => {
  22. let root;
  23. before( () => {
  24. const model = new Model();
  25. const doc = model.document;
  26. root = new RootElement( doc, '$root' );
  27. } );
  28. it( 'should return true for rootElement, element, element with same name and element name', () => {
  29. expect( root.is( 'element', '$root' ) ).to.be.true;
  30. expect( root.is( 'element' ) ).to.be.true;
  31. expect( root.is( '$root' ) ).to.be.true;
  32. expect( root.is( 'rootElement', '$root' ) ).to.be.true;
  33. expect( root.is( 'rootElement' ) ).to.be.true;
  34. } );
  35. it( 'should return false for other accept values', () => {
  36. expect( root.is( 'element', '$graveyard' ) ).to.be.false;
  37. expect( root.is( 'rootElement', '$graveyard' ) ).to.be.false;
  38. expect( root.is( '$graveyard' ) ).to.be.false;
  39. expect( root.is( 'text' ) ).to.be.false;
  40. expect( root.is( 'textProxy' ) ).to.be.false;
  41. expect( root.is( 'documentFragment' ) ).to.be.false;
  42. } );
  43. } );
  44. } );