integration.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 Heading from '../src/heading.js';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  9. import Image from '@ckeditor/ckeditor5-image/src/image';
  10. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
  11. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  12. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  13. describe( 'Heading integration', () => {
  14. let editor, doc, element;
  15. beforeEach( () => {
  16. element = document.createElement( 'div' );
  17. document.body.appendChild( element );
  18. return ClassicTestEditor.create( element, {
  19. plugins: [ Paragraph, Heading, Enter, Image, ImageCaption ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. doc = editor.document;
  24. } );
  25. } );
  26. afterEach( () => {
  27. element.remove();
  28. return editor.destroy();
  29. } );
  30. describe( 'with the enter key', () => {
  31. it( 'should make the "enter" command insert a default heading block if the selection ended at the end of a heading block', () => {
  32. editor.setData( '<h2>foobar</h2>' );
  33. doc.selection.collapse( doc.getRoot().getChild( 0 ), 'end' );
  34. editor.execute( 'enter' );
  35. expect( getModelData( doc ) ).to.equal( '<heading1>foobar</heading1><paragraph>[]</paragraph>' );
  36. } );
  37. it( 'should not alter the "enter" command if selection not ended at the end of a heading block', () => {
  38. // This test is to fill code coverage.
  39. editor.setData( '<h2>foobar</h2>' );
  40. doc.selection.collapse( doc.getRoot().getChild( 0 ), 3 );
  41. editor.execute( 'enter' );
  42. expect( getModelData( doc ) ).to.equal( '<heading1>foo</heading1><heading1>[]bar</heading1>' );
  43. } );
  44. } );
  45. describe( 'with the image feature', () => {
  46. // https://github.com/ckeditor/ckeditor5-heading/issues/73
  47. it( 'should not destroy the image when a selection converted to a heading', () => {
  48. setModelData( editor.document,
  49. '<paragraph>fo[o</paragraph>' +
  50. '<image src="foo.png">' +
  51. '<caption>xxx</caption>' +
  52. '</image>' +
  53. '<paragraph>b]ar</paragraph>'
  54. );
  55. editor.execute( 'heading1' );
  56. expect( getModelData( doc ) ).to.equal(
  57. '<heading1>fo[o</heading1>' +
  58. '<image src="foo.png">' +
  59. '<caption>xxx</caption>' +
  60. '</image>' +
  61. '<heading1>b]ar</heading1>'
  62. );
  63. } );
  64. } );
  65. } );