ソースを参照

Tests: Created a test for the edge case handled in the previous commit.

Piotrek Koszuliński 9 年 前
コミット
69795b49e6
1 ファイル変更34 行追加1 行削除
  1. 34 1
      packages/ckeditor5-engine/tests/view/renderer.js

+ 34 - 1
packages/ckeditor5-engine/tests/view/renderer.js

@@ -640,7 +640,7 @@ describe( 'Renderer', () => {
 			renderer.markToSync( 'children', viewP2 );
 			renderer.render();
 
-			// Step 3: Check whether in the first paragrpah there's a <br> filler and that
+			// Step 3: Check whether in the first paragraph there's a <br> filler and that
 			// in the second one there are two <b> tags.
 			expect( domP.childNodes.length ).to.equal( 1 );
 			expect( isBlockFiller( domP.childNodes[ 0 ], BR_FILLER ) ).to.be.true;
@@ -650,6 +650,39 @@ describe( 'Renderer', () => {
 			expect( domP2.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'b' );
 		} );
 
+		// Test for an edge case in the _isSelectionInInlineFiller which can be triggered like
+		// in one of ckeditor/ckeditor5-typing#59 automated tests.
+		it( 'should not break when selection is moved to a new element, when filler exists', () => {
+			// Step 1: <p>bar<b>"FILLER{}"</b></p>
+			const { view: viewP, selection: newSelection } = parse( '<container:p>bar<attribute:b>[]</attribute:b></container:p>' );
+			viewRoot.appendChildren( viewP );
+			selection.setTo( newSelection );
+
+			renderer.markToSync( 'children', viewRoot );
+			renderer.render();
+
+			const domP = domRoot.childNodes[ 0 ];
+			expect( domP.childNodes.length ).to.equal( 2 );
+			expect( domP.childNodes[ 1 ].childNodes[ 0 ].data ).to.equal( INLINE_FILLER );
+
+			// Step 2: Move selection to a new attribute element and remove the previous one
+			viewP.removeChildren( 1 ); // Remove <b>.
+
+			const viewI = parse( '<attribute:i></attribute:i>' );
+			viewP.appendChildren( viewI );
+
+			selection.removeAllRanges();
+			selection.addRange( ViewRange.createFromParentsAndOffsets( viewI, 0, viewI, 0 ) );
+
+			renderer.markToSync( 'children', viewP );
+			renderer.render();
+
+			// Step 3: Check whether new filler was created in the <i> element.
+			expect( domP.childNodes.length ).to.equal( 2 );
+			expect( domP.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'i' );
+			expect( domP.childNodes[ 1 ].childNodes[ 0 ].data ).to.equal( INLINE_FILLER );
+		} );
+
 		it( 'should handle typing in empty block, do nothing if changes are already applied', () => {
 			const domSelection = document.getSelection();