ckeditor5-692.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import MutationObserver from '../../src/view/observer/mutationobserver';
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor.js';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import { getData as getModelData } from '../../src/dev-utils/model';
  9. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold.js';
  10. import { getData as getViewData } from '../../src/dev-utils/view';
  11. import { isInlineFiller } from '../../src/view/filler';
  12. import Input from '@ckeditor/ckeditor5-typing/src/input';
  13. /* globals document */
  14. describe( 'Bug ckeditor5#692', () => {
  15. let editorElement, editor, mutationObserver, view, domEditor, root;
  16. beforeEach( () => {
  17. editorElement = document.createElement( 'div' );
  18. document.body.appendChild( editorElement );
  19. return ClassicTestEditor.create( editorElement, {
  20. plugins: [ Paragraph, Bold, Input ]
  21. } ).then( newEditor => {
  22. editor = newEditor;
  23. view = editor.editing.view;
  24. mutationObserver = view.getObserver( MutationObserver );
  25. domEditor = editor.ui.view.editableElement;
  26. root = editor.model.document.getRoot();
  27. } );
  28. } );
  29. afterEach( () => {
  30. document.body.removeChild( editorElement );
  31. return editor.destroy();
  32. } );
  33. describe( 'DomConverter', () => {
  34. // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 1.
  35. it( 'should handle space after inline filler at the end of container', () => {
  36. editor.setData( '<p>foo</p>' );
  37. const paragraph = root.getChild( 0 );
  38. // Put caret after at <p>foo[]</p>.
  39. editor.model.change( writer => {
  40. writer.setSelection( paragraph, 3 );
  41. } );
  42. // Create Bold attribute at the end of paragraph.
  43. editor.execute( 'bold' );
  44. expect( getModelData( editor.model ) ).to.equal( '<paragraph>foo<$text bold="true">[]</$text></paragraph>' );
  45. const domParagraph = domEditor.childNodes[ 0 ];
  46. const textNode = domParagraph.childNodes[ 1 ].childNodes[ 0 ];
  47. expect( isInlineFiller( textNode ) ).to.be.true;
  48. // Add space inside the strong's text node.
  49. textNode.data += ' ';
  50. mutationObserver.flush();
  51. expect( getModelData( editor.model ) ).to.equal( '<paragraph>foo<$text bold="true"> []</$text></paragraph>' );
  52. expect( getViewData( editor.editing.view ) ).to.equal( '<p>foo<strong> {}</strong></p>' );
  53. } );
  54. } );
  55. } );