ckeditor.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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( function () {
  35. return ClassicEditor.create( editorElement )
  36. .then( newEditor => {
  37. editor = newEditor;
  38. } );
  39. } );
  40. afterEach( () => {
  41. return editor.destroy();
  42. } );
  43. it( 'should load all its dependencies', () => {
  44. expect( editor.plugins.get( ParagraphPlugin ) ).to.be.instanceOf( ParagraphPlugin );
  45. expect( editor.plugins.get( AutoformatPlugin ) ).to.be.instanceOf( AutoformatPlugin );
  46. expect( editor.plugins.get( BoldPlugin ) ).to.be.instanceOf( BoldPlugin );
  47. expect( editor.plugins.get( HeadingPlugin ) ).to.be.instanceOf( HeadingPlugin );
  48. expect( editor.plugins.get( ImagePlugin ) ).to.be.instanceOf( ImagePlugin );
  49. expect( editor.plugins.get( ImageCaptionPlugin ) ).to.be.instanceOf( ImageCaptionPlugin );
  50. expect( editor.plugins.get( ImageStylePlugin ) ).to.be.instanceOf( ImageStylePlugin );
  51. expect( editor.plugins.get( ImageToolbarPlugin ) ).to.be.instanceOf( ImageToolbarPlugin );
  52. expect( editor.plugins.get( ItalicPlugin ) ).to.be.instanceOf( ItalicPlugin );
  53. expect( editor.plugins.get( LinkPlugin ) ).to.be.instanceOf( LinkPlugin );
  54. expect( editor.plugins.get( ListPlugin ) ).to.be.instanceOf( ListPlugin );
  55. expect( editor.plugins.get( ClipboardPlugin ) ).to.be.instanceOf( ClipboardPlugin );
  56. expect( editor.plugins.get( EnterPlugin ) ).to.be.instanceOf( EnterPlugin );
  57. expect( editor.plugins.get( TypingPlugin ) ).to.be.instanceOf( TypingPlugin );
  58. expect( editor.plugins.get( UndoPlugin ) ).to.be.instanceOf( UndoPlugin );
  59. } );
  60. it( 'creates an instance which inherits from the ClassicEditor', () => {
  61. expect( editor ).to.be.instanceof( ClassicEditor );
  62. expect( editor ).to.be.instanceof( BaseClassicEditor );
  63. } );
  64. it( 'loads data from the editor element', () => {
  65. expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
  66. } );
  67. } );
  68. describe( 'destroy()', () => {
  69. beforeEach( function () {
  70. return ClassicEditor.create( editorElement )
  71. .then( newEditor => {
  72. editor = newEditor;
  73. } );
  74. } );
  75. it( 'sets the data back to the editor element', () => {
  76. editor.setData( '<p>foo</p>' );
  77. return editor.destroy()
  78. .then( () => {
  79. expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
  80. } );
  81. } );
  82. it( 'restores the editor element', () => {
  83. expect( editor.element.style.display ).to.equal( 'none' );
  84. return editor.destroy()
  85. .then( () => {
  86. expect( editor.element.style.display ).to.equal( '' );
  87. } );
  88. } );
  89. } );
  90. } );