Explorar o código

Tests and minor changes in the docs and API.

Piotrek Koszuliński %!s(int64=9) %!d(string=hai) anos
pai
achega
c51076e49c

+ 8 - 5
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -15,7 +15,7 @@ import Toolbar from '../ui/bindings/toolbar.js';
 import StickyToolbarView from '../ui/stickytoolbar/stickytoolbarview.js';
 
 /**
- * Classic editor. Uses inline editable and sticky toolbar, all
+ * Classic editor UI. Uses inline editable and sticky toolbar, all
  * enclosed in a boxed UI.
  *
  * @memberOf editor-classic
@@ -42,21 +42,24 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 		 * Editable UI controller.
 		 *
 		 * @readonly
-		 * @member {ui.editableUI.EditableUI} editor-classic.ClassicEditorUI#editableUI
+		 * @member {ui.editableUI.EditableUI} editor-classic.ClassicEditorUI#editable
 		 */
-		this.editableUI = this._createEditableUI();
+		this.editable = this._createEditableUI();
 	}
 
 	/**
-	 * The HTML element which is editable (usually the one with `contentEditable=true`).
+	 * The editing host.
 	 *
 	 * @readonly
 	 * @type {HTMLElement}
 	 */
 	get editableElement() {
-		return this.editableUI.view.element;
+		return this.editable.view.element;
 	}
 
