瀏覽代碼

Tests: Add tests for wrong style definitions.

Maciej Gołaszewski 8 年之前
父節點
當前提交
b6623e4923

+ 3 - 1
packages/ckeditor5-alignment/src/alignmentediting.js

@@ -14,6 +14,8 @@ import AlignmentCommand from './alignmentcommand';
 import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
 import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
 
+const alignmentTypes = [ 'left', 'right', 'center', 'justify' ];
+
 /**
  * @extends module:core/plugin~Plugin
  */
@@ -49,7 +51,7 @@ export default class AlignmentEditing extends Plugin {
 			.toAttribute( viewElement => {
 				const textAlign = viewElement.getStyle( 'text-align' );
 
-				if ( !textAlign ) {
+				if ( !textAlign || !alignmentTypes.includes( textAlign ) ) {
 					return;
 				}
 

+ 20 - 0
packages/ckeditor5-alignment/tests/alignmentediting.js

@@ -58,6 +58,26 @@ describe( 'AlignmentEditing', () => {
 		} );
 	} );
 
+	describe( 'should work with broken styles', () => {
+		it( 'should ignore empty style', () => {
+			const data = '<p style="text-align:">x</p>';
+
+			editor.setData( data );
+
+			expect( getModelData( doc ) ).to.equal( '<paragraph>[]x</paragraph>' );
+			expect( editor.getData() ).to.equal( '<p>x</p>' );
+		} );
+
+		it( 'should ignore not known style', () => {
+			const data = '<p style="text-align:unset;">x</p>';
+
+			editor.setData( data );
+
+			expect( getModelData( doc ) ).to.equal( '<paragraph>[]x</paragraph>' );
+			expect( editor.getData() ).to.equal( '<p>x</p>' );
+		} );
+	} );
+
 	describe( 'alignCenter', () => {
 		it( 'adds converters to the data pipeline', () => {
 			const data = '<p style="text-align:center;">x</p>';