|
@@ -5,7 +5,6 @@
|
|
|
|
|
|
|
|
import ViewConversionDispatcher from '../../src/conversion/viewconversiondispatcher';
|
|
import ViewConversionDispatcher from '../../src/conversion/viewconversiondispatcher';
|
|
|
import ViewContainerElement from '../../src/view/containerelement';
|
|
import ViewContainerElement from '../../src/view/containerelement';
|
|
|
-import ViewAttributeElement from '../../src/view/attributeelement';
|
|
|
|
|
import ViewDocumentFragment from '../../src/view/documentfragment';
|
|
import ViewDocumentFragment from '../../src/view/documentfragment';
|
|
|
import ViewText from '../../src/view/text';
|
|
import ViewText from '../../src/view/text';
|
|
|
|
|
|
|
@@ -14,7 +13,16 @@ import ModelElement from '../../src/model/element';
|
|
|
import ModelDocumentFragment from '../../src/model/documentfragment';
|
|
import ModelDocumentFragment from '../../src/model/documentfragment';
|
|
|
import { stringify } from '../../src/dev-utils/model';
|
|
import { stringify } from '../../src/dev-utils/model';
|
|
|
|
|
|
|
|
|
|
+import log from '@ckeditor/ckeditor5-utils/src/log';
|
|
|
|
|
+
|
|
|
|
|
+// Stored in case it is silenced and has to be restored.
|
|
|
|
|
+const logWarn = log.warn;
|
|
|
|
|
+
|
|
|
describe( 'ViewConversionDispatcher', () => {
|
|
describe( 'ViewConversionDispatcher', () => {
|
|
|
|
|
+ afterEach( () => {
|
|
|
|
|
+ log.warn = logWarn;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
describe( 'constructor()', () => {
|
|
describe( 'constructor()', () => {
|
|
|
it( 'should create ViewConversionDispatcher with passed api', () => {
|
|
it( 'should create ViewConversionDispatcher with passed api', () => {
|
|
|
const apiObj = {};
|
|
const apiObj = {};
|
|
@@ -34,6 +42,8 @@ describe( 'ViewConversionDispatcher', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should fire viewCleanup event on converted view part', () => {
|
|
it( 'should fire viewCleanup event on converted view part', () => {
|
|
|
|
|
+ silenceWarnings();
|
|
|
|
|
+
|
|
|
sinon.spy( dispatcher, 'fire' );
|
|
sinon.spy( dispatcher, 'fire' );
|
|
|
|
|
|
|
|
const viewP = new ViewContainerElement( 'p' );
|
|
const viewP = new ViewContainerElement( 'p' );
|
|
@@ -43,6 +53,8 @@ describe( 'ViewConversionDispatcher', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should fire proper events', () => {
|
|
it( 'should fire proper events', () => {
|
|
|
|
|
+ silenceWarnings();
|
|
|
|
|
+
|
|
|
const viewText = new ViewText( 'foobar' );
|
|
const viewText = new ViewText( 'foobar' );
|
|
|
const viewElement = new ViewContainerElement( 'p', null, viewText );
|
|
const viewElement = new ViewContainerElement( 'p', null, viewText );
|
|
|
const viewFragment = new ViewDocumentFragment( viewElement );
|
|
const viewFragment = new ViewDocumentFragment( viewElement );
|
|
@@ -59,15 +71,17 @@ describe( 'ViewConversionDispatcher', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should convert ViewText', () => {
|
|
it( 'should convert ViewText', () => {
|
|
|
|
|
+ const spy = sinon.spy();
|
|
|
const viewText = new ViewText( 'foobar' );
|
|
const viewText = new ViewText( 'foobar' );
|
|
|
|
|
|
|
|
dispatcher.on( 'text', ( evt, data, consumable, conversionApi ) => {
|
|
dispatcher.on( 'text', ( evt, data, consumable, conversionApi ) => {
|
|
|
- const result = {
|
|
|
|
|
- eventName: evt.name,
|
|
|
|
|
- input: data.input,
|
|
|
|
|
- // Check whether additional data has been passed.
|
|
|
|
|
- foo: data.foo
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ // Check if this method has been fired.
|
|
|
|
|
+ spy();
|
|
|
|
|
+
|
|
|
|
|
+ // Check correctness of passed parameters.
|
|
|
|
|
+ expect( evt.name ).to.equal( 'text' );
|
|
|
|
|
+ expect( data.input ).to.equal( viewText );
|
|
|
|
|
+ expect( data.foo ).to.equal( 'bar' );
|
|
|
|
|
|
|
|
// Check whether consumable has appropriate value to consume.
|
|
// Check whether consumable has appropriate value to consume.
|
|
|
expect( consumable.consume( data.input ) ).to.be.true;
|
|
expect( consumable.consume( data.input ) ).to.be.true;
|
|
@@ -77,30 +91,31 @@ describe( 'ViewConversionDispatcher', () => {
|
|
|
|
|
|
|
|
// Set conversion result to `output` property of `data`.
|
|
// Set conversion result to `output` property of `data`.
|
|
|
// Later we will check if it was returned by `convert` method.
|
|
// Later we will check if it was returned by `convert` method.
|
|
|
- data.output = result;
|
|
|
|
|
|
|
+ data.output = new ModelText( data.foo );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
// Use `additionalData` parameter to check if it was passed to the event.
|
|
// Use `additionalData` parameter to check if it was passed to the event.
|
|
|
const conversionResult = dispatcher.convert( viewText, { foo: 'bar' } );
|
|
const conversionResult = dispatcher.convert( viewText, { foo: 'bar' } );
|
|
|
|
|
|
|
|
// Check conversion result.
|
|
// Check conversion result.
|
|
|
- expect( conversionResult ).to.deep.equal( {
|
|
|
|
|
- eventName: 'text',
|
|
|
|
|
- input: viewText,
|
|
|
|
|
- foo: 'bar'
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ // Result should be wrapped in document fragment.
|
|
|
|
|
+ expect( conversionResult ).to.be.instanceof( ModelDocumentFragment );
|
|
|
|
|
+ expect( conversionResult.getChild( 0 ).data ).to.equal( 'bar' );
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should convert ViewContainerElement', () => {
|
|
it( 'should convert ViewContainerElement', () => {
|
|
|
|
|
+ const spy = sinon.spy();
|
|
|
const viewElement = new ViewContainerElement( 'p', { attrKey: 'attrValue' } );
|
|
const viewElement = new ViewContainerElement( 'p', { attrKey: 'attrValue' } );
|
|
|
|
|
|
|
|
dispatcher.on( 'element', ( evt, data, consumable, conversionApi ) => {
|
|
dispatcher.on( 'element', ( evt, data, consumable, conversionApi ) => {
|
|
|
- const result = {
|
|
|
|
|
- eventName: evt.name,
|
|
|
|
|
- input: data.input,
|
|
|
|
|
- // Check whether additional data has been passed.
|
|
|
|
|
- foo: data.foo
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ // Check if this method has been fired.
|
|
|
|
|
+ spy();
|
|
|
|
|
+
|
|
|
|
|
+ // Check correctness of passed parameters.
|
|
|
|
|
+ expect( evt.name ).to.equal( 'element:p' );
|
|
|
|
|
+ expect( data.input ).to.equal( viewElement );
|
|
|
|
|
+ expect( data.foo ).to.equal( 'bar' );
|
|
|
|
|
|
|
|
// Check whether consumable has appropriate value to consume.
|
|
// Check whether consumable has appropriate value to consume.
|
|
|
expect( consumable.consume( data.input, { name: true } ) ).to.be.true;
|
|
expect( consumable.consume( data.input, { name: true } ) ).to.be.true;
|
|
@@ -111,30 +126,31 @@ describe( 'ViewConversionDispatcher', () => {
|
|
|
|
|
|
|
|
// Set conversion result to `output` property of `data`.
|
|
// Set conversion result to `output` property of `data`.
|
|
|
// Later we will check if it was returned by `convert` method.
|
|
// Later we will check if it was returned by `convert` method.
|
|
|
- data.output = result;
|
|
|
|
|
|
|
+ data.output = new ModelElement( 'paragraph' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
// Use `additionalData` parameter to check if it was passed to the event.
|
|
// Use `additionalData` parameter to check if it was passed to the event.
|
|
|
const conversionResult = dispatcher.convert( viewElement, { foo: 'bar' } );
|
|
const conversionResult = dispatcher.convert( viewElement, { foo: 'bar' } );
|
|
|
|
|
|
|
|
// Check conversion result.
|
|
// Check conversion result.
|
|
|
- expect( conversionResult ).to.deep.equal( {
|
|
|
|
|
- eventName: 'element:p',
|
|
|
|
|
- input: viewElement,
|
|
|
|
|
- foo: 'bar'
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ // Result should be wrapped in document fragment.
|
|
|
|
|
+ expect( conversionResult ).to.be.instanceof( ModelDocumentFragment );
|
|
|
|
|
+ expect( conversionResult.getChild( 0 ).name ).to.equal( 'paragraph' );
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should convert ViewDocumentFragment', () => {
|
|
it( 'should convert ViewDocumentFragment', () => {
|
|
|
|
|
+ const spy = sinon.spy();
|
|
|
const viewFragment = new ViewDocumentFragment();
|
|
const viewFragment = new ViewDocumentFragment();
|
|
|
|
|
|
|
|
dispatcher.on( 'documentFragment', ( evt, data, consumable, conversionApi ) => {
|
|
dispatcher.on( 'documentFragment', ( evt, data, consumable, conversionApi ) => {
|
|
|
- const result = {
|
|
|
|
|
- eventName: evt.name,
|
|
|
|
|
- input: data.input,
|
|
|
|
|
- // Check whether additional data has been passed.
|
|
|
|
|
- foo: data.foo
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ // Check if this method has been fired.
|
|
|
|
|
+ spy();
|
|
|
|
|
+
|
|
|
|
|
+ // Check correctness of passed parameters.
|
|
|
|
|
+ expect( evt.name ).to.equal( 'documentFragment' );
|
|
|
|
|
+ expect( data.input ).to.equal( viewFragment );
|
|
|
|
|
+ expect( data.foo ).to.equal( 'bar' );
|
|
|
|
|
|
|
|
// Check whether consumable has appropriate value to consume.
|
|
// Check whether consumable has appropriate value to consume.
|
|
|
expect( consumable.consume( data.input ) ).to.be.true;
|
|
expect( consumable.consume( data.input ) ).to.be.true;
|
|
@@ -144,44 +160,16 @@ describe( 'ViewConversionDispatcher', () => {
|
|
|
|
|
|
|
|
// Set conversion result to `output` property of `data`.
|
|
// Set conversion result to `output` property of `data`.
|
|
|
// Later we will check if it was returned by `convert` method.
|
|
// Later we will check if it was returned by `convert` method.
|
|
|
- data.output = result;
|
|
|
|
|
|
|
+ data.output = new ModelDocumentFragment( [ new ModelText( 'foo' ) ] );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
// Use `additionalData` parameter to check if it was passed to the event.
|
|
// Use `additionalData` parameter to check if it was passed to the event.
|
|
|
const conversionResult = dispatcher.convert( viewFragment, { foo: 'bar' } );
|
|
const conversionResult = dispatcher.convert( viewFragment, { foo: 'bar' } );
|
|
|
|
|
|
|
|
// Check conversion result.
|
|
// Check conversion result.
|
|
|
- expect( conversionResult ).to.deep.equal( {
|
|
|
|
|
- eventName: 'documentFragment',
|
|
|
|
|
- input: viewFragment,
|
|
|
|
|
- foo: 'bar'
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should always wrap converted element by ModelDocumentFragment', () => {
|
|
|
|
|
- const viewElement = new ViewContainerElement( 'p' );
|
|
|
|
|
-
|
|
|
|
|
- dispatcher.on( 'element', ( evt, data ) => {
|
|
|
|
|
- data.output = new ModelElement( 'paragraph' );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- const documentFragment = dispatcher.convert( viewElement, { foo: 'bar' } );
|
|
|
|
|
-
|
|
|
|
|
- expect( documentFragment ).to.instanceof( ModelDocumentFragment );
|
|
|
|
|
- expect( stringify( documentFragment ) ).to.equal( '<paragraph></paragraph>' );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should not wrap ModelDocumentFragment', () => {
|
|
|
|
|
- const viewFragment = new ViewDocumentFragment();
|
|
|
|
|
-
|
|
|
|
|
- dispatcher.on( 'documentFragment', ( evt, data ) => {
|
|
|
|
|
- data.output = new ModelDocumentFragment();
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- const documentFragment = dispatcher.convert( viewFragment );
|
|
|
|
|
-
|
|
|
|
|
- expect( documentFragment ).to.instanceof( ModelDocumentFragment );
|
|
|
|
|
- expect( documentFragment.childCount ).to.equal( 0 );
|
|
|
|
|
|
|
+ expect( conversionResult ).to.be.instanceof( ModelDocumentFragment );
|
|
|
|
|
+ expect( conversionResult.getChild( 0 ).data ).to.equal( 'foo' );
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should extract temporary markers stamps from converter element and create static markers list', () => {
|
|
it( 'should extract temporary markers stamps from converter element and create static markers list', () => {
|
|
@@ -207,91 +195,165 @@ describe( 'ViewConversionDispatcher', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'conversionApi#convertItem', () => {
|
|
|
|
|
- it( 'should convert view elements and view text', () => {
|
|
|
|
|
- const dispatcher = new ViewConversionDispatcher();
|
|
|
|
|
- const viewFragment = new ViewDocumentFragment( [
|
|
|
|
|
- new ViewContainerElement( 'p' ), new ViewText( 'foobar' )
|
|
|
|
|
- ] );
|
|
|
|
|
|
|
+ describe( 'conversionApi', () => {
|
|
|
|
|
+ let spy, spyP, spyText, viewP, viewText, modelP, modelText, consumableMock, dispatcher;
|
|
|
|
|
+ let spyNull, spyArray, viewDiv, viewNull, viewArray;
|
|
|
|
|
+
|
|
|
|
|
+ beforeEach( () => {
|
|
|
|
|
+ spy = sinon.spy();
|
|
|
|
|
+ spyP = sinon.spy();
|
|
|
|
|
+ spyText = sinon.spy();
|
|
|
|
|
+
|
|
|
|
|
+ viewP = new ViewContainerElement( 'p' );
|
|
|
|
|
+ viewText = new ViewText( 'foobar' );
|
|
|
|
|
+ modelP = new ModelElement( 'paragraph' );
|
|
|
|
|
+ modelText = new ModelText( 'foobar' );
|
|
|
|
|
+
|
|
|
|
|
+ consumableMock = {};
|
|
|
|
|
+
|
|
|
|
|
+ dispatcher = new ViewConversionDispatcher();
|
|
|
|
|
+
|
|
|
|
|
+ dispatcher.on( 'element:p', ( evt, data, consumable ) => {
|
|
|
|
|
+ spyP();
|
|
|
|
|
|
|
|
- dispatcher.on( 'text', ( evt, data ) => {
|
|
|
|
|
- data.output = { text: data.input.data };
|
|
|
|
|
|
|
+ expect( data.foo ).to.equal( 'bar' );
|
|
|
|
|
+ expect( consumable ).to.equal( consumableMock );
|
|
|
|
|
+
|
|
|
|
|
+ data.output = modelP;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- dispatcher.on( 'element:p', ( evt, data ) => {
|
|
|
|
|
- data.output = { name: 'p' };
|
|
|
|
|
|
|
+ dispatcher.on( 'text', ( evt, data, consumable ) => {
|
|
|
|
|
+ spyText();
|
|
|
|
|
+
|
|
|
|
|
+ expect( data.foo ).to.equal( 'bar' );
|
|
|
|
|
+ expect( consumable ).to.equal( consumableMock );
|
|
|
|
|
+
|
|
|
|
|
+ data.output = modelText;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- dispatcher.on( 'documentFragment', ( evt, data, consumable, conversionApi ) => {
|
|
|
|
|
- data.output = [];
|
|
|
|
|
|
|
+ spyNull = sinon.spy();
|
|
|
|
|
+ spyArray = sinon.spy();
|
|
|
|
|
+
|
|
|
|
|
+ viewDiv = new ViewContainerElement( 'div' ); // Will not be recognized and not converted.
|
|
|
|
|
+ viewNull = new ViewContainerElement( 'null' ); // Will return `null` in `data.output` upon conversion.
|
|
|
|
|
+ viewArray = new ViewContainerElement( 'array' ); // Will return an array in `data.output` upon conversion.
|
|
|
|
|
|
|
|
- for ( let child of data.input.getChildren() ) {
|
|
|
|
|
- data.output.push( conversionApi.convertItem( child ) );
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ dispatcher.on( 'element:null', ( evt, data ) => {
|
|
|
|
|
+ spyNull();
|
|
|
|
|
+
|
|
|
|
|
+ data.output = null;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( dispatcher.convert( viewFragment ) ).to.deep.equal( [
|
|
|
|
|
- { name: 'p' },
|
|
|
|
|
- { text: 'foobar' }
|
|
|
|
|
- ] );
|
|
|
|
|
|
|
+ dispatcher.on( 'element:array', ( evt, data ) => {
|
|
|
|
|
+ spyArray();
|
|
|
|
|
+
|
|
|
|
|
+ data.output = [ new ModelText( 'foo' ) ];
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
- } );
|
|
|
|
|
|
|
|
|
|
- describe( 'conversionApi#convertChildren', () => {
|
|
|
|
|
- it( 'should fire proper events for all children of passed view part', () => {
|
|
|
|
|
- const dispatcher = new ViewConversionDispatcher();
|
|
|
|
|
- const viewFragment = new ViewDocumentFragment( [
|
|
|
|
|
- new ViewContainerElement( 'p' ), new ViewText( 'foobar' )
|
|
|
|
|
- ] );
|
|
|
|
|
|
|
+ describe( 'convertItem', () => {
|
|
|
|
|
+ it( 'should pass consumable and additional data to proper converter and return data.output', () => {
|
|
|
|
|
+ silenceWarnings();
|
|
|
|
|
|
|
|
- dispatcher.on( 'text', ( evt, data ) => {
|
|
|
|
|
- data.output = { text: data.input.data };
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ dispatcher.on( 'documentFragment', ( evt, data, consumable, conversionApi ) => {
|
|
|
|
|
+ spy();
|
|
|
|
|
+
|
|
|
|
|
+ expect( conversionApi.convertItem( viewP, consumableMock, data ) ).to.equal( modelP );
|
|
|
|
|
+ expect( conversionApi.convertItem( viewText, consumableMock, data ) ).to.equal( modelText );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ dispatcher.convert( new ViewDocumentFragment(), { foo: 'bar' } );
|
|
|
|
|
|
|
|
- dispatcher.on( 'element:p', ( evt, data ) => {
|
|
|
|
|
- data.output = { name: 'p' };
|
|
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( spyP.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( spyText.calledOnce ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- dispatcher.on( 'documentFragment', ( evt, data, consumable, conversionApi ) => {
|
|
|
|
|
- data.output = conversionApi.convertChildren( data.input );
|
|
|
|
|
|
|
+ it( 'should return null if element was not converted and log a warning', () => {
|
|
|
|
|
+ sinon.spy( log, 'warn' );
|
|
|
|
|
+
|
|
|
|
|
+ dispatcher.on( 'documentFragment', ( evt, data, consumable, conversionApi ) => {
|
|
|
|
|
+ spy();
|
|
|
|
|
+
|
|
|
|
|
+ expect( conversionApi.convertItem( viewDiv ) ).to.equal( null );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ dispatcher.convert( new ViewDocumentFragment() );
|
|
|
|
|
+
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( log.warn.calledOnce );
|
|
|
|
|
+
|
|
|
|
|
+ log.warn.restore();
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( dispatcher.convert( viewFragment ) ).to.deep.equal( [
|
|
|
|
|
- { name: 'p' },
|
|
|
|
|
- { text: 'foobar' }
|
|
|
|
|
- ] );
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ it( 'should return null if element was incorrectly converted and log a warning', () => {
|
|
|
|
|
+ sinon.spy( log, 'warn' );
|
|
|
|
|
+
|
|
|
|
|
+ dispatcher.on( 'documentFragment', ( evt, data, consumable, conversionApi ) => {
|
|
|
|
|
+ spy();
|
|
|
|
|
+
|
|
|
|
|
+ expect( conversionApi.convertItem( viewArray ) ).to.equal( null );
|
|
|
|
|
+ expect( conversionApi.convertItem( viewNull ) ).to.equal( null );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- it( 'should flatten structure of non-converted elements', () => {
|
|
|
|
|
- const dispatcher = new ViewConversionDispatcher();
|
|
|
|
|
|
|
+ dispatcher.convert( new ViewDocumentFragment() );
|
|
|
|
|
|
|
|
- dispatcher.on( 'text', ( evt, data ) => {
|
|
|
|
|
- data.output = data.input.data;
|
|
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( spyArray.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( spyNull.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( log.warn.calledOnce );
|
|
|
|
|
+
|
|
|
|
|
+ log.warn.restore();
|
|
|
} );
|
|
} );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- dispatcher.on( 'element', ( evt, data, consumable, conversionApi ) => {
|
|
|
|
|
- data.output = conversionApi.convertChildren( data.input, consumable );
|
|
|
|
|
|
|
+ describe( 'convertChildren', () => {
|
|
|
|
|
+ it( 'should fire conversion for all children of passed element and return conversion results wrapped in document fragment', () => {
|
|
|
|
|
+ silenceWarnings();
|
|
|
|
|
+
|
|
|
|
|
+ dispatcher.on( 'documentFragment', ( evt, data, consumable, conversionApi ) => {
|
|
|
|
|
+ spy();
|
|
|
|
|
+
|
|
|
|
|
+ const result = conversionApi.convertChildren( data.input, consumableMock, data );
|
|
|
|
|
+
|
|
|
|
|
+ expect( result ).to.be.instanceof( ModelDocumentFragment );
|
|
|
|
|
+ expect( result.childCount ).to.equal( 2 );
|
|
|
|
|
+ expect( result.getChild( 0 ) ).to.equal( modelP );
|
|
|
|
|
+ expect( result.getChild( 1 ) ).to.equal( modelText );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ dispatcher.convert( new ViewDocumentFragment( [ viewP, viewText ] ), { foo: 'bar' } );
|
|
|
|
|
+
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( spyP.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( spyText.calledOnce ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- const viewStructure = new ViewContainerElement( 'div', null, [
|
|
|
|
|
- new ViewContainerElement( 'p', null, [
|
|
|
|
|
- new ViewContainerElement( 'span', { class: 'nice' }, [
|
|
|
|
|
- new ViewAttributeElement( 'a', { href: 'foo.html' }, new ViewText( 'foo' ) ),
|
|
|
|
|
- new ViewText( ' bar ' ),
|
|
|
|
|
- new ViewAttributeElement( 'i', null, new ViewText( 'xyz' ) )
|
|
|
|
|
- ] )
|
|
|
|
|
- ] ),
|
|
|
|
|
- new ViewContainerElement( 'p', null, [
|
|
|
|
|
- new ViewAttributeElement( 'strong', null, [
|
|
|
|
|
- new ViewText( 'aaa ' ),
|
|
|
|
|
- new ViewAttributeElement( 'span', null, new ViewText( 'bbb' ) ),
|
|
|
|
|
- new ViewText( ' ' ),
|
|
|
|
|
- new ViewAttributeElement( 'a', { href: 'bar.html' }, new ViewText( 'ccc' ) )
|
|
|
|
|
- ] )
|
|
|
|
|
- ] )
|
|
|
|
|
- ] );
|
|
|
|
|
-
|
|
|
|
|
- expect( dispatcher.convert( viewStructure ) ).to.deep.equal( [ 'foo', ' bar ', 'xyz', 'aaa ', 'bbb', ' ', 'ccc' ] );
|
|
|
|
|
|
|
+ it( 'should filter out incorrectly converted elements and log warnings', () => {
|
|
|
|
|
+ dispatcher.on( 'documentFragment', ( evt, data, consumable, conversionApi ) => {
|
|
|
|
|
+ spy();
|
|
|
|
|
+
|
|
|
|
|
+ const result = conversionApi.convertChildren( data.input, consumableMock, data );
|
|
|
|
|
+
|
|
|
|
|
+ expect( result ).to.be.instanceof( ModelDocumentFragment );
|
|
|
|
|
+ expect( result.childCount ).to.equal( 2 );
|
|
|
|
|
+ expect( result.getChild( 0 ) ).to.equal( modelP );
|
|
|
|
|
+ expect( result.getChild( 1 ) ).to.equal( modelText );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ dispatcher.convert( new ViewDocumentFragment( [ viewArray, viewP, viewDiv, viewText, viewNull ] ), { foo: 'bar' } );
|
|
|
|
|
+
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( spyNull.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( spyArray.calledOnce ).to.be.true;
|
|
|
|
|
+ expect( log.warn.calledThirce );
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
+
|
|
|
|
|
+ // Silences warnings that pop up in tests. Use when the test checks a specific functionality and we are not interested in those logs.
|
|
|
|
|
+ // No need to restore `log.warn` - it is done in `afterEach()`.
|
|
|
|
|
+ function silenceWarnings() {
|
|
|
|
|
+ log.warn = () => {};
|
|
|
|
|
+ }
|
|
|
} );
|
|
} );
|