ckeditor.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. describe( 'ClassicEditor', () => {
  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. } );
  18. describe( 'buid', () => {
  19. it( 'contains plugins', () => {
  20. expect( ClassicEditor.build.plugins ).to.not.be.empty;
  21. } );
  22. it( 'contains config', () => {
  23. expect( ClassicEditor.build.config.toolbar ).to.not.be.empty;
  24. } );
  25. } );
  26. describe( 'create()', () => {
  27. beforeEach( () => {
  28. return ClassicEditor.create( editorElement )
  29. .then( newEditor => {
  30. editor = newEditor;
  31. } );
  32. } );
  33. afterEach( () => {
  34. return editor.destroy();
  35. } );
  36. it( 'creates an instance which inherits from the ClassicEditor', () => {
  37. expect( editor ).to.be.instanceof( ClassicEditor );
  38. expect( editor ).to.be.instanceof( BaseClassicEditor );
  39. } );
  40. it( 'loads data from the editor element', () => {
  41. expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
  42. } );
  43. } );
  44. describe( 'destroy()', () => {
  45. beforeEach( function () {
  46. return ClassicEditor.create( editorElement )
  47. .then( newEditor => {
  48. editor = newEditor;
  49. } );
  50. } );
  51. it( 'sets the data back to the editor element', () => {
  52. editor.setData( '<p>foo</p>' );
  53. return editor.destroy()
  54. .then( () => {
  55. expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
  56. } );
  57. } );
  58. it( 'restores the editor element', () => {
  59. expect( editor.element.style.display ).to.equal( 'none' );
  60. return editor.destroy()
  61. .then( () => {
  62. expect( editor.element.style.display ).to.equal( '' );
  63. } );
  64. } );
  65. } );
  66. describe( 'plugins', () => {
  67. it( 'paragraph works', () => {
  68. const data = '<p>Some text inside a paragraph.</p>';
  69. editor.setData( data );
  70. expect( editor.getData() ).to.equal( data );
  71. } );
  72. it( 'basic-styles work', () => {
  73. const data = [
  74. '<p>',
  75. '<strong>Test:strong</strong>',
  76. '<em>Test:em</em>',
  77. '</p>'
  78. ].join( '' );
  79. editor.setData( data );
  80. expect( editor.getData() ).to.equal( data );
  81. } );
  82. it( 'block-quote works', () => {
  83. const data = '<blockquote><p>Quote</p></blockquote>';
  84. editor.setData( data );
  85. expect( editor.getData() ).to.equal( data );
  86. } );
  87. it( 'heading works', () => {
  88. const data = [
  89. '<h2>Heading 1.</h2>',
  90. '<h3>Heading 1.1</h3>',
  91. '<h4>Heading 1.1.1</h4>',
  92. '<h4>Heading 1.1.2</h4>',
  93. '<h3>Heading 1.2</h3>',
  94. '<h4>Heading 1.2.1</h4>',
  95. '<h2>Heading 2</h2>'
  96. ].join( '' );
  97. editor.setData( data );
  98. expect( editor.getData() ).to.equal( data );
  99. } );
  100. it( 'image works', () => {
  101. const data = '<figure class="image"><img src="./manual/sample.jpg"></figure>';
  102. editor.setData( data );
  103. expect( editor.getData() ).to.equal( data );
  104. } );
  105. it( 'list works', () => {
  106. const data = [
  107. '<ul>',
  108. '<li>Item 1.</li>',
  109. '<li>Item 2.</li>',
  110. '</ul>',
  111. '<ol>',
  112. '<li>Item 1.</li>',
  113. '<li>Item 2.</li>',
  114. '</ol>'
  115. ].join( '' );
  116. editor.setData( data );
  117. expect( editor.getData() ).to.equal( data );
  118. } );
  119. it( 'link works', () => {
  120. const data = '<p><a href="//ckeditor.com">CKEditor.com</a></p>';
  121. editor.setData( data );
  122. expect( editor.getData() ).to.equal( data );
  123. } );
  124. } )
  125. } );