Parcourir la source

Add test for inline border position style.

Maciej Gołaszewski il y a 6 ans
Parent
commit
70b938878b

+ 18 - 1
packages/ckeditor5-engine/src/view/styles.js

@@ -90,6 +90,19 @@ export default class Styles {
 		this.extractors.set( 'border-right', borderPositionExtractor( 'right' ) );
 		this.extractors.set( 'border-right', borderPositionExtractor( 'right' ) );
 		this.extractors.set( 'border-bottom', borderPositionExtractor( 'bottom' ) );
 		this.extractors.set( 'border-bottom', borderPositionExtractor( 'bottom' ) );
 		this.extractors.set( 'border-left', borderPositionExtractor( 'left' ) );
 		this.extractors.set( 'border-left', borderPositionExtractor( 'left' ) );
+		this.extractors.set( 'border-top-color', styles => styles.getNormalized( 'border.color.top' ) );
+		// TODO: tests/is needed?
+		this.extractors.set( 'border-bottom-color', styles => styles.getNormalized( 'border.color.bottom' ) );
+		this.extractors.set( 'border-right-color', styles => styles.getNormalized( 'border.color.right' ) );
+		this.extractors.set( 'border-left-color', styles => styles.getNormalized( 'border.color.left' ) );
+		this.extractors.set( 'border-top-width', styles => styles.getNormalized( 'border.width.top' ) );
+		this.extractors.set( 'border-bottom-width', styles => styles.getNormalized( 'border.width.bottom' ) );
+		this.extractors.set( 'border-right-width', styles => styles.getNormalized( 'border.width.right' ) );
+		this.extractors.set( 'border-left-width', styles => styles.getNormalized( 'border.width.left' ) );
+		this.extractors.set( 'border-top-style', styles => styles.getNormalized( 'border.style.top' ) );
+		this.extractors.set( 'border-bottom-style', styles => styles.getNormalized( 'border.style.bottom' ) );
+		this.extractors.set( 'border-right-style', styles => styles.getNormalized( 'border.style.right' ) );
+		this.extractors.set( 'border-left-style', styles => styles.getNormalized( 'border.style.left' ) );
 
 
 		/**
 		/**
 		 * Holds style normalize object reducers.
 		 * Holds style normalize object reducers.
@@ -611,7 +624,11 @@ function getBorderPositionReducer( which ) {
 			reduced.push( value.color[ which ] );
 			reduced.push( value.color[ which ] );
 		}
 		}
 
 
-		return [ [ 'border-' + which, reduced.join( ' ' ) ] ];
+		if ( reduced.length ) {
+			return [ [ 'border-' + which, reduced.join( ' ' ) ] ];
+		}
+
+		return [];
 	};
 	};
 }
 }
 
 

+ 11 - 0
packages/ckeditor5-engine/tests/view/styles.js

@@ -268,6 +268,17 @@ describe( 'Styles', () => {
 				expect( styles.getInlineProperty( 'border-width' ) ).to.equal( '1px' );
 				expect( styles.getInlineProperty( 'border-width' ) ).to.equal( '1px' );
 			} );
 			} );
 
 
+			it( 'should output only defined inline styles', () => {
+				styles.insertProperty( 'border-color', { top: 'blue' } );
+				expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
+					color: { top: 'blue' }
+				} );
+
+				expect( styles.getInlineStyle( 'border' ) ).to.equal( 'border-top:blue;' );
+				// TODO: expect( styles.hasProperty( 'border-top-color' ) ).to.be.true;
+				expect( styles.getInlineProperty( 'border-top-color' ) ).to.equal( 'blue' );
+			} );
+
 			it( 'should output inline shorthand rules #2', () => {
 			it( 'should output inline shorthand rules #2', () => {
 				styles.setStyle( 'border:1px solid blue;border-left:#665511 dashed 2.7em;border-top:7px dotted #ccc;' );
 				styles.setStyle( 'border:1px solid blue;border-left:#665511 dashed 2.7em;border-top:7px dotted #ccc;' );