8
0
Просмотр исходного кода

Fix: Added missing return to the data initialization step.

Oskar Wróbel 7 лет назад
Родитель
Сommit
5a8035aa59

+ 1 - 1
packages/ckeditor5-editor-decoupled/src/decouplededitor.js

@@ -196,7 +196,7 @@ export default class DecoupledEditor extends Editor {
 						editor.fire( 'uiReady' );
 					} )
 					.then( () => {
-						editor.data.init( editor.element ? getDataFromElement( editor.element ) : elementOrData );
+						return editor.data.init( editor.element ? getDataFromElement( editor.element ) : elementOrData );
 					} )
 					.then( () => {
 						editor.fire( 'dataReady' );

+ 34 - 1
packages/ckeditor5-editor-decoupled/tests/decouplededitor.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals document */
+/* globals document, setTimeout */
 
 import DecoupledEditorUI from '../src/decouplededitorui';
 import DecoupledEditorUIView from '../src/decouplededitoruiview';
@@ -57,6 +57,39 @@ describe( 'DecoupledEditor', () => {
 	} );
 
 	describe( 'create()', () => {
+		it( 'should properly handled async data initialization', done => {
+			const spy = sinon.spy();
+			let resolver;
+
+			class AsyncDataInit extends Plugin {
+				init() {
+					this.editor.on( 'dataReady', () => spy( 'dataReady' ) );
+
+					this.editor.data.on( 'init', evt => {
+						evt.stop();
+						evt.return = new Promise( resolve => {
+							resolver = () => {
+								spy( 'asyncInit' );
+								resolve();
+							};
+						} );
+					}, { priority: 'high' } );
+				}
+			}
+
+			DecoupledEditor.create( '<p>foo bar</p>', {
+				plugins: [ Paragraph, Bold, AsyncDataInit ]
+			} ).then( editor => {
+				sinon.assert.calledWith( spy.firstCall, 'asyncInit' );
+				sinon.assert.calledWith( spy.secondCall, 'dataReady' );
+
+				editor.destroy().then( done );
+			} );
+
+			// Resolve init promise in next cycle to hold data initialization.
+			setTimeout( () => resolver() );
+		} );
+
 		describe( 'editor with data', () => {
 			test( () => editorData );
 		} );