ソースを参照

Update test editors.

Piotr Jasiun 9 年 前
コミット
292c1659e0

+ 1 - 1
tests/_utils-tests/classictesteditor.js

@@ -38,7 +38,7 @@ describe( 'ClassicTestEditor', () => {
 			const editor = new ClassicTestEditor( { foo: 1 } );
 
 			expect( editor.document.getRoot() ).to.have.property( 'name', '$root' );
-			expect( editor.editing.view.getRoot() ).to.have.property( 'name', 'DIV' ); // See ckeditor5-engine#450.
+			expect( editor.editing.view.getRoot() ).to.have.property( 'name', 'div' );
 			expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
 		} );
 	} );

+ 0 - 22
tests/_utils-tests/virtualeditingcontroller.js

@@ -1,22 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-import Editor from '/ckeditor5/editor/editor.js';
-import VirtualEditingController from '/tests/ckeditor5/_utils/virtualeditingcontroller.js';
-
-describe( 'VirtualEditingController', () => {
-	describe( 'constructor', () => {
-		it( 'sets necessary properties', () => {
-			const editor = new Editor();
-			const controller = new VirtualEditingController( editor.document );
-
-			expect( controller ).to.have.property( 'model', editor.document );
-			expect( controller ).to.have.property( 'view' );
-			expect( controller ).to.have.property( 'modelToView' );
-		} );
-	} );
-} );

+ 18 - 38
tests/_utils-tests/virtualtesteditor.js

@@ -5,61 +5,41 @@
 
 'use strict';
 
-import Editor from '/ckeditor5/editor/editor.js';
+import StandardEditor from '/ckeditor5/editor/standardeditor.js';
 import VirtualTestEditor from '/tests/ckeditor5/_utils/virtualtesteditor.js';
-import VirtualEditingController from '/tests/ckeditor5/_utils/virtualeditingcontroller.js';
 import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
