From d3c9b2314d380f2a0018c8f403a4db1bac3a7328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Krzto=C5=84?= Date: Wed, 23 Jan 2019 13:46:32 +0100 Subject: [PATCH 1/3] Tests: Adjust unit tests to 'plugincollection#ready' event. --- tests/decouplededitor.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/decouplededitor.js b/tests/decouplededitor.js index c480d6c..9416b78 100644 --- a/tests/decouplededitor.js +++ b/tests/decouplededitor.js @@ -187,12 +187,12 @@ 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.plugins.on( 'ready', spy ); this.editor.ui.on( 'ready', spy ); this.editor.on( 'dataReady', spy ); this.editor.on( 'ready', spy ); @@ -204,7 +204,12 @@ describe( 'DecoupledEditor', () => { plugins: [ EventWatcher ] } ) .then( newEditor => { - expect( fired ).to.deep.equal( [ 'pluginsReady', 'ready', 'dataReady', 'ready' ] ); + expect( fired ).to.deep.equal( [ + 'ready-plugincollection', + 'ready-decouplededitorui', + 'dataReady-decouplededitor', + 'ready-decouplededitor' + ] ); return newEditor.destroy(); } ); From 8fb179de68349f0f16ae8da0b571b49816a4ec2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Krzto=C5=84?= Date: Thu, 24 Jan 2019 11:27:24 +0100 Subject: [PATCH 2/3] Adjustments to new data#ready event. --- src/decouplededitor.js | 5 +---- tests/decouplededitor.js | 32 ++++++-------------------------- tests/decouplededitorui.js | 1 - 3 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/decouplededitor.js b/src/decouplededitor.js index 3d99b93..3c47b68 100644 --- a/src/decouplededitor.js +++ b/src/decouplededitor.js @@ -197,10 +197,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 ) ); } ); diff --git a/tests/decouplededitor.js b/tests/decouplededitor.js index 9416b78..dec0365 100644 --- a/tests/decouplededitor.js +++ b/tests/decouplededitor.js @@ -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(); }; } ); @@ -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 ); } ); @@ -194,7 +196,7 @@ describe( 'DecoupledEditor', () => { init() { this.editor.plugins.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 ); } } @@ -207,7 +209,7 @@ describe( 'DecoupledEditor', () => { expect( fired ).to.deep.equal( [ 'ready-plugincollection', 'ready-decouplededitorui', - 'dataReady-decouplededitor', + 'ready-datacontroller', 'ready-decouplededitor' ] ); @@ -215,28 +217,6 @@ describe( 'DecoupledEditor', () => { } ); } ); - 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( '

foo bar

' ); - - return newEditor.destroy(); - } ); - } ); - it( 'fires ready once UI is rendered', () => { let isReady; diff --git a/tests/decouplededitorui.js b/tests/decouplededitorui.js index f72870f..8604032 100644 --- a/tests/decouplededitorui.js +++ b/tests/decouplededitorui.js @@ -209,7 +209,6 @@ class VirtualDecoupledTestEditor extends VirtualTestEditor { editor.initPlugins() .then( () => { editor.ui.init(); - editor.fire( 'dataReady' ); editor.fire( 'ready' ); } ) .then( () => editor ) From 52f0020fb75a307dc09b4b8c5543c98f60d24cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Krzto=C5=84?= Date: Mon, 28 Jan 2019 17:41:33 +0100 Subject: [PATCH 3/3] Tests: Adjustments. --- tests/decouplededitor.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/decouplededitor.js b/tests/decouplededitor.js index dec0365..f56a3a8 100644 --- a/tests/decouplededitor.js +++ b/tests/decouplededitor.js @@ -194,7 +194,6 @@ describe( 'DecoupledEditor', () => { class EventWatcher extends Plugin { init() { - this.editor.plugins.on( 'ready', spy ); this.editor.ui.on( 'ready', spy ); this.editor.data.on( 'ready', spy ); this.editor.on( 'ready', spy ); @@ -207,7 +206,6 @@ describe( 'DecoupledEditor', () => { } ) .then( newEditor => { expect( fired ).to.deep.equal( [ - 'ready-plugincollection', 'ready-decouplededitorui', 'ready-datacontroller', 'ready-decouplededitor'