rooteditableelement.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  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/editable/element, also with correct name and element name', () => {
  37. expect( el.is( 'rootElement' ) ).to.be.true;
  38. expect( el.is( 'view:rootElement' ) ).to.be.true;
  39. expect( el.is( 'rootElement', 'div' ) ).to.be.true;
  40. expect( el.is( 'view:rootElement', 'div' ) ).to.be.true;
  41. expect( el.is( 'containerElement' ) ).to.be.true;
  42. expect( el.is( 'view:containerElement' ) ).to.be.true;
  43. expect( el.is( 'containerElement', 'div' ) ).to.be.true;
  44. expect( el.is( 'view:containerElement', 'div' ) ).to.be.true;
  45. expect( el.is( 'editableElement' ) ).to.be.true;
  46. expect( el.is( 'view:editableElement' ) ).to.be.true;
  47. expect( el.is( 'editableElement', 'div' ) ).to.be.true;
  48. expect( el.is( 'view:editableElement', 'div' ) ).to.be.true;
  49. expect( el.is( 'element' ) ).to.be.true;
  50. expect( el.is( 'view:element' ) ).to.be.true;
  51. expect( el.is( 'element', 'div' ) ).to.be.true;
  52. expect( el.is( 'view:element', 'div' ) ).to.be.true;
  53. expect( el.is( 'div' ) ).to.be.true;
  54. expect( el.is( 'view:div' ) ).to.be.true;
  55. } );
  56. it( 'should return false for other accept values', () => {
  57. expect( el.is( 'rootElement', 'p' ) ).to.be.false;
  58. expect( el.is( 'view:rootElement', 'p' ) ).to.be.false;
  59. expect( el.is( 'containerElement', 'p' ) ).to.be.false;
  60. expect( el.is( 'view:containerElement', 'p' ) ).to.be.false;
  61. expect( el.is( 'element', 'p' ) ).to.be.false;
  62. expect( el.is( 'view:element', 'p' ) ).to.be.false;
  63. expect( el.is( 'p' ) ).to.be.false;
  64. expect( el.is( 'view:p' ) ).to.be.false;
  65. expect( el.is( 'text' ) ).to.be.false;
  66. expect( el.is( 'view:text' ) ).to.be.false;
  67. expect( el.is( 'textProxy' ) ).to.be.false;
  68. expect( el.is( 'attributeElement' ) ).to.be.false;
  69. expect( el.is( 'uiElement' ) ).to.be.false;
  70. expect( el.is( 'emptyElement' ) ).to.be.false;
  71. expect( el.is( 'documentFragment' ) ).to.be.false;
  72. expect( el.is( 'model:rootElement' ) ).to.be.false;
  73. } );
  74. } );
  75. describe( '_name', () => {
  76. it( 'should set new name to element', () => {
  77. const el = new RootEditableElement( '$root' );
  78. expect( el.name ).to.equal( '$root' );
  79. el._name = 'div';
  80. expect( el.name ).to.equal( 'div' );
  81. } );
  82. } );
  83. it( 'should be cloned properly', () => {
  84. const root = new RootEditableElement( 'h1' );
  85. root._document = createDocumentMock();
  86. root.rootName = 'header';
  87. const newRoot = root._clone();
  88. expect( newRoot._document ).to.equal( root._document );
  89. expect( newRoot.rootName ).to.equal( root.rootName );
  90. } );
  91. } );