articlepluginset.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global document */
  6. import ArticlePluginSet from '../_utils/articlepluginset';
  7. import ClassicTestEditor from '../_utils/classictesteditor';
  8. import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
  9. import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat';
  10. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  11. import Heading from '@ckeditor/ckeditor5-heading/src/heading';
  12. import Image from '@ckeditor/ckeditor5-image/src/image';
  13. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
  14. import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle';
  15. import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar';
  16. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
  17. import Link from '@ckeditor/ckeditor5-link/src/link';
  18. import List from '@ckeditor/ckeditor5-list/src/list';
  19. import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed';
  20. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  21. import Table from '@ckeditor/ckeditor5-table/src/table';
  22. import TableToolbar from '@ckeditor/ckeditor5-table/src/tabletoolbar';
  23. import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
  24. describe( 'ArticlePluginSet', () => {
  25. let editor, editorElement;
  26. beforeEach( () => {
  27. editorElement = document.createElement( 'div' );
  28. document.body.appendChild( editorElement );
  29. return ClassicTestEditor.create( editorElement, { plugins: [ ArticlePluginSet ] } )
  30. .then( newEditor => {
  31. editor = newEditor;
  32. } );
  33. } );
  34. afterEach( () => {
  35. editor.destroy();
  36. editorElement.remove();
  37. } );
  38. it.only( 'should be loaded', () => {
  39. expect( editor.plugins.get( ArticlePluginSet ) ).to.be.instanceOf( ArticlePluginSet );
  40. } );
  41. it( 'should load all its dependencies', () => {
  42. expect( editor.plugins.get( Essentials ) ).to.be.instanceOf( Essentials );
  43. expect( editor.plugins.get( Autoformat ) ).to.be.instanceOf( Autoformat );
  44. expect( editor.plugins.get( Bold ) ).to.be.instanceOf( Bold );
  45. expect( editor.plugins.get( Heading ) ).to.be.instanceOf( Heading );
  46. expect( editor.plugins.get( Image ) ).to.be.instanceOf( Image );
  47. expect( editor.plugins.get( ImageCaption ) ).to.be.instanceOf( ImageCaption );
  48. expect( editor.plugins.get( ImageStyle ) ).to.be.instanceOf( ImageStyle );
  49. expect( editor.plugins.get( ImageToolbar ) ).to.be.instanceOf( ImageToolbar );
  50. expect( editor.plugins.get( Italic ) ).to.be.instanceOf( Italic );
  51. expect( editor.plugins.get( Link ) ).to.be.instanceOf( Link );
  52. expect( editor.plugins.get( List ) ).to.be.instanceOf( List );
  53. expect( editor.plugins.get( MediaEmbed ) ).to.be.instanceOf( MediaEmbed );
  54. expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
  55. expect( editor.plugins.get( Table ) ).to.be.instanceOf( Table );
  56. expect( editor.plugins.get( TableToolbar ) ).to.be.instanceOf( TableToolbar );
  57. } );
  58. it( 'loads data', () => {
  59. const data =
  60. '<h2>Heading 1</h2>' +
  61. '<p>Paragraph</p>' +
  62. '<p><strong>Bold</strong> <i>Italic</i> <a href="foo">Link</a></p>' +
  63. '<ul>' +
  64. '<li>UL List item 1</li>' +
  65. '<li>UL List item 2</li>' +
  66. '</ul>' +
  67. '<ol>' +
  68. '<li>OL List item 1</li>' +
  69. '<li>OL List item 2</li>' +
  70. '</ol>' +
  71. '<figure class="image image-style-side">' +
  72. '<img alt="bar" src="/assets/sample.png">' +
  73. '<figcaption>Caption</figcaption>' +
  74. '</figure>' +
  75. '<blockquote>' +
  76. '<p>Quote</p>' +
  77. '<ul><li>Quoted UL List item 1</li></ul>' +
  78. '</blockquote>' +
  79. '<figure class="table">' +
  80. '<table>' +
  81. '<tbody>' +
  82. '<tr>' +
  83. '<td>a1</td>' +
  84. '<td>a2</td>' +
  85. '</tr>' +
  86. '<tr>' +
  87. '<td>b1</td>' +
  88. '<td>b2</td>' +
  89. '</tr>' +
  90. '</tbody>' +
  91. '</table>' +
  92. '</figure>';
  93. // Can't use data twice due to https://github.com/ckeditor/ckeditor5-utils/issues/128.
  94. const expectedOutput =
  95. '<h2>Heading 1</h2>' +
  96. '<p>Paragraph</p>' +
  97. '<p><strong>Bold</strong> <i>Italic</i> <a href="foo">Link</a></p>' +
  98. '<ul>' +
  99. '<li>UL List item 1</li>' +
  100. '<li>UL List item 2</li>' +
  101. '</ul>' +
  102. '<ol>' +
  103. '<li>OL List item 1</li>' +
  104. '<li>OL List item 2</li>' +
  105. '</ol>' +
  106. '<figure class="image image-style-side">' +
  107. '<img alt="bar" src="/assets/sample.png"></img>' +
  108. '<figcaption>Caption</figcaption>' +
  109. '</figure>' +
  110. '<blockquote>' +
  111. '<p>Quote</p>' +
  112. '<ul><li>Quoted UL List item 1</li></ul>' +
  113. '</blockquote>' +
  114. '<figure class="table">' +
  115. '<table>' +
  116. '<tbody>' +
  117. '<tr>' +
  118. '<td>a1</td>' +
  119. '<td>a2</td>' +
  120. '</tr>' +
  121. '<tr>' +
  122. '<td>b1</td>' +
  123. '<td>b2</td>' +
  124. '</tr>' +
  125. '</tbody>' +
  126. '</table>' +
  127. '</figure>';
  128. editor.setData( data );
  129. expect( normalizeHtml( editor.getData() ) ).to.equal( expectedOutput );
  130. } );
  131. } );