|
@@ -9,7 +9,6 @@ import ViewDocumentFragment from '../../src/view/documentfragment';
|
|
|
import ViewText from '../../src/view/text';
|
|
import ViewText from '../../src/view/text';
|
|
|
|
|
|
|
|
import Model from '../../src/model/model';
|
|
import Model from '../../src/model/model';
|
|
|
-import ModelSchema from '../../src/model/schema';
|
|
|
|
|
import ModelDocumentFragment from '../../src/model/documentfragment';
|
|
import ModelDocumentFragment from '../../src/model/documentfragment';
|
|
|
import ModelElement from '../../src/model/element';
|
|
import ModelElement from '../../src/model/element';
|
|
|
import ModelText from '../../src/model/text';
|
|
import ModelText from '../../src/model/text';
|
|
@@ -17,15 +16,17 @@ import ModelText from '../../src/model/text';
|
|
|
import { convertToModelFragment, convertText } from '../../src/conversion/view-to-model-converters';
|
|
import { convertToModelFragment, convertText } from '../../src/conversion/view-to-model-converters';
|
|
|
|
|
|
|
|
describe( 'view-to-model-converters', () => {
|
|
describe( 'view-to-model-converters', () => {
|
|
|
- let dispatcher, schema, additionalData;
|
|
|
|
|
-
|
|
|
|
|
- const model = new Model();
|
|
|
|
|
|
|
+ let dispatcher, schema, additionalData, model;
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
- schema = new ModelSchema();
|
|
|
|
|
|
|
+ model = new Model();
|
|
|
|
|
+ schema = model.schema;
|
|
|
|
|
+
|
|
|
schema.register( 'paragraph', { inheritAllFrom: '$block' } );
|
|
schema.register( 'paragraph', { inheritAllFrom: '$block' } );
|
|
|
schema.extend( '$text', { allowIn: '$root' } );
|
|
schema.extend( '$text', { allowIn: '$root' } );
|
|
|
|
|
+
|
|
|
additionalData = { context: [ '$root' ] };
|
|
additionalData = { context: [ '$root' ] };
|
|
|
|
|
+
|
|
|
dispatcher = new ViewConversionDispatcher( model, { schema } );
|
|
dispatcher = new ViewConversionDispatcher( model, { schema } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -62,8 +63,16 @@ describe( 'view-to-model-converters', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not convert text if it is wrong with schema', () => {
|
|
it( 'should not convert text if it is wrong with schema', () => {
|
|
|
- // TODO this requires a callback
|
|
|
|
|
- // schema.xdisallow( { name: '$text', inside: '$root' } );
|
|
|
|
|
|
|
+ schema.on( 'checkChild', ( evt, args ) => {
|
|
|
|
|
+ const context = args[ 0 ];
|
|
|
|
|
+ const child = args[ 1 ];
|
|
|
|
|
+ const childRule = schema.getRule( child );
|
|
|
|
|
+
|
|
|
|
|
+ if ( childRule.name == '$text' && context[ context.length - 1 ].name == '$root' ) {
|
|
|
|
|
+ evt.stop();
|
|
|
|
|
+ evt.return = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }, { priority: 'high' } );
|
|
|
|
|
|
|
|
const viewText = new ViewText( 'foobar' );
|
|
const viewText = new ViewText( 'foobar' );
|
|
|
dispatcher.on( 'text', convertText() );
|
|
dispatcher.on( 'text', convertText() );
|