Răsfoiți Sursa

Replaced paragraph integration test by figure converter tests.

Oskar Wróbel 8 ani în urmă
părinte
comite
53762fefc7

+ 58 - 0
packages/ckeditor5-image/tests/image/converters.js

@@ -96,6 +96,64 @@ describe( 'Image converters', () => {
 			expectModel( '<image src="foo.png">xy<foo></foo></image>' );
 		} );
 
+		it( 'should split parent element when image is not allowed - in the middle', () => {
+			buildViewConverter().for( editor.data.viewToModel ).fromElement( 'div' ).toElement( 'div' );
+			buildModelConverter().for( editor.editing.modelToView ).fromElement( 'div' ).toElement( 'div' );
+
+			schema.register( 'div', { inheritAllFrom: '$block', } );
+			schema.extend( 'image', { disallowIn: 'div' } );
+
+			editor.setData(
+				'<div>' +
+					'abc' +
+					'<figure class="image">' +
+						'<img src="foo.jpg"/>' +
+					'</figure>' +
+					'def' +
+				'</div>'
+			);
+
+			expectModel( '<div>abc</div><image src="foo.jpg"></image><div>def</div>' );
+		} );
+
+		it( 'should split parent element when image is not allowed - at the end', () => {
+			buildViewConverter().for( editor.data.viewToModel ).fromElement( 'div' ).toElement( 'div' );
+			buildModelConverter().for( editor.editing.modelToView ).fromElement( 'div' ).toElement( 'div' );
+
+			schema.register( 'div', { inheritAllFrom: '$block', } );
+			schema.extend( 'image', { disallowIn: 'div' } );
+
+			editor.setData(
+				'<div>' +
+					'abc' +
+					'<figure class="image">' +
+						'<img src="foo.jpg"/>' +
+					'</figure>' +
+				'</div>'
+			);
+
+			expectModel( '<div>abc</div><image src="foo.jpg"></image>' );
+		} );
+
+		it( 'should split parent element when image is not allowed - at the beginning', () => {
+			buildViewConverter().for( editor.data.viewToModel ).fromElement( 'div' ).toElement( 'div' );
+			buildModelConverter().for( editor.editing.modelToView ).fromElement( 'div' ).toElement( 'div' );
+
+			schema.register( 'div', { inheritAllFrom: '$block', } );
+			schema.extend( 'image', { disallowIn: 'div' } );
+
+			editor.setData(
+				'<div>' +
+					'<figure class="image">' +
+						'<img src="foo.jpg"/>' +
+					'</figure>' +
+					'def' +
+				'</div>'
+			);
+
+			expectModel( '<image src="foo.jpg"></image><div>def</div>' );
+		} );
+
 		it( 'should be possible to overwrite', () => {
 			dispatcher.on( 'element:figure', ( evt, data, conversionApi ) => {
 				conversionApi.consumable.consume( data.viewItem, { name: true } );

+ 0 - 79
packages/ckeditor5-image/tests/paragraph-integration.js

@@ -1,79 +0,0 @@
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
-import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
-import Image from '@ckeditor/ckeditor5-image/src/image';
-import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
-import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
-import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-
-/* global document */
-
-describe( 'Paragraph feature – integration', () => {
-	let editor, model, element;
-
-	beforeEach( () => {
-		element = document.createElement( 'div' );
-		document.body.appendChild( element );
-
-		return ClassicTestEditor
-			.create( element, {
-				plugins: [ Essentials, Paragraph, Image, ImageCaption ]
-			} )
-			.then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-			} );
-	} );
-
-	afterEach( () => {
-		element.remove();
-		return editor.destroy();
-	} );
-
-	it( 'should convert figure when is inside paragraph element', () => {
-		editor.setData(
-			'<p>' +
-				'<figure class="image">' +
-					'<img src="foo.jpg"/>' +
-					'<figcaption>bar</figcaption>' +
-				'</figure>' +
-			'</p>'
-		);
-
-		// Empty paragraph is not removed because is not split by converter but by DataProcessor.
-		expect( getData( model, { withoutSelection: true } ) )
-			.to.equal( '<paragraph></paragraph><image src="foo.jpg"><caption>bar</caption></image><paragraph></paragraph>' );
-	} );
-
-	it( 'should convert figure when is inside paragraph like element', () => {
-		editor.setData(
-			'<dv>' +
-				'<figure class="image">' +
-					'<img src="foo.jpg"/>' +
-					'<figcaption>bar</figcaption>' +
-				'</figure>' +
-			'</dv>'
-		);
-
-		expect( getData( model, { withoutSelection: true } ) )
-			.to.equal( '<image src="foo.jpg"><caption>bar</caption></image>' );
-	} );
-
-	it( 'should convert figure when element before is autoparagraphed', () => {
-		editor.setData(
-			'foo' +
-			'<figure class="image">' +
-				'<img src="foo.jpg"/>' +
-				'<figcaption>bar</figcaption>' +
-			'</figure>' +
-			'bar'
-		);
-
-		expect( getData( model, { withoutSelection: true } ) )
-			.to.equal( '<paragraph>foo</paragraph><image src="foo.jpg"><caption>bar</caption></image><paragraph>bar</paragraph>' );
-	} );
-} );