-import { getData, setData } from '/tests/engine/_utils/model.js';
+
+import testUtils from '/tests/ckeditor5/_utils/utils.js';
+
+testUtils.createSinonSandbox();
 
 describe( 'VirtualTestEditor', () => {
 	describe( 'constructor', () => {
 		it( 'creates an instance of editor', () => {
 			const editor = new VirtualTestEditor( { foo: 1 } );
 
-			expect( editor ).to.be.instanceof( Editor );
-		} );
-
-		it( 'sets necessary properties', () => {
-			const editor = new VirtualTestEditor( { foo: 1 } );
+			expect( editor ).to.be.instanceof( StandardEditor );
 
 			expect( editor.config.get( 'foo' ) ).to.equal( 1 );
-
-			expect( editor.editing ).to.be.instanceof( VirtualEditingController );
-			expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
 		} );
-	} );
 
-	describe( 'setData', () => {
-		let editor;
-
-		beforeEach( () => {
-			editor = new VirtualTestEditor();
-			editor.document.schema.allow( { name: '$text', inside: '$root' } );
-		} );
-
-		it( 'should set data', () => {
-			editor.document.createRoot();
-
-			editor.setData( 'foo' );
+		it( 'creates model and view roots', () => {
+			const editor = new VirtualTestEditor( { foo: 1 } );
 
-			expect( getData( editor.document, { rootName: 'main', withoutSelection: true } ) ).to.equal( 'foo' );
+			expect( editor.document.getRoot() ).to.have.property( 'name', '$root' );
+			expect( editor.editing.view.getRoot() ).to.have.property( 'name', 'div' );
+			expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
 		} );
 	} );
 
-	describe( 'getData', () => {
-		let editor;
-
-		beforeEach( () => {
-			editor = new VirtualTestEditor();
-			editor.document.schema.allow( { name: '$text', inside: '$root' } );
-		} );
-
-		it( 'should get data', () => {
-			editor.document.createRoot();
-
-			setData( editor.document, 'foo' );
+	describe( 'create', () => {
+		it( 'creates an instance of editor', () => {
+			return VirtualTestEditor.create( { foo: 1 } )
+				.then( editor => {
+					expect( editor ).to.be.instanceof( VirtualTestEditor );
 
-			expect( editor.getData() ).to.equal( 'foo' );
+					expect( editor.config.get( 'foo' ) ).to.equal( 1 );
+				} );
 		} );
 	} );
 } );

+ 6 - 35
tests/_utils/classictesteditor.js

@@ -25,15 +25,14 @@ export default class ClassicTestEditor extends StandardEditor {
 	constructor( element, config ) {
 		super( element, config );
 
-		const editableElement = document.createElement( 'div' );
-
-		document.body.appendChild( editableElement );
-
 		this.document.createRoot();
 
-		this.editing.createRoot( editableElement );
+		this.editing.createRoot( 'div' );
 
 		this.data.processor = new HtmlDataProcessor();
+
+		this.ui = new BoxedEditorUI( this );
+		this.ui.view = new BoxedEditorUIView( this.ui.viewModel, this.locale );
 	}
 
 	/**
@@ -52,39 +51,11 @@ export default class ClassicTestEditor extends StandardEditor {
 			const editor = new this( element, config );
 
 			resolve(
-				editor._createUI()
-					.then( () => editor.initPlugins() )
-					.then( () => editor._initUI() )
+				editor.initPlugins()
+					.then( () => editor.ui.init() )
 					.then( () => editor.loadDataFromEditorElement() )
 					.then( () => editor )
 			);
 		} );
 	}
-
-	/**
-	 * Creates boxed editor UI.
-	 *
-	 * @protected
-	 * @returns {Promise}
-	 */
-	_createUI() {
-		const editorUI = new BoxedEditorUI( this );
-		const editorUIView = new BoxedEditorUIView( editorUI.viewModel, this.locale );
-
-		editorUI.view = editorUIView;
-
-		this.ui = editorUI;
-
-		return Promise.resolve();
-	}
-
-	/**
-	 * Initilizes editor UI.
-	 *
-	 * @protected
-	 * @returns {Promise}
-	 */
-	_initUI() {
-		return this.ui.init();
-	}
 }

+ 0 - 31
tests/_utils/virtualeditingcontroller.js

@@ -1,31 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-import ModelConversionDispatcher from '/ckeditor5/engine/conversion/modelconversiondispatcher.js';
-import ViewDocument from '/ckeditor5/engine/view/document.js';
-
-/**
- * A simplified {@link engine.EditingController editing controller} which should be enough
- * to test engine part of features.
- *
- * Should work in Node.js. If not now, then in the future :).
- *
- * @memberOf tests.ckeditor5._utils
- */
-export default class VirtualEditingController {
-	constructor( model ) {
-		this.model = model;
-
-		this.view = new ViewDocument();
-
-		this.modelToView = new ModelConversionDispatcher( {
-			writer: this.view.writer,
-			mapper: this.mapper,
-			viewSelection: this.view.selection
-		} );
-	}
-}

+ 19 - 15
tests/_utils/virtualtesteditor.js

@@ -5,8 +5,7 @@
 
 'use strict';
 
-import Editor from '/ckeditor5/editor/editor.js';
-import VirtualEditingController from './virtualeditingcontroller.js';
+import StandardEditor from '/ckeditor5/editor/standardeditor.js';
 import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
 
 /**
@@ -17,27 +16,32 @@ import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor
  *
  * @memberOf tests.ckeditor5._utils
  */
-export default class VirtualTestEditor extends Editor {
+export default class VirtualTestEditor extends StandardEditor {
 	constructor( config ) {
-		super( config );
+		super( null, config );
+
+		this.document.createRoot();
+
+		this.editing.createRoot( 'div' );
 
-		this.editing = new VirtualEditingController( this.document );
 		this.data.processor = new HtmlDataProcessor();
 	}
 
 	/**
-	 * Sets the data in the editor's main root.
+	 * Creates a virtual, element-less editor instance.
 	 *
-	 * @param {*} data The data to load.
+	 * @param {Object} config See {@link ckeditor5.editor.StandardEditor}'s param.
+	 * @returns {Promise} Promise resolved once editor is ready.
+	 * @returns {ckeditor5.editor.VirtualTestEditor} return.editor The editor instance.
 	 */
-	setData( data ) {
-		this.data.set( data );
-	}
+	static create( config ) {
+		return new Promise( ( resolve ) => {
+			const editor = new this( config );
 
-	/**
-	 * Gets the data from the editor's main root.
-	 */
-	getData() {
-		return this.data.get();
+			resolve(
+				editor.initPlugins()
+					.then( () => editor )
+			);
+		} );
 	}
 }