ckeditor.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import DecoupledDocumentEditor from '../src/ckeditor';
  7. import DecoupledEditor from '@ckeditor/ckeditor5-editor-decoupled/src/decouplededitor';
  8. describe( 'DecoupledDocumentEditor build', () => {
  9. let editor, editorData;
  10. beforeEach( () => {
  11. editorData = '<p><strong>foo</strong> bar</p>';
  12. } );
  13. afterEach( () => {
  14. editor = null;
  15. } );
  16. describe( 'buid', () => {
  17. it( 'contains plugins', () => {
  18. expect( DecoupledDocumentEditor.build.plugins ).to.not.be.empty;
  19. } );
  20. it( 'contains config', () => {
  21. expect( DecoupledDocumentEditor.build.config.toolbar ).to.not.be.empty;
  22. } );
  23. } );
  24. describe( 'create()', () => {
  25. beforeEach( () => {
  26. return DecoupledDocumentEditor.create( editorData )
  27. .then( newEditor => {
  28. editor = newEditor;
  29. } );
  30. } );
  31. afterEach( () => {
  32. return editor.destroy();
  33. } );
  34. it( 'creates an instance which inherits from the DecoupledDocumentEditor', () => {
  35. expect( editor ).to.be.instanceof( DecoupledDocumentEditor );
  36. expect( editor ).to.be.instanceof( DecoupledEditor );
  37. } );
  38. it( 'loads passed data', () => {
  39. expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
  40. } );
  41. it( 'does not define the UI DOM structure', () => {
  42. expect( editor.ui.view.element ).to.be.null;
  43. expect( editor.ui.view.toolbar.element.parentElement ).to.be.null;
  44. expect( editor.ui.view.editable.element.parentElement ).to.be.null;
  45. } );
  46. } );
  47. describe( 'destroy()', () => {
  48. beforeEach( () => {
  49. return DecoupledDocumentEditor.create( editorData )
  50. .then( newEditor => {
  51. editor = newEditor;
  52. } );
  53. } );
  54. } );
  55. describe( 'plugins', () => {
  56. beforeEach( () => {
  57. return DecoupledDocumentEditor.create( editorData )
  58. .then( newEditor => {
  59. editor = newEditor;
  60. } );
  61. } );
  62. afterEach( () => {
  63. return editor.destroy();
  64. } );
  65. it( 'paragraph works', () => {
  66. const data = '<p>Some text inside a paragraph.</p>';
  67. editor.setData( data );
  68. expect( editor.getData() ).to.equal( data );
  69. } );
  70. it( 'basic-styles work', () => {
  71. const data = [
  72. '<p>',
  73. '<strong>Test:strong</strong>',
  74. '<i>Test:i</i>',
  75. '<u>Test:u</u>',
  76. '<s>Test:s</s>',
  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. it( 'font size works', () => {
  125. const data = '<p><span class="text-big">foo</span></p>';
  126. editor.setData( data );
  127. expect( editor.getData() ).to.equal( data );
  128. } );
  129. it( 'font family works', () => {
  130. const data = '<p><span style="font-family:Georgia, serif;">foo</span></p>';
  131. editor.setData( data );
  132. expect( editor.getData() ).to.equal( data );
  133. } );
  134. it( 'highlight works', () => {
  135. const data = '<p><mark class="marker-green">foo</mark></p>';
  136. editor.setData( data );
  137. expect( editor.getData() ).to.equal( data );
  138. } );
  139. it( 'alignment works', () => {
  140. const data = '<p style="text-align:right;">foo</p>';
  141. editor.setData( data );
  142. expect( editor.getData() ).to.equal( data );
  143. } );
  144. } );
  145. describe( 'config', () => {
  146. afterEach( () => {
  147. return editor.destroy();
  148. } );
  149. // https://github.com/ckeditor/ckeditor5/issues/572
  150. it( 'allows configure toolbar items through config.toolbar', () => {
  151. return DecoupledDocumentEditor
  152. .create( editorData, {
  153. toolbar: [ 'bold' ]
  154. } )
  155. .then( newEditor => {
  156. editor = newEditor;
  157. expect( editor.ui.view.toolbar.items.length ).to.equal( 1 );
  158. } );
  159. } );
  160. } );
  161. } );