|
@@ -70,13 +70,15 @@ describe( 'DecoupledEditor', () => {
|
|
|
|
|
|
|
|
class AsyncDataInit extends Plugin {
|
|
class AsyncDataInit extends Plugin {
|
|
|
init() {
|
|
init() {
|
|
|
- this.editor.on( 'dataReady', () => spy( 'dataReady' ) );
|
|
|
|
|
|
|
+ this.editor.data.on( 'ready', () => spy( 'ready' ) );
|
|
|
|
|
|
|
|
this.editor.data.on( 'init', evt => {
|
|
this.editor.data.on( 'init', evt => {
|
|
|
evt.stop();
|
|
evt.stop();
|
|
|
evt.return = new Promise( resolve => {
|
|
evt.return = new Promise( resolve => {
|
|
|
resolver = () => {
|
|
resolver = () => {
|
|
|
spy( 'asyncInit' );
|
|
spy( 'asyncInit' );
|
|
|
|
|
+ // Since we stop `init` event, `data#ready` needs to be fired manually.
|
|
|
|
|
+ this.editor.data.fire( 'ready' );
|
|
|
resolve();
|
|
resolve();
|
|
|
};
|
|
};
|
|
|
} );
|
|
} );
|
|
@@ -88,7 +90,7 @@ describe( 'DecoupledEditor', () => {
|
|
|
plugins: [ Paragraph, Bold, AsyncDataInit ]
|
|
plugins: [ Paragraph, Bold, AsyncDataInit ]
|
|
|
} ).then( editor => {
|
|
} ).then( editor => {
|
|
|
sinon.assert.calledWith( spy.firstCall, 'asyncInit' );
|
|
sinon.assert.calledWith( spy.firstCall, 'asyncInit' );
|
|
|
- sinon.assert.calledWith( spy.secondCall, 'dataReady' );
|
|
|
|
|
|
|
+ sinon.assert.calledWith( spy.secondCall, 'ready' );
|
|
|
|
|
|
|
|
editor.destroy().then( done );
|
|
editor.destroy().then( done );
|
|
|
} );
|
|
} );
|
|
@@ -187,14 +189,13 @@ describe( 'DecoupledEditor', () => {
|
|
|
const fired = [];
|
|
const fired = [];
|
|
|
|
|
|
|
|
function spy( evt ) {
|
|
function spy( evt ) {
|
|
|
- fired.push( evt.name );
|
|
|
|
|
|
|
+ fired.push( `${ evt.name }-${ evt.source.constructor.name.toLowerCase() }` );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class EventWatcher extends Plugin {
|
|
class EventWatcher extends Plugin {
|
|
|
init() {
|
|
init() {
|
|
|
- this.editor.on( 'pluginsReady', spy );
|
|
|
|
|
this.editor.ui.on( 'ready', spy );
|
|
this.editor.ui.on( 'ready', spy );
|
|
|
- this.editor.on( 'dataReady', spy );
|
|
|
|
|
|
|
+ this.editor.data.on( 'ready', spy );
|
|
|
this.editor.on( 'ready', spy );
|
|
this.editor.on( 'ready', spy );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -204,29 +205,11 @@ describe( 'DecoupledEditor', () => {
|
|
|
plugins: [ EventWatcher ]
|
|
plugins: [ EventWatcher ]
|
|
|
} )
|
|
} )
|
|
|
.then( newEditor => {
|
|
.then( newEditor => {
|
|
|
- expect( fired ).to.deep.equal( [ 'pluginsReady', 'ready', 'dataReady', 'ready' ] );
|
|
|
|
|
-
|
|
|
|
|
- return newEditor.destroy();
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'fires dataReady once data is loaded', () => {
|
|
|
|
|
- let data;
|
|
|
|
|
-
|
|
|
|
|
- class EventWatcher extends Plugin {
|
|
|
|
|
- init() {
|
|
|
|
|
- this.editor.on( 'dataReady', () => {
|
|
|
|
|
- data = this.editor.getData();
|
|
|
|
|
- } );
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return DecoupledEditor
|
|
|
|
|
- .create( getElementOrData(), {
|
|
|
|
|
- plugins: [ EventWatcher, Paragraph, Bold ]
|
|
|
|
|
- } )
|
|
|
|
|
- .then( newEditor => {
|
|
|
|
|
- expect( data ).to.equal( '<p><strong>foo</strong> bar</p>' );
|
|
|
|
|
|
|
+ expect( fired ).to.deep.equal( [
|
|
|
|
|
+ 'ready-decouplededitorui',
|
|
|
|
|
+ 'ready-datacontroller',
|
|
|
|
|
+ 'ready-decouplededitor'
|
|
|
|
|
+ ] );
|
|
|
|
|
|
|
|
return newEditor.destroy();
|
|
return newEditor.destroy();
|
|
|
} );
|
|
} );
|