ckeditor.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. '</p>'
  76. ].join( '' );
  77. editor.setData( data );
  78. expect( editor.getData() ).to.equal( data );
  79. } );
  80. it( 'block-quote works', () => {
  81. const data = '<blockquote><p>Quote</p></blockquote>';
  82. editor.setData( data );
  83. expect( editor.getData() ).to.equal( data );
  84. } );
  85. it( 'heading works', () => {
  86. const data = [
  87. '<h2>Heading 1.</h2>',
  88. '<h3>Heading 1.1</h3>',
  89. '<h4>Heading 1.1.1</h4>',
  90. '<h4>Heading 1.1.2</h4>',
  91. '<h3>Heading 1.2</h3>',
  92. '<h4>Heading 1.2.1</h4>',
  93. '<h2>Heading 2</h2>'
  94. ].join( '' );
  95. editor.setData( data );
  96. expect( editor.getData() ).to.equal( data );
  97. } );
  98. it( 'image works', () => {
  99. const data = '<figure class="image"><img src="./manual/sample.jpg"></figure>';
  100. editor.setData( data );
  101. expect( editor.getData() ).to.equal( data );
  102. } );
  103. it( 'list works', () => {
  104. const data = [
  105. '<ul>',
  106. '<li>Item 1.</li>',
  107. '<li>Item 2.</li>',
  108. '</ul>',
  109. '<ol>',
  110. '<li>Item 1.</li>',
  111. '<li>Item 2.</li>',
  112. '</ol>'
  113. ].join( '' );
  114. editor.setData( data );
  115. expect( editor.getData() ).to.equal( data );
  116. } );
  117. it( 'link works', () => {
  118. const data = '<p><a href="//ckeditor.com">CKEditor.com</a></p>';
  119. editor.setData( data );
  120. expect( editor.getData() ).to.equal( data );
  121. } );
  122. } );
  123. describe( 'config', () => {
  124. afterEach( () => {
  125. return editor.destroy();
  126. } );
  127. // https://github.com/ckeditor/ckeditor5/issues/572
  128. it( 'allows configure toolbar items through config.toolbar', () => {
  129. return DecoupledDocumentEditor
  130. .create( editorData, {
  131. toolbar: [ 'bold' ]
  132. } )
  133. .then( newEditor => {
  134. editor = newEditor;
  135. expect( editor.ui.view.toolbar.items.length ).to.equal( 1 );
  136. } );
  137. } );
  138. } );
  139. } );