浏览代码

Added integration test.

Szymon Kupś 7 年之前
父节点
当前提交
533c230e55
共有 1 个文件被更改,包括 38 次插入0 次删除
  1. 38 0
      packages/ckeditor5-undo/tests/undoediting-integration.js

+ 38 - 0
packages/ckeditor5-undo/tests/undoediting-integration.js

@@ -1048,6 +1048,44 @@ describe( 'UndoEditing integration', () => {
 		} );
 	} );
 
+	it( 'postfixers should not add another undo step when fixing undo changes', () => {
+		input( '<paragraph>[]</paragraph>' );
+		const paragraph = root.getChild( 0 );
+
+		// 1. Step - add text and marker to the paragraph.
+		model.change( writer => {
+			writer.appendText( 'foo', paragraph );
+			writer.setMarker( 'marker', Range.createIn( paragraph ) );
+		} );
+
+		// 2. Step - remove text from paragraph.
+		model.change( writer => {
+			writer.remove( Range.createIn( paragraph ) );
+		} );
+
+		// Register post fixer to remove marker from non-empty paragraph.
+		model.document.registerPostFixer( writer => {
+			const hasMarker = model.markers.has( 'marker' );
+			const isEmpty = paragraph.childCount === 0;
+
+			// Remove marker when paragraph is empty.
+			if ( hasMarker && !isEmpty ) {
+				writer.removeMarker( 'marker' );
+
+				return true;
+			}
+
+			return false;
+		} );
+
+		editor.execute( 'undo' );
+
+		// Check if postfixer changes are executed together with undo and there is no additional undo steps.
+		expect( model.markers.has( 'marker' ) ).to.be.false;
+		expect( editor.commands.get( 'undo' )._stack.length ).to.equal( 1 );
+		output( '<paragraph>foo[]</paragraph>' );
+	} );
+
 	function split( path ) {
 		setSelection( path.slice(), path.slice() );
 		editor.execute( 'enter' );