rootelement.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 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( 'model:element', '$root' ) ).to.be.true;
  31. expect( root.is( 'element' ) ).to.be.true;
  32. expect( root.is( 'model:element' ) ).to.be.true;
  33. expect( root.is( 'rootElement', '$root' ) ).to.be.true;
  34. expect( root.is( 'model:rootElement', '$root' ) ).to.be.true;
  35. expect( root.is( 'rootElement' ) ).to.be.true;
  36. expect( root.is( 'model:rootElement' ) ).to.be.true;
  37. expect( root.is( 'node' ) ).to.be.true;
  38. expect( root.is( 'model:node' ) ).to.be.true;
  39. } );
  40. it( 'should return false for other accept values', () => {
  41. expect( root.is( 'element', '$graveyard' ) ).to.be.false;
  42. expect( root.is( 'model:element', '$graveyard' ) ).to.be.false;
  43. expect( root.is( 'rootElement', '$graveyard' ) ).to.be.false;
  44. expect( root.is( 'model:rootElement', '$graveyard' ) ).to.be.false;
  45. expect( root.is( '$graveyard' ) ).to.be.false;
  46. expect( root.is( '$text' ) ).to.be.false;
  47. expect( root.is( '$textProxy' ) ).to.be.false;
  48. expect( root.is( 'documentFragment' ) ).to.be.false;
  49. expect( root.is( 'view:element' ) ).to.be.false;
  50. expect( root.is( '$root' ) ).to.be.false;
  51. expect( root.is( 'model:$root' ) ).to.be.false;
  52. expect( root.is( 'node', '$root' ) ).to.be.false;
  53. expect( root.is( 'model:node', '$root' ) ).to.be.false;
  54. } );
  55. } );
  56. } );