8
0

ckeditor.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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( 'heading works', () => {
  83. const data = [
  84. '<h2>Heading 1.</h2>',
  85. '<h3>Heading 1.1</h3>',
  86. '<h4>Heading 1.1.1</h4>',
  87. '<h4>Heading 1.1.2</h4>',
  88. '<h3>Heading 1.2</h3>',
  89. '<h4>Heading 1.2.1</h4>',
  90. '<h2>Heading 2</h2>'
  91. ].join( '' );
  92. editor.setData( data );
  93. expect( editor.getData() ).to.equal( data );
  94. } );
  95. it( 'image works', () => {
  96. const data = '<figure class="image"><img src="./manual/sample.jpg"></figure>';
  97. editor.setData( data );
  98. expect( editor.getData() ).to.equal( data );
  99. } );
  100. it( 'list works', () => {
  101. const data = [
  102. '<ul>',
  103. '<li>Item 1.</li>',
  104. '<li>Item 2.</li>',
  105. '</ul>',
  106. '<ol>',
  107. '<li>Item 1.</li>',
  108. '<li>Item 2.</li>',
  109. '</ol>'
  110. ].join( '' );
  111. editor.setData( data );
  112. expect( editor.getData() ).to.equal( data );
  113. } );
  114. it( 'link works', () => {
  115. const data = '<p><a href="//ckeditor.com">CKEditor.com</a></p>';
  116. editor.setData( data );
  117. expect( editor.getData() ).to.equal( data );
  118. } );
  119. } )
  120. } );