From 4d86bf6e06bba0062f4586708614173a5f71b71a Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Tue, 6 Feb 2018 17:11:51 +0100 Subject: [PATCH 01/11] Fixed processing text data. --- src/view/domconverter.js | 11 +++++++---- src/view/observer/mutationobserver.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/view/domconverter.js b/src/view/domconverter.js index f6d09e882..a90644367 100644 --- a/src/view/domconverter.js +++ b/src/view/domconverter.js @@ -7,7 +7,7 @@ * @module engine/view/domconverter */ -/* globals document, Node, NodeFilter */ +/* globals document, Node, NodeFilter, Text */ import ViewText from './text'; import ViewElement from './element'; @@ -956,10 +956,10 @@ export default class DomConverter { * @private */ _processDataFromDomText( node ) { - let data = getDataWithoutFiller( node ); + let data = node.data; if ( _hasDomParentOfType( node, this.preElements ) ) { - return data; + return getDataWithoutFiller( node ); } // Change all consecutive whitespace characters (from the [ \n\t\r] set – @@ -978,9 +978,12 @@ export default class DomConverter { } // If next text node does not exist remove space character from the end of this text node. - if ( !nextNode ) { + if ( !nextNode && !startsWithFiller( node ) ) { data = data.replace( / $/, '' ); } + + data = getDataWithoutFiller( new Text( data ) ); + // At this point we should have removed all whitespaces from DOM text data. // Now we have to change   chars, that were in DOM text data because of rendering reasons, to spaces. diff --git a/src/view/observer/mutationobserver.js b/src/view/observer/mutationobserver.js index 620acc7a0..7b9881762 100644 --- a/src/view/observer/mutationobserver.js +++ b/src/view/observer/mutationobserver.js @@ -204,8 +204,8 @@ export default class MutationObserver extends Observer { } for ( const viewElement of mutatedElements ) { - const domElement = domConverter.mapViewToDom( viewElement ); const viewChildren = Array.from( viewElement.getChildren() ); + const domElement = domConverter.mapViewToDom( viewElement ); const newViewChildren = Array.from( domConverter.domChildrenToView( domElement ) ); // It may happen that as a result of many changes (sth was inserted and then removed), From 3cf3a54afeaf9eb33b1210ac842a4f15c50d1d1c Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Mon, 12 Feb 2018 11:26:52 +0100 Subject: [PATCH 02/11] Added comment to link FF issue. --- src/view/domconverter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/view/domconverter.js b/src/view/domconverter.js index a90644367..6dac7635a 100644 --- a/src/view/domconverter.js +++ b/src/view/domconverter.js @@ -982,6 +982,8 @@ export default class DomConverter { data = data.replace( / $/, '' ); } + // Firefox inserts whitespace and
instead of non-breaking space. To prevent normal space from + // being removed inline filler is removed after first string replaces. See ckeditor5#692. data = getDataWithoutFiller( new Text( data ) ); // At this point we should have removed all whitespaces from DOM text data. From 0688c26a4bf5b535563c1a1adcaa6c6b459fc029 Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Mon, 12 Feb 2018 13:59:53 +0100 Subject: [PATCH 03/11] Added tests for coverting text with inline filler. --- tests/view/domconverter/dom-to-view.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/view/domconverter/dom-to-view.js b/tests/view/domconverter/dom-to-view.js index a30194787..558cde1ca 100644 --- a/tests/view/domconverter/dom-to-view.js +++ b/tests/view/domconverter/dom-to-view.js @@ -525,6 +525,30 @@ describe( 'DomConverter', () => { // See also whitespace-handling-integration.js. // } ); + + describe( 'clearing auto filler', () => { + it( 'should remove inline filler when converting dom to view', () => { + const text = document.createTextNode( INLINE_FILLER + 'foo' ); + const view = converter.domToView( text ); + + expect( view.data ).to.equal( 'foo' ); + } ); + + // See https://github.com/ckeditor/ckeditor5/issues/692. + it( 'should not remove space after inline filler if previous node nor next node does not exist', () => { + const text = document.createTextNode( INLINE_FILLER + ' ' ); + const view = converter.domToView( text ); + + expect( view.data ).to.equal( ' ' ); + } ); + + it( 'should convert non breaking space to normal space after inline filler', () => { + const text = document.createTextNode( INLINE_FILLER + '\u00A0' ); + const view = converter.domToView( text ); + + expect( view.data ).to.equal( ' ' ); + } ); + } ); } ); describe( 'domChildrenToView', () => { From 30da0045cea1cbb79f61a336da2737ba8a16a0ee Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Wed, 14 Feb 2018 13:10:20 +0100 Subject: [PATCH 04/11] Added 3 test for 3 scenarios that fix ckeditor5#692. --- tests/view/observer/mutationobserver.js | 62 ++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/tests/view/observer/mutationobserver.js b/tests/view/observer/mutationobserver.js index d7aef2bfa..3b3498d0b 100644 --- a/tests/view/observer/mutationobserver.js +++ b/tests/view/observer/mutationobserver.js @@ -269,6 +269,66 @@ describe( 'MutationObserver', () => { expect( lastMutations[ 0 ].newText ).to.equal( 'xy' ); } ); + // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 1. + it( 'should handle space after inline filler at the end of container', () => { + const { view, selection } = parse( 'foo[]' ); + + viewRoot.appendChildren( view ); + viewDocument.selection.setTo( selection ); + + viewDocument.render(); + + const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 1 ].childNodes[ 0 ]; + + inlineFiller.data += ' '; + + mutationObserver.flush(); + + expect( lastMutations.length ).to.equal( 1 ); + expect( lastMutations[ 0 ].type ).to.equal( 'children' ); + expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent ); + } ); + + // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 3. + it( 'should handle space after inline filler at the end of container #2', () => { + const { view, selection } = parse( 'foobar[]' ); + + viewRoot.appendChildren( view ); + viewDocument.selection.setTo( selection ); + + viewDocument.render(); + + const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 2 ]; + + inlineFiller.data += ' '; + + mutationObserver.flush(); + + expect( lastMutations.length ).to.equal( 1 ); + expect( lastMutations[ 0 ].type ).to.equal( 'children' ); + expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent ); + } ); + + // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 2. + it( 'should handle space after inline filler at the beginning of container', () => { + const { view, selection } = parse( '[]foo' ); + + viewRoot.appendChildren( view ); + viewDocument.selection.setTo( selection ); + + viewDocument.render(); + + const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 0 ].childNodes[ 0 ]; + + inlineFiller.data += ' '; + + mutationObserver.flush(); + + expect( lastMutations.length ).to.equal( 1 ); + expect( lastMutations[ 0 ].type ).to.equal( 'children' ); + expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent ); + } ); + it( 'should have no block filler in mutation', () => { viewRoot.appendChildren( parse( '' ) ); @@ -359,7 +419,7 @@ describe( 'MutationObserver', () => { mutationObserver.flush(); - // There was onlu P2 change. P1 must be ignored. + // There was only P2 change. P1 must be ignored. const viewP2 = viewRoot.getChild( 1 ); expect( lastMutations.length ).to.equal( 1 ); expect( lastMutations[ 0 ].node ).to.equal( viewP2 ); From 5e774cd1a368009e7f2a1c1354f9870ccc468e8f Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Mon, 26 Feb 2018 12:55:21 +0100 Subject: [PATCH 05/11] Docs: Expanded inline comment. --- src/view/domconverter.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/view/domconverter.js b/src/view/domconverter.js index 6dac7635a..c9861f77f 100644 --- a/src/view/domconverter.js +++ b/src/view/domconverter.js @@ -982,8 +982,10 @@ export default class DomConverter { data = data.replace( / $/, '' ); } - // Firefox inserts whitespace and
instead of non-breaking space. To prevent normal space from - // being removed inline filler is removed after first string replaces. See ckeditor5#692. + // At the beginning and end of a block element, Firefox inserts normal space +
instead of non-breaking space. + // This means that the text node starts/end with normal space instead of non-breaking space. + // This causes a problem because the normal space would be removed in `.replace` calls above. To prevent that, + // the inline filler is removed only after the data is initially processed (by the `.replace` above). See ckeditor5#692. data = getDataWithoutFiller( new Text( data ) ); // At this point we should have removed all whitespaces from DOM text data. From c48c8ea160c58851eba5e1cde4f86f1c8fa6c8a9 Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Thu, 1 Mar 2018 11:45:48 +0100 Subject: [PATCH 06/11] Tests: Added more accurate assertions. --- src/view/observer/mutationobserver.js | 2 +- tests/view/observer/mutationobserver.js | 58 ++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/view/observer/mutationobserver.js b/src/view/observer/mutationobserver.js index 7b9881762..620acc7a0 100644 --- a/src/view/observer/mutationobserver.js +++ b/src/view/observer/mutationobserver.js @@ -204,8 +204,8 @@ export default class MutationObserver extends Observer { } for ( const viewElement of mutatedElements ) { - const viewChildren = Array.from( viewElement.getChildren() ); const domElement = domConverter.mapViewToDom( viewElement ); + const viewChildren = Array.from( viewElement.getChildren() ); const newViewChildren = Array.from( domConverter.domChildrenToView( domElement ) ); // It may happen that as a result of many changes (sth was inserted and then removed), diff --git a/tests/view/observer/mutationobserver.js b/tests/view/observer/mutationobserver.js index 3b3498d0b..3d35361f5 100644 --- a/tests/view/observer/mutationobserver.js +++ b/tests/view/observer/mutationobserver.js @@ -271,14 +271,21 @@ describe( 'MutationObserver', () => { // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 1. it( 'should handle space after inline filler at the end of container', () => { - const { view, selection } = parse( 'foo[]' ); + const { view, selection } = parse( + '' + + 'foo' + + '[]' + + '' + ); viewRoot.appendChildren( view ); viewDocument.selection.setTo( selection ); viewDocument.render(); - const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 1 ].childNodes[ 0 ]; + // Appended container is third in the tree. + const container = domEditor.childNodes[ 2 ]; + const inlineFiller = container.childNodes[ 1 ].childNodes[ 0 ]; inlineFiller.data += ' '; @@ -286,19 +293,31 @@ describe( 'MutationObserver', () => { expect( lastMutations.length ).to.equal( 1 ); expect( lastMutations[ 0 ].type ).to.equal( 'children' ); + expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 0 ); + expect( lastMutations[ 0 ].newChildren.length ).to.equal( 1 ); + expect( lastMutations[ 0 ].newChildren[ 0 ].is( 'text' ) ).to.be.true; + expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( ' ' ); expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent ); } ); // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 3. it( 'should handle space after inline filler at the end of container #2', () => { - const { view, selection } = parse( 'foobar[]' ); + const { view, selection } = parse( + '' + + 'foo' + + 'bar' + + '[]' + + '' + ); viewRoot.appendChildren( view ); viewDocument.selection.setTo( selection ); viewDocument.render(); - const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 2 ]; + // Appended container is third in the tree. + const container = domEditor.childNodes[ 2 ]; + const inlineFiller = container.childNodes[ 2 ]; inlineFiller.data += ' '; @@ -306,19 +325,42 @@ describe( 'MutationObserver', () => { expect( lastMutations.length ).to.equal( 1 ); expect( lastMutations[ 0 ].type ).to.equal( 'children' ); + expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 2 ); + expect( lastMutations[ 0 ].newChildren.length ).to.equal( 3 ); + + // Foo and attribute is removed and reinserted. + expect( lastMutations[ 0 ].oldChildren[ 0 ].is( 'text' ) ).to.be.true; + expect( lastMutations[ 0 ].oldChildren[ 0 ].data ).to.equal( 'foo' ); + expect( lastMutations[ 0 ].newChildren[ 0 ].is( 'text' ) ).to.be.true; + expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( 'foo' ); + + expect( lastMutations[ 0 ].oldChildren[ 1 ].is( 'attributeElement' ) ).to.be.true; + expect( lastMutations[ 0 ].oldChildren[ 1 ].name ).to.equal( 'b' ); + expect( lastMutations[ 0 ].newChildren[ 1 ].is( 'attributeElement' ) ).to.be.true; + expect( lastMutations[ 0 ].newChildren[ 1 ].name ).to.equal( 'b' ); + + expect( lastMutations[ 0 ].newChildren[ 2 ].is( 'text' ) ).to.be.true; + expect( lastMutations[ 0 ].newChildren[ 2 ].data ).to.equal( ' ' ); expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent ); } ); // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 2. it( 'should handle space after inline filler at the beginning of container', () => { - const { view, selection } = parse( '[]foo' ); + const { view, selection } = parse( + '' + + '[]' + + 'foo' + + '' + ); viewRoot.appendChildren( view ); viewDocument.selection.setTo( selection ); viewDocument.render(); - const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 0 ].childNodes[ 0 ]; + // Appended container is third in the tree. + const container = domEditor.childNodes[ 2 ]; + const inlineFiller = container.childNodes[ 0 ].childNodes[ 0 ]; inlineFiller.data += ' '; @@ -326,6 +368,10 @@ describe( 'MutationObserver', () => { expect( lastMutations.length ).to.equal( 1 ); expect( lastMutations[ 0 ].type ).to.equal( 'children' ); + expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 0 ); + expect( lastMutations[ 0 ].newChildren.length ).to.equal( 1 ); + expect( lastMutations[ 0 ].newChildren[ 0 ].is( 'text' ) ).to.be.true; + expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( ' ' ); expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent ); } ); From 3cd535944fa61d0f4818c3fab71fbb8c061d6e86 Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Thu, 1 Mar 2018 11:48:54 +0100 Subject: [PATCH 07/11] Aligned code to recent changes that landed on master. --- tests/view/observer/mutationobserver.js | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/view/observer/mutationobserver.js b/tests/view/observer/mutationobserver.js index 3d35361f5..16dc59eab 100644 --- a/tests/view/observer/mutationobserver.js +++ b/tests/view/observer/mutationobserver.js @@ -271,17 +271,17 @@ describe( 'MutationObserver', () => { // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 1. it( 'should handle space after inline filler at the end of container', () => { - const { view, selection } = parse( + const { view: viewContainer, selection } = parse( '' + 'foo' + '[]' + '' ); - viewRoot.appendChildren( view ); - viewDocument.selection.setTo( selection ); - - viewDocument.render(); + view.change( writer => { + viewRoot.appendChildren( viewContainer ); + writer.setSelection( selection ); + } ); // Appended container is third in the tree. const container = domEditor.childNodes[ 2 ]; @@ -302,7 +302,7 @@ describe( 'MutationObserver', () => { // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 3. it( 'should handle space after inline filler at the end of container #2', () => { - const { view, selection } = parse( + const { view: viewContainer, selection } = parse( '' + 'foo' + 'bar' + @@ -310,10 +310,10 @@ describe( 'MutationObserver', () => { '' ); - viewRoot.appendChildren( view ); - viewDocument.selection.setTo( selection ); - - viewDocument.render(); + view.change( writer => { + viewRoot.appendChildren( viewContainer ); + writer.setSelection( selection ); + } ); // Appended container is third in the tree. const container = domEditor.childNodes[ 2 ]; @@ -346,17 +346,17 @@ describe( 'MutationObserver', () => { // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 2. it( 'should handle space after inline filler at the beginning of container', () => { - const { view, selection } = parse( + const { view: viewContainer, selection } = parse( '' + '[]' + 'foo' + '' ); - viewRoot.appendChildren( view ); - viewDocument.selection.setTo( selection ); - - viewDocument.render(); + view.change( writer => { + viewRoot.appendChildren( viewContainer ); + writer.setSelection( selection ); + } ); // Appended container is third in the tree. const container = domEditor.childNodes[ 2 ]; From 3acdca02916f8346d56761a8f14e8e3033490a8f Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Wed, 7 Mar 2018 16:39:14 +0100 Subject: [PATCH 08/11] Added integration test. --- tests/tickets/ckeditor5-692.js | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/tickets/ckeditor5-692.js diff --git a/tests/tickets/ckeditor5-692.js b/tests/tickets/ckeditor5-692.js new file mode 100644 index 000000000..a4d7baf90 --- /dev/null +++ b/tests/tickets/ckeditor5-692.js @@ -0,0 +1,71 @@ +/** + * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md. + */ + +import MutationObserver from '../../src/view/observer/mutationobserver'; +import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor.js'; +import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; +import { getData as getModelData } from '../../src/dev-utils/model'; +import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold.js'; +import { getData as getViewData } from '../../src/dev-utils/view'; +import { isInlineFiller } from '../../src/view/filler'; +import Input from '@ckeditor/ckeditor5-typing/src/input'; + +/* globals document */ + +describe( 'Bug ckeditor5#692', () => { + let editorElement, editor, mutationObserver, view, domEditor, root; + + beforeEach( () => { + editorElement = document.createElement( 'div' ); + document.body.appendChild( editorElement ); + + return ClassicTestEditor.create( editorElement, { + plugins: [ Paragraph, Bold, Input ] + } ).then( newEditor => { + editor = newEditor; + view = editor.editing.view; + mutationObserver = view.getObserver( MutationObserver ); + domEditor = editor.ui.view.editableElement; + root = editor.model.document.getRoot(); + } ); + } ); + + afterEach( () => { + document.body.removeChild( editorElement ); + + return editor.destroy(); + } ); + + describe( 'DomConverter', () => { + // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 1. + it( 'should handle space after inline filler at the end of container', () => { + editor.setData( '

foo

' ); + + const paragraph = root.getChild( 0 ); + + // Put caret after at

foo[]

. + editor.model.change( writer => { + writer.setSelection( paragraph, 3 ); + } ); + + // Create Bold attribute at the end of paragraph. + editor.execute( 'bold' ); + + expect( getModelData( editor.model ) ).to.equal( 'foo<$text bold="true">[]' ); + + const domParagraph = domEditor.childNodes[ 0 ]; + const textNode = domParagraph.childNodes[ 1 ].childNodes[ 0 ]; + + expect( isInlineFiller( textNode ) ).to.be.true; + + // Add space inside the strong's text node. + textNode.data += ' '; + mutationObserver.flush(); + + expect( getModelData( editor.model ) ).to.equal( 'foo<$text bold="true"> []' ); + expect( getViewData( editor.editing.view ) ).to.equal( '

foo {}

' ); + } ); + } ); +} ); From 3764463cbf2211f9668c60c215555f991d9d79b2 Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Wed, 7 Mar 2018 17:06:20 +0100 Subject: [PATCH 09/11] Added 2. integration test. --- tests/tickets/ckeditor5-692.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/tickets/ckeditor5-692.js b/tests/tickets/ckeditor5-692.js index a4d7baf90..21384bd0b 100644 --- a/tests/tickets/ckeditor5-692.js +++ b/tests/tickets/ckeditor5-692.js @@ -67,5 +67,34 @@ describe( 'Bug ckeditor5#692', () => { expect( getModelData( editor.model ) ).to.equal( 'foo<$text bold="true"> []' ); expect( getViewData( editor.editing.view ) ).to.equal( '

foo {}

' ); } ); + + // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 2. + it( 'should handle space after inline filler at the end of container', () => { + editor.setData( '

foo

' ); + + const paragraph = root.getChild( 0 ); + + // Put caret after at

[]foo

. + editor.model.change( writer => { + writer.setSelection( paragraph, 0 ); + } ); + + // Create Bold attribute at the end of paragraph. + editor.execute( 'bold' ); + + expect( getModelData( editor.model ) ).to.equal( '<$text bold="true">[]foo' ); + + const domParagraph = domEditor.childNodes[ 0 ]; + const textNode = domParagraph.childNodes[ 0 ].childNodes[ 0 ]; + + expect( isInlineFiller( textNode ) ).to.be.true; + + // Add space inside the strong's text node. + textNode.data += ' '; + mutationObserver.flush(); + + expect( getModelData( editor.model ) ).to.equal( '<$text bold="true"> []foo' ); + expect( getViewData( editor.editing.view ) ).to.equal( '

{}foo

' ); + } ); } ); } ); From 929e6499f573155b8804b485c2ead84fd8a394b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Wed, 7 Mar 2018 21:02:15 +0100 Subject: [PATCH 10/11] Fixed code style. --- tests/tickets/ckeditor5-692.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/tickets/ckeditor5-692.js b/tests/tickets/ckeditor5-692.js index 21384bd0b..83fdf9cc4 100644 --- a/tests/tickets/ckeditor5-692.js +++ b/tests/tickets/ckeditor5-692.js @@ -21,15 +21,17 @@ describe( 'Bug ckeditor5#692', () => { editorElement = document.createElement( 'div' ); document.body.appendChild( editorElement ); - return ClassicTestEditor.create( editorElement, { - plugins: [ Paragraph, Bold, Input ] - } ).then( newEditor => { - editor = newEditor; - view = editor.editing.view; - mutationObserver = view.getObserver( MutationObserver ); - domEditor = editor.ui.view.editableElement; - root = editor.model.document.getRoot(); - } ); + return ClassicTestEditor + .create( editorElement, { + plugins: [ Paragraph, Bold, Input ] + } ) + .then( newEditor => { + editor = newEditor; + view = editor.editing.view; + mutationObserver = view.getObserver( MutationObserver ); + domEditor = editor.ui.view.editableElement; + root = editor.model.document.getRoot(); + } ); } ); afterEach( () => { From ed99ed17ec489401ba5d5dc7fe30380814a2ac1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Wed, 7 Mar 2018 21:07:40 +0100 Subject: [PATCH 11/11] Simplified the tests. --- tests/tickets/ckeditor5-692.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/tests/tickets/ckeditor5-692.js b/tests/tickets/ckeditor5-692.js index 83fdf9cc4..b5a3ae32c 100644 --- a/tests/tickets/ckeditor5-692.js +++ b/tests/tickets/ckeditor5-692.js @@ -6,7 +6,7 @@ import MutationObserver from '../../src/view/observer/mutationobserver'; import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor.js'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; -import { getData as getModelData } from '../../src/dev-utils/model'; +import { getData as getModelData, setData as setModelData } from '../../src/dev-utils/model'; import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold.js'; import { getData as getViewData } from '../../src/dev-utils/view'; import { isInlineFiller } from '../../src/view/filler'; @@ -15,7 +15,7 @@ import Input from '@ckeditor/ckeditor5-typing/src/input'; /* globals document */ describe( 'Bug ckeditor5#692', () => { - let editorElement, editor, mutationObserver, view, domEditor, root; + let editorElement, editor, mutationObserver, view, domEditor; beforeEach( () => { editorElement = document.createElement( 'div' ); @@ -30,7 +30,6 @@ describe( 'Bug ckeditor5#692', () => { view = editor.editing.view; mutationObserver = view.getObserver( MutationObserver ); domEditor = editor.ui.view.editableElement; - root = editor.model.document.getRoot(); } ); } ); @@ -43,14 +42,7 @@ describe( 'Bug ckeditor5#692', () => { describe( 'DomConverter', () => { // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 1. it( 'should handle space after inline filler at the end of container', () => { - editor.setData( '

foo

' ); - - const paragraph = root.getChild( 0 ); - - // Put caret after at

foo[]

. - editor.model.change( writer => { - writer.setSelection( paragraph, 3 ); - } ); + setModelData( editor.model, 'foo[]' ); // Create Bold attribute at the end of paragraph. editor.execute( 'bold' ); @@ -72,14 +64,7 @@ describe( 'Bug ckeditor5#692', () => { // https://github.com/ckeditor/ckeditor5/issues/692 Scenario 2. it( 'should handle space after inline filler at the end of container', () => { - editor.setData( '

foo

' ); - - const paragraph = root.getChild( 0 ); - - // Put caret after at

[]foo

. - editor.model.change( writer => { - writer.setSelection( paragraph, 0 ); - } ); + setModelData( editor.model, '[]foo' ); // Create Bold attribute at the end of paragraph. editor.execute( 'bold' );