浏览代码

Add basic table border style upcast conversion test.

Maciej Gołaszewski 6 年之前
父节点
当前提交
eb898bc61c

+ 19 - 0
packages/ckeditor5-table/tests/_utils/utils.js

@@ -190,6 +190,11 @@ export function defaultSchema( schema, registerParagraph = true ) {
 	if ( registerParagraph ) {
 		schema.register( 'paragraph', { inheritAllFrom: '$block' } );
 	}
+
+	// Styles
+	schema.extend( 'tableCell', {
+		allowAttributes: [ 'border' ]
+	} );
 }
 
 export function defaultConversion( conversion, asWidget = false ) {
@@ -215,6 +220,20 @@ export function defaultConversion( conversion, asWidget = false ) {
 
 	conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange( { asWidget } ) );
 	conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange( { asWidget } ) );
+
+	// Styles
+	conversion.for( 'upcast' ).attributeToAttribute( {
+		view: {
+			name: 'td',
+			styles: {
+				border: /[\s\S]+/
+			}
+		},
+		model: {
+			key: 'border',
+			value: viewElement => viewElement.getStyle( 'border' )
+		}
+	} );
 }
 
 // Formats table cell attributes

+ 24 - 5
packages/ckeditor5-table/tests/converters/upcasttable.js

@@ -10,6 +10,7 @@ import ImageEditing from '@ckeditor/ckeditor5-image/src/image/imageediting';
 import Widget from '@ckeditor/ckeditor5-widget/src/widget';
 
 import { defaultConversion, defaultSchema, formatTable, modelTable } from '../_utils/utils';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'upcastTable()', () => {
 	let editor, model;
@@ -551,13 +552,31 @@ describe( 'upcastTable()', () => {
 
 			expectModel(
 				'<table>' +
-					'<tableRow><tableCell><paragraph>1</paragraph></tableCell></tableRow>' +
-					'<tableRow><tableCell><paragraph>2</paragraph></tableCell></tableRow>' +
-					'<tableRow><tableCell><paragraph>3</paragraph></tableCell></tableRow>' +
-					'<tableRow><tableCell><paragraph>4</paragraph></tableCell></tableRow>' +
-					'<tableRow><tableCell><paragraph>5</paragraph></tableCell></tableRow>' +
+				'<tableRow><tableCell><paragraph>1</paragraph></tableCell></tableRow>' +
+				'<tableRow><tableCell><paragraph>2</paragraph></tableCell></tableRow>' +
+				'<tableRow><tableCell><paragraph>3</paragraph></tableCell></tableRow>' +
+				'<tableRow><tableCell><paragraph>4</paragraph></tableCell></tableRow>' +
+				'<tableRow><tableCell><paragraph>5</paragraph></tableCell></tableRow>' +
 				'</table>'
 			);
 		} );
 	} );
+
+	describe( 'styles', () => {
+		describe( 'table cell borders', () => {
+			it( 'should pass', () => {
+				editor.setData( '<table><tr><td style="border:1px solid blue">foo</td></tr></table>' );
+
+				assertEqualMarkup( getModelData( model, { withoutSelection: true } ),
+					'<table>' +
+						'<tableRow>' +
+							'<tableCell border="1px solid blue">' +
+								'<paragraph>foo</paragraph>' +
+							'</tableCell>' +
+						'</tableRow>' +
+					'</table>'
+				);
+			} );
+		} );
+	} );
 } );