Преглед изворни кода

Update the differ tests for "refresh" changes handling.

Maciej Gołaszewski пре 5 година
родитељ
комит
5507aab825

+ 3 - 0
packages/ckeditor5-engine/src/conversion/downcastdispatcher.js

@@ -149,6 +149,9 @@ export default class DowncastDispatcher {
 
 					return element.is( 'element', expectedElement ) ? element : element.findAncestor( expectedElement );
 				}
+				// TODO: lacking API - handle inner change of given event. Either by:
+				// - a) differ API (mark change as invalid)
+				// - b) skip given event.
 			} )
 			.filter( element => !!element );
 

+ 2 - 2
packages/ckeditor5-engine/tests/conversion/downcasthelpers.js

@@ -528,8 +528,8 @@ describe( 'DowncastHelpers', () => {
 				it( 'should convert element on removing slot', () => {
 					setModelData( model,
 						'<complex>' +
-						'<slot><paragraph>foo</paragraph></slot>' +
-						'<slot><paragraph>bar</paragraph></slot>' +
+							'<slot><paragraph>foo</paragraph></slot>' +
+							'<slot><paragraph>bar</paragraph></slot>' +
 						'</complex>' );
 
 					model.change( writer => {

+ 43 - 3
packages/ckeditor5-engine/tests/model/differ.js

@@ -1823,7 +1823,7 @@ describe( 'Differ', () => {
 			], true );
 		} );
 
-		it( 'an element with child removed', () => {
+		it( 'an element with child removed (refresh + remove)', () => {
 			const complex = root.getChild( 2 );
 
 			model.change( () => {
@@ -1836,7 +1836,34 @@ describe( 'Differ', () => {
 			} );
 		} );
 
-		it( 'an element with child added', () => {
+		it( 'an element with child removed (remove + refresh)', () => {
+			const complex = root.getChild( 2 );
+
+			model.change( () => {
+				remove( model.createPositionAt( complex, 1 ), 1 );
+				differ._pocRefreshItem( complex );
+
+				expectChanges( [
+					{ type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) },
+					{ type: 'remove', name: 'slot', length: 1, position: model.createPositionAfter( complex.getChild( 0 ) ) }
+				], false );
+			} );
+		} );
+
+		it( 'an element with child added (refresh + add)', () => {
+			const complex = root.getChild( 2 );
+
+			model.change( () => {
+				differ._pocRefreshItem( complex );
+				insert( new Element( 'slot' ), model.createPositionAt( complex, 2 ) );
+
+				expectChanges( [
+					{ type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
+				], true );
+			} );
+		} );
+
+		it( 'an element with child added (add + refresh)', () => {
 			const complex = root.getChild( 2 );
 
 			model.change( () => {
@@ -1849,7 +1876,20 @@ describe( 'Differ', () => {
 			} );
 		} );
 
-		it( 'an element with attribute set', () => {
+		it( 'an element with attribute set (refresh + attribute)', () => {
+			const complex = root.getChild( 2 );
+
+			model.change( () => {
+				differ._pocRefreshItem( complex );
+				attribute( model.createRangeOn( complex ), 'foo', undefined, true );
+
+				expectChanges( [
+					{ type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
+				], true );
+			} );
+		} );
+
+		it( 'an element with attribute set (attribute + refresh)', () => {
 			const complex = root.getChild( 2 );
 
 			model.change( () => {