浏览代码

Increased cc of ViewConversionDispatcher.

Oskar Wróbel 7 年之前
父节点
当前提交
b3f593786c
共有 1 个文件被更改,包括 45 次插入0 次删除
  1. 45 0
      packages/ckeditor5-engine/tests/conversion/viewconversiondispatcher.js

+ 45 - 0
packages/ckeditor5-engine/tests/conversion/viewconversiondispatcher.js

@@ -342,6 +342,51 @@ describe( 'ViewConversionDispatcher', () => {
 			expect( marker1.end.path ).to.deep.equal( [ 4 ] );
 			expect( marker2.start.path ).to.deep.equal( marker2.end.path ).to.deep.equal( [ 3 ] );
 		} );
+
+		it( 'should convert according to given context', () => {
+			dispatcher = new ViewConversionDispatcher( model, { schema: model.schema } );
+
+			const spy = sinon.spy();
+			const viewElement = new ViewContainerElement( 'third' );
+			let checkChildResult;
+
+			model.schema.register( 'first', {
+				allowIn: '$root'
+			} );
+			model.schema.register( 'second', {
+				allowIn: 'first'
+			} );
+			model.schema.register( 'third', {
+				allowIn: 'second',
+				disallowIn: 'first'
+			} );
+
+			dispatcher.on( 'element:third', ( evt, data, consumable, conversionApi ) => {
+				spy();
+				checkChildResult = conversionApi.schema.checkChild( data.position, 'third' );
+			} );
+
+			// Default context $root.
+			dispatcher.convert( viewElement );
+			sinon.assert.calledOnce( spy );
+			expect( checkChildResult ).to.false;
+
+			// SchemaDefinition as context.
+			dispatcher.convert( viewElement, [ 'first' ] );
+			sinon.assert.calledTwice( spy );
+			expect( checkChildResult ).to.false;
+
+			// Position as context.
+			const fragment = new ModelDocumentFragment( [
+				new ModelElement( 'first', { foo: 'bar' }, [
+					new ModelElement( 'second', null )
+				] )
+			] );
+
+			dispatcher.convert( viewElement, new ModelPosition( fragment, [ 0, 0, 0 ] ) );
+			sinon.assert.calledThrice( spy );
+			expect( checkChildResult ).to.true;
+		} );
 	} );
 
 	describe( 'conversionApi', () => {