articlepluginset.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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( async () => {
  27. editorElement = document.createElement( 'div' );
  28. document.body.appendChild( editorElement );
  29. editor = await ClassicTestEditor.create( editorElement, { plugins: [ ArticlePluginSet ] } );
  30. } );
  31. afterEach( async () => {
  32. await editor.destroy();
  33. editorElement.remove();
  34. } );
  35. it( 'should be loaded', () => {
  36. expect( editor.plugins.get( ArticlePluginSet ) ).to.be.instanceOf( ArticlePluginSet );
  37. } );
  38. it( 'should load all its dependencies', () => {
  39. expect( editor.plugins.get( Essentials ) ).to.be.instanceOf( Essentials );
  40. expect( editor.plugins.get( Autoformat ) ).to.be.instanceOf( Autoformat );
  41. expect( editor.plugins.get( Bold ) ).to.be.instanceOf( Bold );
  42. expect( editor.plugins.get( Heading ) ).to.be.instanceOf( Heading );
  43. expect( editor.plugins.get( Image ) ).to.be.instanceOf( Image );
  44. expect( editor.plugins.get( ImageCaption ) ).to.be.instanceOf( ImageCaption );
  45. expect( editor.plugins.get( ImageStyle ) ).to.be.instanceOf( ImageStyle );
  46. expect( editor.plugins.get( ImageToolbar ) ).to.be.instanceOf( ImageToolbar );
  47. expect( editor.plugins.get( Italic ) ).to.be.instanceOf( Italic );
  48. expect( editor.plugins.get( Link ) ).to.be.instanceOf( Link );
  49. expect( editor.plugins.get( List ) ).to.be.instanceOf( List );
  50. expect( editor.plugins.get( MediaEmbed ) ).to.be.instanceOf( MediaEmbed );
  51. expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
  52. expect( editor.plugins.get( Table ) ).to.be.instanceOf( Table );
  53. expect( editor.plugins.get( TableToolbar ) ).to.be.instanceOf( TableToolbar );
  54. } );
  55. it( 'loads data', () => {
  56. const data =
  57. '<h2>Heading 1</h2>' +
  58. '<p>Paragraph</p>' +
  59. '<p><strong>Bold</strong> <i>Italic</i> <a href="foo">Link</a></p>' +
  60. '<ul>' +
  61. '<li>UL List item 1</li>' +
  62. '<li>UL List item 2</li>' +
  63. '</ul>' +
  64. '<ol>' +
  65. '<li>OL List item 1</li>' +
  66. '<li>OL List item 2</li>' +
  67. '</ol>' +
  68. '<figure class="image image-style-side">' +
  69. '<img alt="bar" src="/assets/sample.png">' +
  70. '<figcaption>Caption</figcaption>' +
  71. '</figure>' +
  72. '<blockquote>' +
  73. '<p>Quote</p>' +
  74. '<ul><li>Quoted UL List item 1</li></ul>' +
  75. '</blockquote>' +
  76. '<figure class="table">' +
  77. '<table>' +
  78. '<tbody>' +
  79. '<tr>' +
  80. '<td>a1</td>' +
  81. '<td>a2</td>' +
  82. '</tr>' +
  83. '<tr>' +
  84. '<td>b1</td>' +
  85. '<td>b2</td>' +
  86. '</tr>' +
  87. '</tbody>' +
  88. '</table>' +
  89. '</figure>';
  90. // Can't use data twice due to https://github.com/ckeditor/ckeditor5-utils/issues/128.
  91. const expectedOutput =
  92. '<h2>Heading 1</h2>' +
  93. '<p>Paragraph</p>' +
  94. '<p><strong>Bold</strong> <i>Italic</i> <a href="foo">Link</a></p>' +
  95. '<ul>' +
  96. '<li>UL List item 1</li>' +
  97. '<li>UL List item 2</li>' +
  98. '</ul>' +
  99. '<ol>' +
  100. '<li>OL List item 1</li>' +
  101. '<li>OL List item 2</li>' +
  102. '</ol>' +
  103. '<figure class="image image-style-side">' +
  104. '<img alt="bar" src="/assets/sample.png"></img>' +
  105. '<figcaption>Caption</figcaption>' +
  106. '</figure>' +
  107. '<blockquote>' +
  108. '<p>Quote</p>' +
  109. '<ul><li>Quoted UL List item 1</li></ul>' +
  110. '</blockquote>' +
  111. '<figure class="table">' +
  112. '<table>' +
  113. '<tbody>' +
  114. '<tr>' +
  115. '<td>a1</td>' +
  116. '<td>a2</td>' +
  117. '</tr>' +
  118. '<tr>' +
  119. '<td>b1</td>' +
  120. '<td>b2</td>' +
  121. '</tr>' +
  122. '</tbody>' +
  123. '</table>' +
  124. '</figure>';
  125. editor.setData( data );
  126. expect( normalizeHtml( editor.getData() ) ).to.equal( expectedOutput );
  127. } );
  128. } );