Parcourir la source

Merge pull request #44 from ckeditor/t/43

t/43: Update ClassicTestEditor after bringing ClassicEditorUI "controller" back.
Piotrek Koszuliński il y a 9 ans
Parent
commit
731c4e1a28

+ 0 - 8
packages/ckeditor5-core/src/editor/editor.js

@@ -9,7 +9,6 @@ import PluginCollection from '../plugincollection.js';
 import Locale from '../../utils/locale.js';
 import DataController from '../../engine/controller/datacontroller.js';
 import Document from '../../engine/model/document.js';
-import FocusTracker from '../../utils/focustracker.js';
 
 import CKEditorError from '../../utils/ckeditorerror.js';
 import mix from '../../utils/mix.js';
@@ -84,13 +83,6 @@ export default class Editor {
 		this.data = new DataController( this.document );
 
 		/**
-		 * Keeps information about editor focus.
-		 *
-		 * @member {utils.FocusTracker} core.editor.Editor#focusTracker
-		 */
-		this.focusTracker = new FocusTracker();
-
-		/**
 		 * Instance of the {@link engine.controller.EditingController editing controller}.
 		 *
 		 * This property is set by more specialized editor classes (such as {@link core.editor.StandardEditor}),

+ 9 - 5
packages/ckeditor5-core/tests/_utils-tests/classictesteditor.js

@@ -7,9 +7,12 @@
 
 import StandardEditor from 'ckeditor5/core/editor/standardeditor.js';
 import ClassicTestEditor from 'tests/core/_utils/classictesteditor.js';
+
+import Feature from 'ckeditor5/core/feature.js';
 import HtmlDataProcessor from 'ckeditor5/engine/dataprocessor/htmldataprocessor.js';
+
+import ClassicTestEditorUI from 'tests/core/_utils/classictesteditorui.js';
 import BoxedEditorUIView from 'ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
-import Feature from 'ckeditor5/core/feature.js';
 
 import { getData } from 'ckeditor5/engine/dev-utils/model.js';
 import testUtils from 'tests/core/_utils/utils.js';
@@ -29,10 +32,10 @@ describe( 'ClassicTestEditor', () => {
 			const editor = new ClassicTestEditor( editorElement, { foo: 1 } );
 
 			expect( editor ).to.be.instanceof( StandardEditor );
-
 			expect( editor.config.get( 'foo' ) ).to.equal( 1 );
-			expect( editor ).to.have.property( 'element', editorElement );
-			expect( editor ).to.have.property( 'ui' ).to.instanceOf( BoxedEditorUIView );
+			expect( editor.element ).to.equal( editorElement );
+			expect( editor.ui ).to.be.instanceOf( ClassicTestEditorUI );
+			expect( editor.ui.view ).to.be.instanceOf( BoxedEditorUIView );
 		} );
 
 		it( 'creates model and view roots', () => {
@@ -58,7 +61,8 @@ describe( 'ClassicTestEditor', () => {
 		it( 'creates and initilizes the UI', () => {
 			return ClassicTestEditor.create( editorElement, { foo: 1 } )
 				.then( editor => {
-					expect( editor.ui ).to.be.instanceof( BoxedEditorUIView );
+					expect( editor.ui ).to.be.instanceOf( ClassicTestEditorUI );
+					expect( editor.ui.view ).to.be.instanceOf( BoxedEditorUIView );
 				} );
 		} );
 

+ 71 - 0
packages/ckeditor5-core/tests/_utils-tests/classictesteditorui.js

@@ -0,0 +1,71 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* bender-tags: editor, browser-only */
+
+import ComponentFactory from 'ckeditor5/ui/componentfactory.js';
+import FocusTracker from 'ckeditor5/utils/focustracker.js';
+import ClassicTestEditorUI from 'tests/core/_utils/classictesteditorui.js';
+import View from 'ckeditor5/ui/view.js';
+
+describe( 'ClassicTestEditorUI', () => {
+	let editor, view, ui;
+
+	beforeEach( () => {
+		editor = {};
+		view = new View();
+		ui = new ClassicTestEditorUI( editor, view );
+	} );
+
+	describe( 'constructor()', () => {
+		it( 'sets #editor', () => {
+			expect( ui.editor ).to.equal( editor );
+		} );
+
+		it( 'sets #view', () => {
+			expect( ui.view ).to.equal( view );
+		} );
+
+		it( 'creates #featureComponents factory', () => {
+			expect( ui.featureComponents ).to.be.instanceOf( ComponentFactory );
+		} );
+
+		it( 'creates #focusTracker', () => {
+			expect( ui.focusTracker ).to.be.instanceOf( FocusTracker );
+		} );
+	} );
+
+	describe( 'init()', () => {
+		it( 'returns a promise', () => {
+			expect( ui.init() ).to.be.instanceof( Promise );
+		} );
+
+		it( 'initializes the #view', () => {
+			const spy = sinon.spy( view, 'init' );
+
+			return ui.init().then( () => {
+				sinon.assert.calledOnce( spy );
+			} );
+		} );
+	} );
+
+	describe( 'destroy()', () => {
+		it( 'returns a promise', () => {
+			return ui.init().then( () => {
+				expect( ui.destroy() ).to.be.instanceof( Promise );
+			} );
+		} );
+
+		it( 'destroys the #view', () => {
+			const spy = sinon.spy( view, 'destroy' );
+
+			return ui.init()
+				.then( () => ui.destroy() )
+				.then( () => {
+					sinon.assert.calledOnce( spy );
+				} );
+		} );
+	} );
+} );

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

@@ -5,6 +5,7 @@
 
 import StandardEditor from 'ckeditor5/core/editor/standardeditor.js';
 import HtmlDataProcessor from 'ckeditor5/engine/dataprocessor/htmldataprocessor.js';
+import ClassicTestEditorUI from './classictesteditorui.js';
 import BoxedEditorUIView from 'ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
 
 /**
@@ -24,7 +25,7 @@ export default class ClassicTestEditor extends StandardEditor {
 		this.editing.createRoot( 'div' );
 		this.data.processor = new HtmlDataProcessor();
 
-		this.ui = new BoxedEditorUIView( this, this.locale );
+		this.ui = new ClassicTestEditorUI( this, new BoxedEditorUIView( this.locale ) );
 	}
 
 	/**

+ 72 - 0
packages/ckeditor5-core/tests/_utils/classictesteditorui.js

@@ -0,0 +1,72 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import ComponentFactory from 'ckeditor5/ui/componentfactory.js';
+import FocusTracker from 'ckeditor5/utils/focustracker.js';
+
+/**
+ * A simplified classic editor ui class. Useful for testing features.
+ *
+ * @memberOf tests.core._utils
+ * @extends ui.View
+ */
+export default class ClassicTestEditorUI {
+	/**
+	 * Creates an instance of the test editor UI class.
+	 *
+	 * @param {core.editor.Editor} editor The editor instance.
+	 * @param {ui.editorUI.EditorUIView} view View of the ui.
+	 */
+	constructor( editor, view ) {
+		/**
+		 * Editor that the UI belongs to.
+		 *
+		 * @readonly
+		 * @member {core.editor.Editor} tests.core._utils.ClassicTestEditorUI#editor
+		 */
+		this.editor = editor;
+
+		/**
+		 * View of the ui.
+		 *
+		 * @readonly
+		 * @member {ui.editorUI.EditorUIView} tests.core._utils.ClassicTestEditorUI#view
+		 */
+		this.view = view;
+
+		/**
+		 * Instance of the {@link ui.ComponentFactory}.
+		 *
+		 * @readonly
+		 * @member {ui.ComponentFactory} tests.core._utils.ClassicTestEditorUI#featureComponents
+		 */
+		this.featureComponents = new ComponentFactory( editor );
+
+		/**
+		 * Keeps information about editor focus.
+		 *
+		 * @member {utils.FocusTracker} tests.core._utils.ClassicTestEditorUI#focusTracker
+		 */
+		this.focusTracker = new FocusTracker();
+	}
+
+	/**
+	 * Initializes the UI.
+	 *
+	 * @returns {Promise} A Promise resolved when the initialization process is finished.
+	 */
+	init() {
+		return this.view.init();
+	}
+
+	/**
+	 * Destroys the UI.
+	 *
+	 * @returns {Promise} A Promise resolved when the destruction process is finished.
+	 */
+	destroy() {
+		return this.view.destroy();
+	}
+}

+ 0 - 2
packages/ckeditor5-core/tests/editor/editor.js

@@ -10,7 +10,6 @@ import Editor from 'ckeditor5/core/editor/editor.js';
 import Plugin from 'ckeditor5/core/plugin.js';
 import Config from 'ckeditor5/utils/config.js';
 import PluginCollection from 'ckeditor5/core/plugincollection.js';
-import FocusTracker from 'ckeditor5/utils/focustracker.js';
 
 class PluginA extends Plugin {
 	constructor( editor ) {
@@ -52,7 +51,6 @@ describe( 'Editor', () => {
 
 			expect( editor.config ).to.be.an.instanceof( Config );
 			expect( editor.commands ).to.be.an.instanceof( Map );
-			expect( editor.focusTracker ).to.instanceOf( FocusTracker );
 
 			expect( editor.plugins ).to.be.an.instanceof( PluginCollection );
 			expect( getPlugins( editor ) ).to.be.empty;