+	/**
+	 * @inheritDoc
+	 */
 	init() {
 		if ( this.editor.config.toolbar ) {
 			this.toolbar.addButtons( this.editor.config.toolbar );

+ 35 - 23
packages/ckeditor5-editor-classic/tests/classic.js

@@ -7,14 +7,9 @@
 
 'use strict';
 
-import BoxedEditorUI from '/ckeditor5/ui/editorui/boxed/boxededitorui.js';
+import ClassicEditorUI from '/ckeditor5/creator-classic/classiceditorui.js';
 import BoxedEditorUIView from '/ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
 
-// import EditableUI from '/ckeditor5/ui/editableui/editableui.js';
-// import InlineEditableUIView from '/ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
-
-// import StickyToolbarView from '/ckeditor5/ui/stickytoolbar/stickytoolbarview.js';
-
 import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
 
 import ClassicEditor from '/ckeditor5/creator-classic/classic.js';
@@ -38,23 +33,12 @@ describe( 'ClassicEditor', () => {
 		editorElement.remove();
 	} );
 
-	describe( 'create', () => {
-		beforeEach( function() {
-			return ClassicEditor.create( editorElement, {
-					features: [ 'paragraph', 'basic-styles/bold', 'basic-styles/italic' ],
-					toolbar: [ 'bold', 'italic' ]
-				} )
-				.then( newEditor => {
-					editor = newEditor;
-				} );
-		} );
-
-		it( 'creates an instance which inherits from the ClassicEditor', () => {
-			expect( editor ).to.be.instanceof( ClassicEditor );
+	describe( 'constructor', () => {
+		beforeEach( () => {
+			editor = new ClassicEditor( editorElement );
 		} );
 
 		it( 'creates a single div editable root in the view', () => {
-			expect( editor.editing.view.domRoots.size ).to.equal( 1 );
 			expect( editor.editing.view.getRoot() ).to.have.property( 'name', 'div' );
 		} );
 
@@ -64,16 +48,35 @@ describe( 'ClassicEditor', () => {
 		} );
 
 		it( 'creates the UI using BoxedEditorUI classes', () => {
-			expect( editor.ui ).to.be.instanceof( BoxedEditorUI );
+			expect( editor.ui ).to.be.instanceof( ClassicEditorUI );
 			expect( editor.ui.view ).to.be.instanceof( BoxedEditorUIView );
 		} );
 
+		it( 'uses HTMLDataProcessor', () => {
+			expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
+		} );
+	} );
+
+	describe( 'create', () => {
+		beforeEach( function() {
+			return ClassicEditor.create( editorElement, {
+					features: [ 'paragraph', 'basic-styles/bold' ]
+				} )
+				.then( newEditor => {
+					editor = newEditor;
+				} );
+		} );
+
+		it( 'creates an instance which inherits from the ClassicEditor', () => {
+			expect( editor ).to.be.instanceof( ClassicEditor );
+		} );
+
 		it( 'inserts editor UI next to editor element', () => {
 			expect( editor.ui.view.element.previousSibling ).to.equal( editorElement );
 		} );
 
-		it( 'uses HTMLDataProcessor', () => {
-			expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
+		it( 'attaches editable UI as view\'s DOM root', () => {
+			expect( editor.editing.view.getDomRoot() ).to.equal( editor.ui.editable.view.element );
 		} );
 
 		it( 'loads data from the editor element', () => {
@@ -97,5 +100,14 @@ describe( 'ClassicEditor', () => {
 					expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
 				} );
 		} );
+
+		it( 'restores the editor element', () => {
+			expect( editor.element.style.display ).to.equal( 'none' );
+
+			return editor.destroy()
+				.then( () => {
+					expect( editor.element.style.display ).to.equal( '' );
+				} );
+		} );
 	} );
 } );

+ 77 - 0
packages/ckeditor5-editor-classic/tests/classiceditorui.js

@@ -0,0 +1,77 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* bender-tags: editor, browser-only */
+
+'use strict';
+
+import ClassicEditorUI from '/ckeditor5/creator-classic/classiceditorui.js';
+import BoxedEditorUIView from '/ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
+
+import Toolbar from '/ckeditor5/ui/toolbar/toolbar.js';
+import StickyToolbarView from '/ckeditor5/ui/stickytoolbar/stickytoolbarview.js';
+
+import EditableUI from '/ckeditor5/ui/editableui/editableui.js';
+import InlineEditableUIView from '/ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
+
+import ClassicTestEditor from '/tests/ckeditor5/_utils/classictesteditor.js';
+
+describe( 'ClassicEditorUI', () => {
+	let editorElement, editor, editorUI;
+
+	beforeEach( () => {
+		editorElement = document.createElement( 'div' );
+		document.body.appendChild( editorElement );
+
+		editor = new ClassicTestEditor( editorElement );
+		editorUI = new ClassicEditorUI( editor );
+		editorUI.view = new BoxedEditorUIView( editorUI.viewModel, editor.locale );
+	} );
+
+	describe( 'constructor', () => {
+		it( 'creates toolbar', () => {
+			expect( editorUI.toolbar ).to.be.instanceof( Toolbar );
+			expect( editorUI.toolbar.view ).to.be.instanceof( StickyToolbarView );
+		} );
+
+		it( 'creates editable', () => {
+			expect( editorUI.editable ).to.be.instanceof( EditableUI );
+			expect( editorUI.editable.view ).to.be.instanceof( InlineEditableUIView );
+		} );
+	} );
+
+	describe( 'editableElement', () => {
+		it( 'returns editable\'s view element', () => {
+			document.body.appendChild( editorUI.view.element );
+
+			return editorUI.init()
+				.then( () => {
+					expect( editorUI.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
+				} );
+		} );
+	} );
+
+	describe( 'init', () => {
+		it( 'adds buttons', () => {
+			editor.config.set( 'toolbar', [ 'foo', 'bar' ] );
+
+			document.body.appendChild( editorUI.view.element );
+
+			const spy = sinon.stub( editorUI.toolbar, 'addButtons' );
+
+			return editorUI.init()
+				.then( () => {
+					expect( spy.calledOnce ).to.be.true;
+					expect( spy.args[ 0 ][ 0 ] ).to.deep.equal( [ 'foo', 'bar' ] );
+				} );
+		} );
+
+		it( 'returns a promise', () => {
+			document.body.appendChild( editorUI.view.element );
+
+			expect( editorUI.init() ).to.be.instanceof( Promise );
+		} );
+	} );
+} );