ckeditor.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. /* globals document */
  6. import InlineEditor from '../src/ckeditor';
  7. import BaseInlineEditor from '@ckeditor/ckeditor5-editor-inline/src/inlineeditor';
  8. import { describeMemoryUsage, testMemoryUsage } from '@ckeditor/ckeditor5-core/tests/_utils/memory';
  9. describe( 'InlineEditor 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( InlineEditor.builtinPlugins ).to.not.be.empty;
  22. } );
  23. it( 'contains config', () => {
  24. expect( InlineEditor.defaultConfig.toolbar ).to.not.be.empty;
  25. } );
  26. } );
  27. describe( 'create()', () => {
  28. beforeEach( () => {
  29. return InlineEditor.create( editorElement )
  30. .then( newEditor => {
  31. editor = newEditor;
  32. } );
  33. } );
  34. afterEach( () => {
  35. return editor.destroy();
  36. } );
  37. it( 'creates an instance which inherits from the InlineEditor', () => {
  38. expect( editor ).to.be.instanceof( InlineEditor );
  39. expect( editor ).to.be.instanceof( BaseInlineEditor );
  40. } );
  41. it( 'loads data from the editor element', () => {
  42. expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
  43. } );
  44. } );
  45. describe( 'destroy()', () => {
  46. beforeEach( () => {
  47. return InlineEditor.create( editorElement )
  48. .then( newEditor => {
  49. editor = newEditor;
  50. } );
  51. } );
  52. it( 'sets the data back to the editor element', () => {
  53. editor.setData( '<p>foo</p>' );
  54. return editor.destroy()
  55. .then( () => {
  56. expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
  57. } );
  58. } );
  59. } );
  60. describe( 'plugins', () => {
  61. beforeEach( () => {
  62. return InlineEditor.create( editorElement )
  63. .then( newEditor => {
  64. editor = newEditor;
  65. } );
  66. } );
  67. afterEach( () => {
  68. return editor.destroy();
  69. } );
  70. it( 'paragraph works', () => {
  71. const data = '<p>Some text inside a paragraph.</p>';
  72. editor.setData( data );
  73. expect( editor.getData() ).to.equal( data );
  74. } );
  75. it( 'basic-styles work', () => {
  76. const data = [
  77. '<p>',
  78. '<strong>Test:strong</strong>',
  79. '<i>Test:i</i>',
  80. '</p>'
  81. ].join( '' );
  82. editor.setData( data );
  83. expect( editor.getData() ).to.equal( data );
  84. } );
  85. it( 'block-quote works', () => {
  86. const data = '<blockquote><p>Quote</p></blockquote>';
  87. editor.setData( data );
  88. expect( editor.getData() ).to.equal( data );
  89. } );
  90. it( 'heading works', () => {
  91. const data = [
  92. '<h2>Heading 1.</h2>',
  93. '<h3>Heading 1.1</h3>',
  94. '<h4>Heading 1.1.1</h4>',
  95. '<h4>Heading 1.1.2</h4>',
  96. '<h3>Heading 1.2</h3>',
  97. '<h4>Heading 1.2.1</h4>',
  98. '<h2>Heading 2</h2>'
  99. ].join( '' );
  100. editor.setData( data );
  101. expect( editor.getData() ).to.equal( data );
  102. } );
  103. it( 'image works', () => {
  104. const data = '<figure class="image"><img src="/assets/sample.png"></figure>';
  105. editor.setData( data );
  106. expect( editor.getData() ).to.equal( data );
  107. } );
  108. it( 'list works', () => {
  109. const data = [
  110. '<ul>',
  111. '<li>Item 1.</li>',
  112. '<li>Item 2.</li>',
  113. '</ul>',
  114. '<ol>',
  115. '<li>Item 1.</li>',
  116. '<li>Item 2.</li>',
  117. '</ol>'
  118. ].join( '' );
  119. editor.setData( data );
  120. expect( editor.getData() ).to.equal( data );
  121. } );
  122. it( 'link works', () => {
  123. const data = '<p><a href="//ckeditor.com">CKEditor.com</a></p>';
  124. editor.setData( data );
  125. expect( editor.getData() ).to.equal( data );
  126. } );
  127. } );
  128. describeMemoryUsage( () => {
  129. testMemoryUsage(
  130. 'should not grow on multiple create/destroy',
  131. () => InlineEditor.create( document.querySelector( '#mem-editor' ) ) );
  132. } );
  133. } );