ckeditor.js 5.6 KB

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