浏览代码

Tests: Extended MediaEmbedEditing tests.

Aleksander Nowodzinski 7 年之前
父节点
当前提交
bb1b2c4445

+ 6 - 9
packages/ckeditor5-media-embed/src/converters.js

@@ -47,10 +47,10 @@ export function viewFigureToModel() {
 		const conversionResult = conversionApi.convertItem( viewWrapper, data.modelCursor );
 
 		// Get the model wrapper from conversion result.
-		const modelWrapper = first( conversionResult.modelRange.getItems() );
+		const mediaElement = first( conversionResult.modelRange.getItems() );
 
-		// If the wrapper wasn't successfully converted, then finish conversion.
-		if ( !modelWrapper ) {
+		// If the media has not been successfully converted, finish the conversion.
+		if ( !mediaElement ) {
 			return;
 		}
 
@@ -75,20 +75,17 @@ export function modelToViewUrlAttributeConverter( editor, options ) {
 		const viewWriter = conversionApi.writer;
 		const figure = conversionApi.mapper.toViewElement( data.item );
 		const attributes = {};
-		const wrapper = figure.getChild( 0 );
-		const withAspectWrapper = options.inEditingPipeline || options.shouldRenderContent;
+		const withAspectWrapper = options.isEditingPipeline || options.shouldRenderContent;
 		const wrapperContent = withAspectWrapper ? getMediaContent( editor, data.attributeNewValue ) : null;
 
 		// TODO: removing it and creating it from scratch is a hack. We can do better than that.
-		if ( wrapper ) {
-			viewWriter.remove( ViewRange.createOn( wrapper ) );
-		}
+		viewWriter.remove( ViewRange.createIn( figure ) );
 
 		if ( data.attributeNewValue !== null ) {
 			attributes[ 'data-oembed-url' ] = data.attributeNewValue;
 		}
 
-		if ( options.inEditingPipeline ) {
+		if ( options.isEditingPipeline ) {
 			attributes.class = 'ck-media__wrapper';
 		}
 

+ 2 - 6
packages/ckeditor5-media-embed/src/mediaembedediting.js

@@ -140,18 +140,14 @@ export default class MediaEmbedEditing extends Plugin {
 		conversion.for( 'editingDowncast' ).add( downcastElementToElement( {
 			model: 'media',
 			view: ( modelElement, viewWriter ) => {
-				const figure = createMediaFigureElement( viewWriter, {
-					witgAspectWrapper: true
-				} );
-
-				return toMediaWidget( figure, viewWriter, t( 'media widget' ) );
+				return toMediaWidget( createMediaFigureElement( viewWriter ), viewWriter, t( 'media widget' ) );
 			}
 		} ) );
 
 		// Model -> View (url -> data-oembed-url)
 		conversion.for( 'editingDowncast' )
 			.add( modelToViewUrlAttributeConverter( editor, {
-				inEditingPipeline: true
+				isEditingPipeline: true
 			} ) );
 
 		// View -> Model (data-oembed-url -> url)

+ 1 - 1
packages/ckeditor5-media-embed/src/utils.js

@@ -35,7 +35,7 @@ export function toMediaWidget( viewElement, writer, label ) {
 // @private
 // @param {module:engine/view/writer~Writer} writer
 // @returns {module:engine/view/containerelement~ContainerElement}
-export function createMediaFigureElement( writer, options ) {
+export function createMediaFigureElement( writer, options = {} ) {
 	const figure = writer.createContainerElement( 'figure', { class: 'media' } );
 
 	// TODO: This is a hack. Without it, the figure in the data pipeline will contain   because

+ 12 - 4
packages/ckeditor5-media-embed/tests/mediaembedediting.js

@@ -117,20 +117,28 @@ describe( 'MediaEmbedEditing', () => {
 						.to.equal( '' );
 				} );
 
+				it( 'should not convert when the wrapper has no data-oembed-url attribute', () => {
+					editor.setData( '<figure class="media"><div></div></figure>' );
+
+					expect( getModelData( model, { withoutSelection: true } ) )
+						.to.equal( '' );
+				} );
+
 				it( 'should not convert in the wrong context', () => {
-					model.schema.register( 'div', { inheritAllFrom: '$block' } );
+					model.schema.register( 'blockquote', { inheritAllFrom: '$block' } );
 					model.schema.addChildCheck( ( ctx, childDef ) => {
 						if ( ctx.endsWith( '$root' ) && childDef.name == 'media' ) {
 							return false;
 						}
 					} );
 
-					editor.conversion.elementToElement( { model: 'div', view: 'div' } );
+					editor.conversion.elementToElement( { model: 'blockquote', view: 'blockquote' } );
 
-					editor.setData( '<div><figure class="media"><div data-oembed-url="http://ckeditor.com"></div></figure></div>' );
+					editor.setData(
+						'<blockquote><figure class="media"><div data-oembed-url="http://ckeditor.com"></div></figure></blockquote>' );
 
 					expect( getModelData( model, { withoutSelection: true } ) )
-						.to.equal( '<div></div>' );
+						.to.equal( '<blockquote></blockquote>' );
 				} );
 
 				it( 'should not convert if the oembed wrapper is already consumed', () => {