articlepluginset.js 4.9 KB

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