ckeditor.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import { ClassicEditor } from '../ckeditor';
  7. import BaseClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
  8. import AutoformatPlugin from '@ckeditor/ckeditor5-autoformat/src/autoformat';
  9. import BoldPlugin from '@ckeditor/ckeditor5-basic-styles/src/bold';
  10. import ClipboardPlugin from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  11. import ParagraphPlugin from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  12. import HeadingPlugin from '@ckeditor/ckeditor5-heading/src/heading';
  13. import ImagePlugin from '@ckeditor/ckeditor5-image/src/image';
  14. import ImageCaptionPlugin from '@ckeditor/ckeditor5-image/src/imagecaption';
  15. import ImageStylePlugin from '@ckeditor/ckeditor5-image/src/imagestyle';
  16. import ImageToolbarPlugin from '@ckeditor/ckeditor5-image/src/imagetoolbar';
  17. import ItalicPlugin from '@ckeditor/ckeditor5-basic-styles/src/italic';
  18. import LinkPlugin from '@ckeditor/ckeditor5-link/src/link';
  19. import ListPlugin from '@ckeditor/ckeditor5-list/src/list';
  20. import EnterPlugin from '@ckeditor/ckeditor5-enter/src/enter';
  21. import TypingPlugin from '@ckeditor/ckeditor5-typing/src/typing';
  22. import UndoPlugin from '@ckeditor/ckeditor5-undo/src/undo';
  23. describe( 'ClassicEditor', () => {
  24. let editor, editorElement;
  25. beforeEach( () => {
  26. editorElement = document.createElement( 'div' );
  27. editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
  28. document.body.appendChild( editorElement );
  29. } );
  30. afterEach( () => {
  31. editorElement.remove();
  32. } );
  33. describe( 'create()', () => {
  34. beforeEach( () => {
  35. return ClassicEditor.create( editorElement )
  36. .then( newEditor => {
  37. editor = newEditor;
  38. } );
  39. } );
  40. afterEach( () => {
  41. return editor.destroy();
  42. } );
  43. it( 'creates an instance which inherits from the ClassicEditor', () => {
  44. expect( editor ).to.be.instanceof( ClassicEditor );
  45. expect( editor ).to.be.instanceof( BaseClassicEditor );
  46. } );
  47. it( 'loads data from the editor element', () => {
  48. expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
  49. } );
  50. } );
  51. describe( 'destroy()', () => {
  52. beforeEach( function () {
  53. return ClassicEditor.create( editorElement )
  54. .then( newEditor => {
  55. editor = newEditor;
  56. } );
  57. } );
  58. it( 'sets the data back to the editor element', () => {
  59. editor.setData( '<p>foo</p>' );
  60. return editor.destroy()
  61. .then( () => {
  62. expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
  63. } );
  64. } );
  65. it( 'restores the editor element', () => {
  66. expect( editor.element.style.display ).to.equal( 'none' );
  67. return editor.destroy()
  68. .then( () => {
  69. expect( editor.element.style.display ).to.equal( '' );
  70. } );
  71. } );
  72. } );
  73. describe( 'plugins', () => {
  74. it( 'paragraph', () => {
  75. const data = '<p>Some text inside a paragraph.</p>';
  76. editor.setData( data );
  77. expect( editor.getData() ).to.equal( data );
  78. } );
  79. it( 'basic-styles', () => {
  80. const data = [
  81. '<p>',
  82. '<strong>Test:strong</strong>',
  83. '<em>Test:em</em>',
  84. '</p>'
  85. ].join( '' );
  86. editor.setData( data );
  87. expect( editor.getData() ).to.equal( data );
  88. } );
  89. it( 'heading', () => {
  90. const data = [
  91. '<h2>Heading 1.</h2>',
  92. '<h3>Heading 1.1</h3>',
  93. '<h4>Heading 1.1.1</h4>',
  94. '<h4>Heading 1.1.2</h4>',
  95. '<h3>Heading 1.2</h3>',
  96. '<h4>Heading 1.2.1</h4>',
  97. '<h2>Heading 2</h2>'
  98. ].join( '' );
  99. editor.setData( data );
  100. expect( editor.getData() ).to.equal( data );
  101. } );
  102. it( 'image', () => {
  103. const data = '<figure class="image"><img src="./manual/sample.jpg"></figure>';
  104. editor.setData( data );
  105. expect( editor.getData() ).to.equal( data );
  106. } );
  107. it( 'list', () => {
  108. const data = [
  109. '<ul>',
  110. '<li>Item 1.</li>',
  111. '<li>Item 2.</li>',
  112. '</ul>',
  113. '<ol>',
  114. '<li>Item 1.</li>',
  115. '<li>Item 2.</li>',
  116. '</ol>'
  117. ].join( '' );
  118. editor.setData( data );
  119. expect( editor.getData() ).to.equal( data );
  120. } );
  121. it( 'link', () => {
  122. const data = '<p><a href="//ckeditor.com">CKEditor.com</a></p>';
  123. editor.setData( data );
  124. expect( editor.getData() ).to.equal( data );
  125. } );
  126. } )
  127. } );