浏览代码

Added undo/redo integration test for image caption.

Szymon Kupś 8 年之前
父节点
当前提交
8cb62b98bb
共有 1 个文件被更改,包括 35 次插入1 次删除
  1. 35 1
      packages/ckeditor5-image/tests/imagecaption/imagecaptionengine.js

+ 35 - 1
packages/ckeditor5-image/tests/imagecaption/imagecaptionengine.js

@@ -12,6 +12,7 @@ import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
 import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
 import ImageCaptionEngine from '../../src/imagecaption/imagecaptionengine';
 import ImageEngine from '../../src/image/imageengine';
+import UndoEngine from '@ckeditor/ckeditor5-undo/src/undoengine';
 import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
@@ -22,7 +23,7 @@ describe( 'ImageCaptionEngine', () => {
 
 	beforeEach( () => {
 		return VirtualTestEditor.create( {
-			plugins: [ ImageCaptionEngine, ImageEngine ]
+			plugins: [ ImageCaptionEngine, ImageEngine, UndoEngine ]
 		} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -317,5 +318,38 @@ describe( 'ImageCaptionEngine', () => {
 				'</figure>]'
 			);
 		} );
+
+		describe( 'undo/redo integration', () => {
+			it( 'should create view element after redo', () => {
+				setModelData( document, '<image src=""><caption>[foo bar baz]</caption></image>' );
+
+				const modelRoot = document.getRoot();
+				const modelImage = modelRoot.getChild( 0 );
+				const modelCaption = modelImage.getChild( 0 );
+
+				// Remove text and selection from caption.
+				document.enqueueChanges( () => {
+					const batch = document.batch();
+
+					batch.remove( ModelRange.createIn( modelCaption ) );
+					document.selection.removeAllRanges();
+				} );
+
+				// Check if there is no figcaption in the view.
+				expect( getViewData( viewDocument ) ).to.equal(
+					'[]<figure class="image ck-widget" contenteditable="false"><img src=""></img></figure>'
+				);
+
+				editor.execute( 'undo' );
+
+				// Check if figcaption is back with contents.
+				expect( getViewData( viewDocument ) ).to.equal(
+					'<figure class="image ck-widget" contenteditable="false">' +
+						'<img src=""></img>' +
+						'<figcaption contenteditable="true">{foo bar baz}</figcaption>' +
+					'</figure>'
+				);
+			} );
+		} );
 	} );
 } );