ckeditor.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 BalloonToolbarEditor from '../ckeditor';
  7. import BaseBalloonToolbarEditor from '@ckeditor/ckeditor5-editor-balloon-toolbar/src/balloontoolbareditor';
  8. describe( 'BalloonToolbarEditor 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( BalloonToolbarEditor.build.plugins ).to.not.be.empty;
  21. } );
  22. it( 'contains config', () => {
  23. expect( BalloonToolbarEditor.build.config.toolbar ).to.not.be.empty;
  24. } );
  25. } );
  26. describe( 'create()', () => {
  27. beforeEach( () => {
  28. return BalloonToolbarEditor.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 BalloonToolbarEditor', () => {
  37. expect( editor ).to.be.instanceof( BalloonToolbarEditor );
  38. expect( editor ).to.be.instanceof( BaseBalloonToolbarEditor );
  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 BalloonToolbarEditor.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. it( 'paragraph works', () => {
  61. const data = '<p>Some text inside a paragraph.</p>';
  62. editor.setData( data );
  63. expect( editor.getData() ).to.equal( data );
  64. } );
  65. it( 'basic-styles work', () => {
  66. const data = [
  67. '<p>',
  68. '<strong>Test:strong</strong>',
  69. '<i>Test:i</i>',
  70. '</p>'
  71. ].join( '' );
  72. editor.setData( data );
  73. expect( editor.getData() ).to.equal( data );
  74. } );
  75. it( 'block-quote works', () => {
  76. const data = '<blockquote><p>Quote</p></blockquote>';
  77. editor.setData( data );
  78. expect( editor.getData() ).to.equal( data );
  79. } );
  80. it( 'heading works', () => {
  81. const data = [
  82. '<h2>Heading 1.</h2>',
  83. '<h3>Heading 1.1</h3>',
  84. '<h4>Heading 1.1.1</h4>',
  85. '<h4>Heading 1.1.2</h4>',
  86. '<h3>Heading 1.2</h3>',
  87. '<h4>Heading 1.2.1</h4>',
  88. '<h2>Heading 2</h2>'
  89. ].join( '' );
  90. editor.setData( data );
  91. expect( editor.getData() ).to.equal( data );
  92. } );
  93. it( 'image works', () => {
  94. const data = '<figure class="image"><img src="./manual/sample.jpg"></figure>';
  95. editor.setData( data );
  96. expect( editor.getData() ).to.equal( data );
  97. } );
  98. it( 'list works', () => {
  99. const data = [
  100. '<ul>',
  101. '<li>Item 1.</li>',
  102. '<li>Item 2.</li>',
  103. '</ul>',
  104. '<ol>',
  105. '<li>Item 1.</li>',
  106. '<li>Item 2.</li>',
  107. '</ol>'
  108. ].join( '' );
  109. editor.setData( data );
  110. expect( editor.getData() ).to.equal( data );
  111. } );
  112. it( 'link works', () => {
  113. const data = '<p><a href="//ckeditor.com">CKEditor.com</a></p>';
  114. editor.setData( data );
  115. expect( editor.getData() ).to.equal( data );
  116. } );
  117. } );
  118. } );