shiftenter-integration.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import ShiftEnter from '../src/shiftenter';
  9. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  11. describe( 'ShiftEnter integration', () => {
  12. let editor, model, div;
  13. const options = { withoutSelection: true };
  14. beforeEach( () => {
  15. div = document.createElement( 'div' );
  16. div.innerHTML = '<p>First line.<br>Second line.</p>';
  17. document.body.appendChild( div );
  18. return ClassicEditor.create( div, { plugins: [ Paragraph, ShiftEnter ] } )
  19. .then( newEditor => {
  20. editor = newEditor;
  21. model = editor.model;
  22. } );
  23. } );
  24. afterEach( () => {
  25. div.remove();
  26. return editor.destroy();
  27. } );
  28. it( 'loads correct data', () => {
  29. expect( getModelData( model, options ) ).to.equal( '<paragraph>First line.<softBreak></softBreak>Second line.</paragraph>' );
  30. expect( getViewData( editor.editing.view, options ) ).to.equal( '<p>First line.<br></br>Second line.</p>' );
  31. } );
  32. it( 'BLOCK_FILLER should be inserted after <br> in the paragraph', () => {
  33. setModelData( model, '<paragraph>[]</paragraph>' );
  34. editor.commands.get( 'shiftEnter' ).execute();
  35. expect( editor.getData( { trim: 'none' } ) ).to.equal( '<p><br>&nbsp;</p>' );
  36. expect( editor.ui.view.editable.element.innerHTML ).to.equal( '<p><br><br data-cke-filler="true"></p>' );
  37. } );
  38. } );