Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into t/ckeditor5/479
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Jan 29, 2019
2 parents fdc6688 + 3bb0e40 commit 8049700
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
5 changes: 1 addition & 4 deletions src/decouplededitor.js
Expand Up @@ -198,10 +198,7 @@ export default class DecoupledEditor extends Editor {

return editor.data.init( initialData );
} )
.then( () => {
editor.fire( 'dataReady' );
editor.fire( 'ready' );
} )
.then( () => editor.fire( 'ready' ) )
.then( () => editor )
);
} );
Expand Down
39 changes: 11 additions & 28 deletions tests/decouplededitor.js
Expand Up @@ -70,13 +70,15 @@ describe( 'DecoupledEditor', () => {

class AsyncDataInit extends Plugin {
init() {
this.editor.on( 'dataReady', () => spy( 'dataReady' ) );
this.editor.data.on( 'ready', () => spy( 'ready' ) );

this.editor.data.on( 'init', evt => {
evt.stop();
evt.return = new Promise( resolve => {
resolver = () => {
spy( 'asyncInit' );
// Since we stop `init` event, `data#ready` needs to be fired manually.
this.editor.data.fire( 'ready' );
resolve();
};
} );
Expand All @@ -88,7 +90,7 @@ describe( 'DecoupledEditor', () => {
plugins: [ Paragraph, Bold, AsyncDataInit ]
} ).then( editor => {
sinon.assert.calledWith( spy.firstCall, 'asyncInit' );
sinon.assert.calledWith( spy.secondCall, 'dataReady' );
sinon.assert.calledWith( spy.secondCall, 'ready' );

editor.destroy().then( done );
} );
Expand Down Expand Up @@ -187,14 +189,13 @@ describe( 'DecoupledEditor', () => {
const fired = [];

function spy( evt ) {
fired.push( evt.name );
fired.push( `${ evt.name }-${ evt.source.constructor.name.toLowerCase() }` );
}

class EventWatcher extends Plugin {
init() {
this.editor.on( 'pluginsReady', spy );
this.editor.ui.on( 'ready', spy );
this.editor.on( 'dataReady', spy );
this.editor.data.on( 'ready', spy );
this.editor.on( 'ready', spy );
}
}
Expand All @@ -204,29 +205,11 @@ describe( 'DecoupledEditor', () => {
plugins: [ EventWatcher ]
} )
.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();
} );
Expand Down
1 change: 0 additions & 1 deletion tests/decouplededitorui.js
Expand Up @@ -262,7 +262,6 @@ class VirtualDecoupledTestEditor extends VirtualTestEditor {
editor.initPlugins()
.then( () => {
editor.ui.init();
editor.fire( 'dataReady' );
editor.fire( 'ready' );
} )
.then( () => editor )
Expand Down

0 comments on commit 8049700

Please sign in to comment.