8
0

ckeditor.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. /* globals document */
  6. import DecoupledEditor from '../src/ckeditor';
  7. import BaseDecoupledEditor from '@ckeditor/ckeditor5-editor-decoupled/src/decouplededitor';
  8. import { describeMemoryUsage, testMemoryUsage } from '@ckeditor/ckeditor5-core/tests/_utils/memory';
  9. describe( 'DecoupledEditor build', () => {
  10. let editor, editorData, editorElement;
  11. beforeEach( () => {
  12. editorData = '<p><strong>foo</strong> bar</p>';
  13. editorElement = document.createElement( 'div' );
  14. editorElement.innerHTML = editorData;
  15. document.body.appendChild( editorElement );
  16. } );
  17. afterEach( () => {
  18. editorElement.remove();
  19. editor = null;
  20. } );
  21. describe( 'build', () => {
  22. it( 'contains plugins', () => {
  23. expect( DecoupledEditor.builtinPlugins ).to.not.be.empty;
  24. } );
  25. it( 'contains config', () => {
  26. expect( DecoupledEditor.defaultConfig.toolbar ).to.not.be.empty;
  27. } );
  28. } );
  29. describe( 'editor with data', () => {
  30. test( () => editorData );
  31. it( 'does not define the UI DOM structure', () => {
  32. return DecoupledEditor.create( editorData )
  33. .then( newEditor => {
  34. expect( newEditor.ui.view.element ).to.be.null;
  35. expect( newEditor.ui.view.toolbar.element.parentElement ).to.be.null;
  36. expect( newEditor.ui.view.editable.element.parentElement ).to.be.null;
  37. } );
  38. } );
  39. } );
  40. describe( 'editor with editable element', () => {
  41. test( () => editorElement );
  42. it( 'uses the provided editable element', () => {
  43. return DecoupledEditor.create( editorElement )
  44. .then( newEditor => {
  45. expect( newEditor.ui.view.editable.element.parentElement ).to.equal( document.body );
  46. } );
  47. } );
  48. } );
  49. describeMemoryUsage( () => {
  50. testMemoryUsage(
  51. 'should not grow on multiple create/destroy',
  52. () => DecoupledEditor.create( document.querySelector( '#mem-editor' ) ) );
  53. } );
  54. function test( getEditorDataOrElement ) {
  55. describe( 'create()', () => {
  56. beforeEach( () => {
  57. return DecoupledEditor.create( getEditorDataOrElement() )
  58. .then( newEditor => {
  59. editor = newEditor;
  60. } );
  61. } );
  62. afterEach( () => {
  63. return editor.destroy();
  64. } );
  65. it( 'creates an instance which inherits from the DecoupledEditor', () => {
  66. expect( editor ).to.be.instanceof( BaseDecoupledEditor );
  67. expect( editor ).to.be.instanceof( BaseDecoupledEditor );
  68. } );
  69. it( 'loads passed data', () => {
  70. expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
  71. } );
  72. } );
  73. describe( 'destroy()', () => {
  74. beforeEach( () => {
  75. return DecoupledEditor.create( getEditorDataOrElement() )
  76. .then( newEditor => {
  77. editor = newEditor;
  78. } );
  79. } );
  80. } );
  81. describe( 'plugins', () => {
  82. beforeEach( () => {
  83. return DecoupledEditor.create( getEditorDataOrElement() )
  84. .then( newEditor => {
  85. editor = newEditor;
  86. } );
  87. } );
  88. afterEach( () => {
  89. return editor.destroy();
  90. } );
  91. it( 'paragraph works', () => {
  92. const data = '<p>Some text inside a paragraph.</p>';
  93. editor.setData( data );
  94. expect( editor.getData() ).to.equal( data );
  95. } );
  96. it( 'basic-styles work', () => {
  97. const data = [
  98. '<p>',
  99. '<strong>Test:strong</strong>',
  100. '<i>Test:i</i>',
  101. '<u>Test:u</u>',
  102. '<s>Test:s</s>',
  103. '</p>'
  104. ].join( '' );
  105. editor.setData( data );
  106. expect( editor.getData() ).to.equal( data );
  107. } );
  108. it( 'block-quote works', () => {
  109. const data = '<blockquote><p>Quote</p></blockquote>';
  110. editor.setData( data );
  111. expect( editor.getData() ).to.equal( data );
  112. } );
  113. it( 'heading works', () => {
  114. const data = [
  115. '<h2>Heading 1.</h2>',
  116. '<h3>Heading 1.1</h3>',
  117. '<h4>Heading 1.1.1</h4>',
  118. '<h4>Heading 1.1.2</h4>',
  119. '<h3>Heading 1.2</h3>',
  120. '<h4>Heading 1.2.1</h4>',
  121. '<h2>Heading 2</h2>'
  122. ].join( '' );
  123. editor.setData( data );
  124. expect( editor.getData() ).to.equal( data );
  125. } );
  126. it( 'image works', () => {
  127. const data = '<figure class="image"><img src="./manual/sample.jpg"></figure>';
  128. editor.setData( data );
  129. expect( editor.getData() ).to.equal( data );
  130. } );
  131. it( 'list works', () => {
  132. const data = [
  133. '<ul>',
  134. '<li>Item 1.</li>',
  135. '<li>Item 2.</li>',
  136. '</ul>',
  137. '<ol>',
  138. '<li>Item 1.</li>',
  139. '<li>Item 2.</li>',
  140. '</ol>'
  141. ].join( '' );
  142. editor.setData( data );
  143. expect( editor.getData() ).to.equal( data );
  144. } );
  145. it( 'link works', () => {
  146. const data = '<p><a href="//ckeditor.com">CKEditor.com</a></p>';
  147. editor.setData( data );
  148. expect( editor.getData() ).to.equal( data );
  149. } );
  150. it( 'font size works', () => {
  151. const data = '<p><span class="text-big">foo</span></p>';
  152. editor.setData( data );
  153. expect( editor.getData() ).to.equal( data );
  154. } );
  155. it( 'font family works', () => {
  156. const data = '<p><span style="font-family:Georgia, serif;">foo</span></p>';
  157. editor.setData( data );
  158. expect( editor.getData() ).to.equal( data );
  159. } );
  160. it( 'highlight works', () => {
  161. const data = '<p><mark class="marker-green">foo</mark></p>';
  162. editor.setData( data );
  163. expect( editor.getData() ).to.equal( data );
  164. } );
  165. it( 'alignment works', () => {
  166. const data = '<p style="text-align:right;">foo</p>';
  167. editor.setData( data );
  168. expect( editor.getData() ).to.equal( data );
  169. } );
  170. } );
  171. describe( 'config', () => {
  172. afterEach( () => {
  173. return editor.destroy();
  174. } );
  175. // https://github.com/ckeditor/ckeditor5/issues/572
  176. it( 'allows configure toolbar items through config.toolbar', () => {
  177. return DecoupledEditor
  178. .create( getEditorDataOrElement(), {
  179. toolbar: [ 'bold' ]
  180. } )
  181. .then( newEditor => {
  182. editor = newEditor;
  183. expect( editor.ui.view.toolbar.items.length ).to.equal( 1 );
  184. } );
  185. } );
  186. } );
  187. }
  188. } );