Răsfoiți Sursa

Added support for the `config.initialData` option in `ClassicTestEditor` and `VirtualTestEditor`.

Maciej Bukowski 6 ani în urmă
părinte
comite
00dba1ecc6

+ 19 - 0
packages/ckeditor5-core/tests/_utils-tests/classictesteditor.js

@@ -10,6 +10,7 @@ import ClassicTestEditor from '../../tests/_utils/classictesteditor';
 
 import Plugin from '../../src/plugin';
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 
 import EditorUI from '../../src/editor/editorui';
 import BoxedEditorUIView from '@ckeditor/ckeditor5-ui/src/editorui/boxed/boxededitoruiview';
@@ -175,6 +176,24 @@ describe( 'ClassicTestEditor', () => {
 					return editor.destroy();
 				} );
 		} );
+
+		it( 'initializes the data with `config.initialData` if this option is provided', () => {
+			return ClassicTestEditor.create( editorElement, { initialData: '<p>foo</p>', plugins: [ Paragraph ] } )
+				.then( editor => {
+					expect( editor.getData() ).to.equal( '<p>foo</p>' );
+
+					return editor.destroy();
+				} );
+		} );
+
+		it( 'initializes the data with an empty string if the `config.initialData` is not provided', () => {
+			return ClassicTestEditor.create( editorElement )
+				.then( editor => {
+					expect( editor.getData() ).to.equal( '' );
+
+					return editor.destroy();
+				} );
+		} );
 	} );
 
 	describe( 'destroy()', () => {

+ 15 - 0
packages/ckeditor5-core/tests/_utils-tests/virtualtesteditor.js

@@ -9,6 +9,7 @@ import VirtualTestEditor from '../../tests/_utils/virtualtesteditor';
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
 import DataApiMixin from '../../src/editor/utils/dataapimixin';
 import RootElement from '@ckeditor/ckeditor5-engine/src/model/rootelement';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 
 import testUtils from '../../tests/_utils/utils';
 
@@ -33,5 +34,19 @@ describe( 'VirtualTestEditor', () => {
 		it( 'mixes DataApiMixin', () => {
 			expect( testUtils.isMixed( VirtualTestEditor, DataApiMixin ) ).to.true;
 		} );
+
+		it( 'supports `config.initialData`', () => {
+			return VirtualTestEditor.create( { initialData: '<p>foo</p>', plugins: [ Paragraph ] } )
+				.then( editor => {
+					expect( editor.getData() ).to.equal( '<p>foo</p>' );
+				} );
+		} );
+
+		it( 'initializes an empty editor if the `config.initialData` is not provided', () => {
+			return VirtualTestEditor.create()
+				.then( editor => {
+					expect( editor.getData() ).to.equal( '' );
+				} );
+		} );
 	} );
 } );

+ 2 - 2
packages/ckeditor5-core/tests/_utils/classictesteditor.js

@@ -54,7 +54,7 @@ export default class ClassicTestEditor extends Editor {
 	/**
 	 * @inheritDoc
 	 */
-	static create( element, config ) {
+	static create( element, config = {} ) {
 		return new Promise( resolve => {
 			const editor = new this( element, config );
 
@@ -64,7 +64,7 @@ export default class ClassicTestEditor extends Editor {
 					// should be rendered after plugins are initialized.
 					.then( () => editor.ui.init( element ) )
 					.then( () => editor.editing.view.attachDomRoot( editor.ui.getEditableElement() ) )
-					.then( () => editor.data.init( getDataFromElement( element ) ) )
+					.then( () => editor.data.init( config.initialData || getDataFromElement( element ) ) )
 					.then( () => {
 						editor.state = 'ready';
 						editor.fire( 'ready' );

+ 3 - 1
packages/ckeditor5-core/tests/_utils/virtualtesteditor.js

@@ -27,13 +27,15 @@ export default class VirtualTestEditor extends Editor {
 		this.model.document.createRoot();
 	}
 
-	static create( config ) {
+	static create( config = {} ) {
 		return new Promise( resolve => {
 			const editor = new this( config );
 
 			resolve(
 				editor.initPlugins()
 					.then( () => {
+						editor.data.init( config.initialData || '' );
+
 						// Fire `data#ready` event manually as `data#init()` method is not used.
 						editor.data.fire( 'ready' );
 						editor.fire( 'ready' );