article.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import ArticlePreset from '../src/article';
  7. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  8. import EssentialsPreset from '../src/essentials';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  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 normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
  20. describe( 'Article preset', () => {
  21. let editor, editorElement;
  22. beforeEach( () => {
  23. editorElement = document.createElement( 'div' );
  24. document.body.appendChild( editorElement );
  25. return ClassicTestEditor.create( editorElement, { plugins: [ ArticlePreset ] } )
  26. .then( newEditor => {
  27. editor = newEditor;
  28. } );
  29. } );
  30. afterEach( () => {
  31. editor.destroy();
  32. editorElement.remove();
  33. } );
  34. it( 'should be loaded', () => {
  35. expect( editor.plugins.get( ArticlePreset ) ).to.be.instanceOf( ArticlePreset );
  36. } );
  37. it( 'should load all its dependencies', () => {
  38. expect( editor.plugins.get( EssentialsPreset ) ).to.be.instanceOf( EssentialsPreset );
  39. expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
  40. expect( editor.plugins.get( Bold ) ).to.be.instanceOf( Bold );
  41. expect( editor.plugins.get( Heading ) ).to.be.instanceOf( Heading );
  42. expect( editor.plugins.get( Image ) ).to.be.instanceOf( Image );
  43. expect( editor.plugins.get( ImageCaption ) ).to.be.instanceOf( ImageCaption );
  44. expect( editor.plugins.get( ImageStyle ) ).to.be.instanceOf( ImageStyle );
  45. expect( editor.plugins.get( ImageToolbar ) ).to.be.instanceOf( ImageToolbar );
  46. expect( editor.plugins.get( Italic ) ).to.be.instanceOf( Italic );
  47. expect( editor.plugins.get( Link ) ).to.be.instanceOf( Link );
  48. expect( editor.plugins.get( List ) ).to.be.instanceOf( List );
  49. } );
  50. it( 'loads data', () => {
  51. const data =
  52. '<h2>Heading 1</h2>' +
  53. '<p>Paragraph</p>' +
  54. '<p><strong>Bold</strong> <i>Italic</i> <a href="foo">Link</a></p>' +
  55. '<ul>' +
  56. '<li>UL List item 1</li>' +
  57. '<li>UL List item 2</li>' +
  58. '</ul>' +
  59. '<ol>' +
  60. '<li>OL List item 1</li>' +
  61. '<li>OL List item 2</li>' +
  62. '</ol>' +
  63. '<figure class="image image-style-side">' +
  64. '<img alt="bar" src="foo">' +
  65. '<figcaption>Caption</figcaption>' +
  66. '</figure>' +
  67. '<blockquote>' +
  68. '<p>Quote</p>' +
  69. '<ul><li>Quoted UL List item 1</li></ul>' +
  70. '</blockquote>';
  71. // Can't use data twice due to https://github.com/ckeditor/ckeditor5-utils/issues/128.
  72. const expectedOutput =
  73. '<h2>Heading 1</h2>' +
  74. '<p>Paragraph</p>' +
  75. '<p><strong>Bold</strong> <i>Italic</i> <a href="foo">Link</a></p>' +
  76. '<ul>' +
  77. '<li>UL List item 1</li>' +
  78. '<li>UL List item 2</li>' +
  79. '</ul>' +
  80. '<ol>' +
  81. '<li>OL List item 1</li>' +
  82. '<li>OL List item 2</li>' +
  83. '</ol>' +
  84. '<figure class="image image-style-side">' +
  85. '<img alt="bar" src="foo"></img>' +
  86. '<figcaption>Caption</figcaption>' +
  87. '</figure>' +
  88. '<blockquote>' +
  89. '<p>Quote</p>' +
  90. '<ul><li>Quoted UL List item 1</li></ul>' +
  91. '</blockquote>';
  92. editor.setData( data );
  93. expect( normalizeHtml( editor.getData() ) ).to.equal( expectedOutput );
  94. } );
  95. } );