ckeditor.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import BalloonEditor from '../src/ckeditor';
  7. import BaseBalloonEditor from '@ckeditor/ckeditor5-editor-balloon/src/ballooneditor';
  8. import { describeMemoryUsage, testMemoryUsage } from '@ckeditor/ckeditor5-core/tests/_utils/memory';
  9. describe( 'BalloonEditor build', () => {
  10. let editor, editorElement;
  11. beforeEach( () => {
  12. editorElement = document.createElement( 'div' );
  13. editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
  14. document.body.appendChild( editorElement );
  15. } );
  16. afterEach( () => {
  17. editorElement.remove();
  18. } );
  19. describe( 'buid', () => {
  20. it( 'contains plugins', () => {
  21. expect( BalloonEditor.builtinPlugins ).to.not.be.empty;
  22. } );
  23. it( 'contains config', () => {
  24. expect( BalloonEditor.defaultConfig.toolbar ).to.not.be.empty;
  25. } );
  26. it( 'contains block toolbar config', () => {
  27. expect( BalloonEditor.defaultConfig.blockToolbar ).to.not.be.empty;
  28. } );
  29. } );
  30. describe( 'create()', () => {
  31. beforeEach( () => {
  32. return BalloonEditor.create( editorElement )
  33. .then( newEditor => {
  34. editor = newEditor;
  35. } );
  36. } );
  37. afterEach( () => {
  38. return editor.destroy();
  39. } );
  40. it( 'creates an instance which inherits from the BalloonEditor', () => {
  41. expect( editor ).to.be.instanceof( BalloonEditor );
  42. expect( editor ).to.be.instanceof( BaseBalloonEditor );
  43. } );
  44. it( 'loads data from the editor element', () => {
  45. expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
  46. } );
  47. } );
  48. describe( 'destroy()', () => {
  49. beforeEach( () => {
  50. return BalloonEditor.create( editorElement )
  51. .then( newEditor => {
  52. editor = newEditor;
  53. } );
  54. } );
  55. it( 'sets the data back to the editor element', () => {
  56. editor.setData( '<p>foo</p>' );
  57. return editor.destroy()
  58. .then( () => {
  59. expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
  60. } );
  61. } );
  62. } );
  63. describe( 'plugins', () => {
  64. beforeEach( () => {
  65. return BalloonEditor.create( editorElement )
  66. .then( newEditor => {
  67. editor = newEditor;
  68. } );
  69. } );
  70. afterEach( () => {
  71. return editor.destroy();
  72. } );
  73. it( 'block toolbar works', () => {
  74. expect( editor.plugins.get( 'BlockToolbar' ) ).to.be.an( 'object' );
  75. } );
  76. it( 'paragraph works', () => {
  77. const data = '<p>Some text inside a paragraph.</p>';
  78. editor.setData( data );
  79. expect( editor.getData() ).to.equal( data );
  80. } );
  81. it( 'basic-styles work', () => {
  82. const data = [
  83. '<p>',
  84. '<strong>Test:strong</strong>',
  85. '<i>Test:i</i>',
  86. '</p>'
  87. ].join( '' );
  88. editor.setData( data );
  89. expect( editor.getData() ).to.equal( data );
  90. } );
  91. it( 'block-quote works', () => {
  92. const data = '<blockquote><p>Quote</p></blockquote>';
  93. editor.setData( data );
  94. expect( editor.getData() ).to.equal( data );
  95. } );
  96. it( 'heading works', () => {
  97. const data = [
  98. '<h2>Heading 1.</h2>',
  99. '<h3>Heading 1.1</h3>',
  100. '<h4>Heading 1.1.1</h4>',
  101. '<h4>Heading 1.1.2</h4>',
  102. '<h3>Heading 1.2</h3>',
  103. '<h4>Heading 1.2.1</h4>',
  104. '<h2>Heading 2</h2>'
  105. ].join( '' );
  106. editor.setData( data );
  107. expect( editor.getData() ).to.equal( data );
  108. } );
  109. it( 'image works', () => {
  110. const data = '<figure class="image"><img src="./manual/sample.jpg"></figure>';
  111. editor.setData( data );
  112. expect( editor.getData() ).to.equal( data );
  113. } );
  114. it( 'list works', () => {
  115. const data = [
  116. '<ul>',
  117. '<li>Item 1.</li>',
  118. '<li>Item 2.</li>',
  119. '</ul>',
  120. '<ol>',
  121. '<li>Item 1.</li>',
  122. '<li>Item 2.</li>',
  123. '</ol>'
  124. ].join( '' );
  125. editor.setData( data );
  126. expect( editor.getData() ).to.equal( data );
  127. } );
  128. it( 'link works', () => {
  129. const data = '<p><a href="//ckeditor.com">CKEditor.com</a></p>';
  130. editor.setData( data );
  131. expect( editor.getData() ).to.equal( data );
  132. } );
  133. } );
  134. describeMemoryUsage( () => {
  135. testMemoryUsage(
  136. 'should not grow on multiple create/destroy',
  137. () => BalloonEditor.create( document.querySelector( '#mem-editor' ) ) );
  138. } );
  139. } );