8
0

ckeditor5-692.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. 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, setData as setModelData } 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;
  16. beforeEach( () => {
  17. editorElement = document.createElement( 'div' );
  18. document.body.appendChild( editorElement );
  19. return ClassicTestEditor
  20. .create( editorElement, {
  21. plugins: [ Paragraph, Bold, Input ]
  22. } )
  23. .then( newEditor => {
  24. editor = newEditor;
  25. view = editor.editing.view;
  26. mutationObserver = view.getObserver( MutationObserver );
  27. domEditor = editor.ui.getEditableElement();
  28. } );
  29. } );
  30. afterEach( () => {
  31. document.body.removeChild( editorElement );
  32. return editor.destroy();
  33. } );
  34. describe( 'DomConverter', () => {
  35. // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 1.
  36. it( 'should handle space after inline filler at the end of container (scenario 1)', () => {
  37. setModelData( editor.model, '<paragraph>foo[]</paragraph>' );
  38. // Create Bold attribute at the end of paragraph.
  39. editor.execute( 'bold' );
  40. expect( getModelData( editor.model ) ).to.equal( '<paragraph>foo<$text bold="true">[]</$text></paragraph>' );
  41. const domParagraph = domEditor.childNodes[ 0 ];
  42. const textNode = domParagraph.childNodes[ 1 ].childNodes[ 0 ];
  43. expect( isInlineFiller( textNode ) ).to.be.true;
  44. // Add space inside the strong's text node.
  45. textNode.data += ' ';
  46. mutationObserver.flush();
  47. expect( getModelData( editor.model ) ).to.equal( '<paragraph>foo<$text bold="true"> []</$text></paragraph>' );
  48. expect( getViewData( editor.editing.view ) ).to.equal( '<p>foo<strong> {}</strong></p>' );
  49. } );
  50. // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 2.
  51. it( 'should handle space after inline filler at the end of container (scenario 2)', () => {
  52. setModelData( editor.model, '<paragraph>[]foo</paragraph>' );
  53. // Create Bold attribute at the end of paragraph.
  54. editor.execute( 'bold' );
  55. expect( getModelData( editor.model ) ).to.equal( '<paragraph><$text bold="true">[]</$text>foo</paragraph>' );
  56. const domParagraph = domEditor.childNodes[ 0 ];
  57. const textNode = domParagraph.childNodes[ 0 ].childNodes[ 0 ];
  58. expect( isInlineFiller( textNode ) ).to.be.true;
  59. // Add space inside the strong's text node.
  60. textNode.data += ' ';
  61. mutationObserver.flush();
  62. expect( getModelData( editor.model ) ).to.equal( '<paragraph><$text bold="true"> []</$text>foo</paragraph>' );
  63. expect( getViewData( editor.editing.view ) ).to.equal( '<p><strong> {}</strong>foo</p>' );
  64. } );
  65. } );
  66. } );