ckeditor.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 BalloonEditor from '../src/ckeditor';
  7. import BaseBalloonEditor from '@ckeditor/ckeditor5-editor-balloon/src/ballooneditor';
  8. describe( 'BalloonEditor build', () => {
  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( BalloonEditor.build.plugins ).to.not.be.empty;
  21. } );
  22. it( 'contains config', () => {
  23. expect( BalloonEditor.build.config.toolbar ).to.not.be.empty;
  24. } );
  25. } );
  26. describe( 'create()', () => {
  27. beforeEach( () => {
  28. return BalloonEditor.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 BalloonEditor', () => {
  37. expect( editor ).to.be.instanceof( BalloonEditor );
  38. expect( editor ).to.be.instanceof( BaseBalloonEditor );
  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( () => {
  46. return BalloonEditor.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. } );
  59. describe( 'plugins', () => {
  60. beforeEach( () => {
  61. return BalloonEditor.create( editorElement )
  62. .then( newEditor => {
  63. editor = newEditor;
  64. } );
  65. } );
  66. afterEach( () => {
  67. return editor.destroy();
  68. } );
  69. it( 'paragraph works', () => {
  70. const data = '<p>Some text inside a paragraph.</p>';
  71. editor.setData( data );
  72. expect( editor.getData() ).to.equal( data );
  73. } );
  74. it( 'basic-styles work', () => {
  75. const data = [
  76. '<p>',
  77. '<strong>Test:strong</strong>',
  78. '<i>Test:i</i>',
  79. '</p>'
  80. ].join( '' );
  81. editor.setData( data );
  82. expect( editor.getData() ).to.equal( data );
  83. } );
  84. it( 'block-quote works', () => {
  85. const data = '<blockquote><p>Quote</p></blockquote>';
  86. editor.setData( data );
  87. expect( editor.getData() ).to.equal( data );
  88. } );
  89. it( 'heading works', () => {
  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 works', () => {
  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 works', () => {
  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 works', () => {
  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. } );