8
0
Просмотр исходного кода

Tests: Moved undo integration tests from HeadingCommand to the proper integration file.

Aleksander Nowodzinski 8 лет назад
Родитель
Сommit
ab1d8e2a40

+ 2 - 9
packages/ckeditor5-heading/tests/headingcommand.js

@@ -159,15 +159,10 @@ describe( 'HeadingCommand', () => {
 			}
 
 			it( 'does nothing when executed with already applied option', () => {
-				const command = commands.heading1;
-				const batch = document.batch();
-
 				setData( document, '<heading1>foo[]bar</heading1>' );
 
-				command.execute( { batch } );
-
+				commands.heading1.execute();
 				expect( getData( document ) ).to.equal( '<heading1>foo[]bar</heading1>' );
-				expect( batch.deltas ).to.be.empty;
 			} );
 
 			it( 'converts topmost blocks', () => {
@@ -210,13 +205,11 @@ describe( 'HeadingCommand', () => {
 
 			it( 'does nothing to the elements with same option (#1)', () => {
 				setData( document, '<heading1>[foo</heading1><heading1>bar]</heading1>' );
-				const batch = document.batch();
-				commands.heading1.execute( { batch } );
+				commands.heading1.execute();
 
 				expect( getData( document ) ).to.equal(
 					'<heading1>[foo</heading1><heading1>bar]</heading1>'
 				);
-				expect( batch.deltas ).to.be.empty;
 			} );
 
 			it( 'does nothing to the elements with same option (#2)', () => {

+ 22 - 1
packages/ckeditor5-heading/tests/integration.js

@@ -11,6 +11,7 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import Enter from '@ckeditor/ckeditor5-enter/src/enter';
 import Image from '@ckeditor/ckeditor5-image/src/image';
 import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
+import Undo from '@ckeditor/ckeditor5-undo/src/undo';
 
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
@@ -23,7 +24,7 @@ describe( 'Heading integration', () => {
 		document.body.appendChild( element );
 
 		return ClassicTestEditor.create( element, {
-			plugins: [ Paragraph, Heading, Enter, Image, ImageCaption ]
+			plugins: [ Paragraph, Heading, Enter, Image, ImageCaption, Undo ]
 		} )
 		.then( newEditor => {
 			editor = newEditor;
@@ -80,4 +81,24 @@ describe( 'Heading integration', () => {
 			);
 		} );
 	} );
+
+	describe( 'with the undo feature', () => {
+		it( 'does not create undo steps when applied to an existing heading (collapsed selection)', () => {
+			setModelData( editor.document, '<heading1>foo[]bar</heading1>' );
+
+			editor.execute( 'heading1' );
+			expect( getModelData( editor.document ) ).to.equal( '<heading1>foo[]bar</heading1>' );
+
+			expect( editor.commands.get( 'undo' ).isEnabled ).to.be.false;
+		} );
+
+		it( 'does not create undo steps when applied to an existing heading (non–collapsed selection)', () => {
+			setModelData( editor.document, '<heading1>[foo</heading1><heading1>bar]</heading1>' );
+
+			editor.execute( 'heading1' );
+			expect( getModelData( editor.document ) ).to.equal( '<heading1>[foo</heading1><heading1>bar]</heading1>' );
+
+			expect( editor.commands.get( 'undo' ).isEnabled ).to.be.false;
+		} );
+	} );
 } );