8
0

rooteditableelement.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 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. let document;
  11. beforeEach( () => {
  12. document = createDocumentMock();
  13. } );
  14. describe( 'constructor()', () => {
  15. it( 'should create an element with default root name', () => {
  16. const root = new RootEditableElement( document, 'div' );
  17. expect( root ).to.be.instanceof( EditableElement );
  18. expect( root ).to.be.instanceof( ContainerElement );
  19. expect( root.rootName ).to.equal( 'main' );
  20. expect( root.name ).to.equal( 'div' );
  21. expect( root.isFocused ).to.be.false;
  22. expect( root.isReadOnly ).to.be.false;
  23. } );
  24. it( 'should create an element with custom root name', () => {
  25. const root = new RootEditableElement( document, 'h1' );
  26. root.rootName = 'header';
  27. expect( root.rootName ).to.equal( 'header' );
  28. expect( root.name ).to.equal( 'h1' );
  29. expect( root.isFocused ).to.be.false;
  30. expect( root.isReadOnly ).to.be.false;
  31. } );
  32. } );
  33. describe( 'is()', () => {
  34. let el;
  35. before( () => {
  36. el = new RootEditableElement( document, 'div' );
  37. } );
  38. it( 'should return true for rootElement/containerElement/editable/element, also with correct name and element name', () => {
  39. expect( el.is( 'rootElement' ) ).to.be.true;
  40. expect( el.is( 'view:rootElement' ) ).to.be.true;
  41. expect( el.is( 'rootElement', 'div' ) ).to.be.true;
  42. expect( el.is( 'view:rootElement', 'div' ) ).to.be.true;
  43. expect( el.is( 'containerElement' ) ).to.be.true;
  44. expect( el.is( 'view:containerElement' ) ).to.be.true;
  45. expect( el.is( 'containerElement', 'div' ) ).to.be.true;
  46. expect( el.is( 'view:containerElement', 'div' ) ).to.be.true;
  47. expect( el.is( 'editableElement' ) ).to.be.true;
  48. expect( el.is( 'view:editableElement' ) ).to.be.true;
  49. expect( el.is( 'editableElement', 'div' ) ).to.be.true;
  50. expect( el.is( 'view:editableElement', 'div' ) ).to.be.true;
  51. expect( el.is( 'element' ) ).to.be.true;
  52. expect( el.is( 'view:element' ) ).to.be.true;
  53. expect( el.is( 'element', 'div' ) ).to.be.true;
  54. expect( el.is( 'view:element', '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( 'element', '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. expect( el.is( 'div' ) ).to.be.false;
  74. expect( el.is( 'view:div' ) ).to.be.false;
  75. expect( el.is( 'node', 'div' ) ).to.be.false;
  76. expect( el.is( 'view:node', 'div' ) ).to.be.false;
  77. } );
  78. } );
  79. describe( '_name', () => {
  80. it( 'should set new name to element', () => {
  81. const el = new RootEditableElement( document, '$root' );
  82. expect( el.name ).to.equal( '$root' );
  83. el._name = 'div';
  84. expect( el.name ).to.equal( 'div' );
  85. } );
  86. } );
  87. it( 'should be cloned properly', () => {
  88. const root = new RootEditableElement( document, 'h1' );
  89. root.rootName = 'header';
  90. const newRoot = root._clone();
  91. expect( newRoot.document ).to.equal( root.document );
  92. expect( newRoot.rootName ).to.equal( root.rootName );
  93. } );
  94. } );