8
0

ckeditor.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicEditor from '../src/ckeditor';
  7. import BaseClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  8. describe( 'ClassicEditor build', () => {
  9. let editor, editorElement;
  10. beforeEach( () => {
  11. editorElement = document.createElement( 'div' );
  12. editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
  13. document.body.appendChild( editorElement );
  14. } );
  15. afterEach( () => {
  16. editorElement.remove();
  17. editor = null;
  18. } );
  19. describe( 'buid', () => {
  20. it( 'contains plugins', () => {
  21. expect( ClassicEditor.build.plugins ).to.not.be.empty;
  22. } );
  23. it( 'contains config', () => {
  24. expect( ClassicEditor.build.config.toolbar ).to.not.be.empty;
  25. } );
  26. } );
  27. describe( 'create()', () => {
  28. beforeEach( () => {
  29. return ClassicEditor.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 ClassicEditor', () => {
  38. expect( editor ).to.be.instanceof( ClassicEditor );
  39. expect( editor ).to.be.instanceof( BaseClassicEditor );
  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 ClassicEditor.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. it( 'restores the editor element', () => {
  60. expect( editor.element.style.display ).to.equal( 'none' );
  61. return editor.destroy()
  62. .then( () => {
  63. expect( editor.element.style.display ).to.equal( '' );
  64. } );
  65. } );
  66. } );
  67. describe( 'plugins', () => {
  68. beforeEach( () => {
  69. return ClassicEditor.create( editorElement )
  70. .then( newEditor => {
  71. editor = newEditor;
  72. } );
  73. } );
  74. afterEach( () => {
  75. return editor.destroy();
  76. } );
  77. it( 'paragraph works', () => {
  78. const data = '<p>Some text inside a paragraph.</p>';
  79. editor.setData( data );
  80. expect( editor.getData() ).to.equal( data );
  81. } );
  82. it( 'basic-styles work', () => {
  83. const data = [
  84. '<p>',
  85. '<strong>Test:strong</strong>',
  86. '<i>Test:i</i>',
  87. '</p>'
  88. ].join( '' );
  89. editor.setData( data );
  90. expect( editor.getData() ).to.equal( data );
  91. } );
  92. it( 'block-quote works', () => {
  93. const data = '<blockquote><p>Quote</p></blockquote>';
  94. editor.setData( data );
  95. expect( editor.getData() ).to.equal( data );
  96. } );
  97. it( 'heading works', () => {
  98. const data = [
  99. '<h2>Heading 1.</h2>',
  100. '<h3>Heading 1.1</h3>',
  101. '<h4>Heading 1.1.1</h4>',
  102. '<h4>Heading 1.1.2</h4>',
  103. '<h3>Heading 1.2</h3>',
  104. '<h4>Heading 1.2.1</h4>',
  105. '<h2>Heading 2</h2>'
  106. ].join( '' );
  107. editor.setData( data );
  108. expect( editor.getData() ).to.equal( data );
  109. } );
  110. it( 'image works', () => {
  111. const data = '<figure class="image"><img src="./manual/sample.jpg"></figure>';
  112. editor.setData( data );
  113. expect( editor.getData() ).to.equal( data );
  114. } );
  115. it( 'list works', () => {
  116. const data = [
  117. '<ul>',
  118. '<li>Item 1.</li>',
  119. '<li>Item 2.</li>',
  120. '</ul>',
  121. '<ol>',
  122. '<li>Item 1.</li>',
  123. '<li>Item 2.</li>',
  124. '</ol>'
  125. ].join( '' );
  126. editor.setData( data );
  127. expect( editor.getData() ).to.equal( data );
  128. } );
  129. it( 'link works', () => {
  130. const data = '<p><a href="//ckeditor.com">CKEditor.com</a></p>';
  131. editor.setData( data );
  132. expect( editor.getData() ).to.equal( data );
  133. } );
  134. } );
  135. describe( 'config', () => {
  136. afterEach( () => {
  137. return editor.destroy();
  138. } );
  139. // https://github.com/ckeditor/ckeditor5/issues/572
  140. it( 'allows configure toolbar items through config.toolbar', () => {
  141. return ClassicEditor
  142. .create( editorElement, {
  143. toolbar: [ 'bold' ]
  144. } )
  145. .then( newEditor => {
  146. editor = newEditor;
  147. expect( editor.ui.view.toolbar.items.length ).to.equal( 1 );
  148. } );
  149. } );
  150. // https://github.com/ckeditor/ckeditor5/issues/572
  151. it( 'allows configure toolbar offset without overriding toolbar items', () => {
  152. return ClassicEditor
  153. .create( editorElement, {
  154. toolbar: {
  155. viewportTopOffset: 42
  156. }
  157. } )
  158. .then( newEditor => {
  159. editor = newEditor;
  160. expect( editor.ui.view.toolbar.items.length ).to.equal( 9 );
  161. expect( editor.ui.view.stickyPanel.viewportTopOffset ).to.equal( 42 );
  162. } );
  163. } );
  164. } );
  165. } );