|
|
@@ -9,20 +9,26 @@ import Schema from '@ckeditor/ckeditor5-engine/src/model/schema';
|
|
|
import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
|
|
|
import { parse as parseView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
import { stringify as stringifyModel } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
+import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
|
|
|
|
|
|
describe.only( 'Image converters', () => {
|
|
|
describe( 'viewToModelImage', () => {
|
|
|
- let dispatcher;
|
|
|
+ let dispatcher, schema;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
- const schema = new Schema();
|
|
|
+ schema = new Schema();
|
|
|
schema.registerItem( 'image' );
|
|
|
schema.requireAttributes( 'image', [ 'src' ] );
|
|
|
schema.allow( { name: 'image', attributes: [ 'alt', 'src' ], inside: '$root' } );
|
|
|
schema.objects.add( 'image' );
|
|
|
+ schema.registerItem( 'paragraph', '$block' );
|
|
|
|
|
|
dispatcher = new ViewConversionDispatcher( { schema } );
|
|
|
dispatcher.on( 'element:figure', viewToModelImage() );
|
|
|
+
|
|
|
+ buildViewConverter().for( dispatcher )
|
|
|
+ .fromElement( 'p' )
|
|
|
+ .toElement( 'paragraph' );
|
|
|
} );
|
|
|
|
|
|
it( 'should convert view figure element', () => {
|
|
|
@@ -52,6 +58,21 @@ describe.only( 'Image converters', () => {
|
|
|
);
|
|
|
} );
|
|
|
|
|
|
+ it( 'should not convert image if schema disallows it', () => {
|
|
|
+ schema.disallow( { name: 'image', attributes: [ 'alt', 'src' ], inside: '$root' } );
|
|
|
+ const element = parseView( '<figure class="image"><img src="foo.png"></img></figure>' );
|
|
|
+ const model = dispatcher.convert( element );
|
|
|
+
|
|
|
+ expect( model ).to.be.null;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should not convert image if there is no img element', () => {
|
|
|
+ const element = parseView( '<figure class="image"></figure>' );
|
|
|
+ const model = dispatcher.convert( element );
|
|
|
+
|
|
|
+ expect( model ).to.be.null;
|
|
|
+ } );
|
|
|
+
|
|
|
function test( viewString, modelString ) {
|
|
|
const element = parseView( viewString );
|
|
|
const model = dispatcher.convert( element );
|