shiftenter-integration.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 LinkEditing from '@ckeditor/ckeditor5-link/src/linkediting';
  9. import Delete from '@ckeditor/ckeditor5-typing/src/delete';
  10. import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';
  11. import ShiftEnter from '../src/shiftenter';
  12. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  13. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  14. describe( 'ShiftEnter integration', () => {
  15. let editor, model, div;
  16. const options = { withoutSelection: true };
  17. beforeEach( () => {
  18. div = document.createElement( 'div' );
  19. div.innerHTML = '<p>First line.<br>Second line.</p>';
  20. document.body.appendChild( div );
  21. return ClassicEditor.create( div, { plugins: [ Paragraph, ShiftEnter, LinkEditing, Delete, BoldEditing ] } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. model = editor.model;
  25. } );
  26. } );
  27. afterEach( () => {
  28. div.remove();
  29. return editor.destroy();
  30. } );
  31. it( 'loads correct data', () => {
  32. expect( getModelData( model, options ) ).to.equal( '<paragraph>First line.<softBreak></softBreak>Second line.</paragraph>' );
  33. expect( getViewData( editor.editing.view, options ) ).to.equal( '<p>First line.<br></br>Second line.</p>' );
  34. } );
  35. it( 'BLOCK_FILLER should be inserted after <br> in the paragraph', () => {
  36. setModelData( model, '<paragraph>[]</paragraph>' );
  37. editor.execute( 'shiftEnter' );
  38. expect( editor.getData( { trim: 'none' } ) ).to.equal( '<p><br>&nbsp;</p>' );
  39. expect( editor.ui.view.editable.element.innerHTML ).to.equal( '<p><br><br data-cke-filler="true"></p>' );
  40. } );
  41. it( 'should not inherit text attributes before the "softBreak" element', () => {
  42. setModelData( model,
  43. '<paragraph>' +
  44. '<$text linkHref="foo" bold="true">Bolded link</$text>' +
  45. '<softBreak></softBreak>' +
  46. 'F[]' +
  47. '</paragraph>'
  48. );
  49. editor.execute( 'delete' );
  50. const selection = model.document.selection;
  51. expect( selection.hasAttribute( 'linkHref' ) ).to.equal( false );
  52. expect( selection.hasAttribute( 'bold' ) ).to.equal( false );
  53. } );
  54. } );