8
0
Quellcode durchsuchen

Merge pull request #22 from ckeditor/t/21

t/21: Alloweded simplified toolbar items creation by using a Model–driven dat…
Szymon Cofalik vor 9 Jahren
Ursprung
Commit
4bb7fb4c8a

+ 3 - 14
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -55,19 +55,6 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 		return this.editable.view.element;
 	}
 
-	/**
-	 * @inheritDoc
-	 */
-	init() {
-		const toolbar = this.editor.config.get( 'toolbar' );
-
-		if ( toolbar ) {
-			this.toolbar.addButtons( toolbar );
-		}
-
-		return super.init();
-	}
-
 	/**
 	 * Creates the sticky toolbar of the editor.
 	 *
@@ -76,8 +63,10 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 	 */
 	_createToolbar() {
 		const editor = this.editor;
+		const model = new Model( {
+			config: this.editor.config.get( 'toolbar' )
+		} );
 
-		const model = new Model();
 		model.bind( 'isActive' ).to( editor.editing.view.getRoot(), 'isFocused' );
 
 		const toolbar = new StickyToolbar( model, new StickyToolbarView( editor.locale ), editor );

+ 18 - 16
packages/ckeditor5-editor-classic/tests/classiceditorui.js

@@ -8,6 +8,10 @@
 import ClassicEditorUI from '/ckeditor5/editor-classic/classiceditorui.js';
 import BoxedEditorUIView from '/ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
 
+import Model from '/ckeditor5/ui/model.js';
+import Button from '/ckeditor5/ui/button/button.js';
+import ButtonView from '/ckeditor5/ui/button/buttonview.js';
+
 import Toolbar from '/ckeditor5/ui/toolbar/toolbar.js';
 import StickyToolbarView from '/ckeditor5/ui/toolbar/sticky/stickytoolbarview.js';
 
@@ -23,9 +27,15 @@ describe( 'ClassicEditorUI', () => {
 		editorElement = document.createElement( 'div' );
 		document.body.appendChild( editorElement );
 
-		editor = new ClassicTestEditor( editorElement );
-		editorUI = new ClassicEditorUI( editor );
+		editor = new ClassicTestEditor( editorElement, {
+			toolbar: [ 'foo', 'bar' ]
+		} );
+
+		editor.ui = editorUI = new ClassicEditorUI( editor );
 		editorUI.view = new BoxedEditorUIView( editor.locale );
+
+		editorUI.featureComponents.add( 'foo', Button, ButtonView, new Model( {} ) );
+		editorUI.featureComponents.add( 'bar', Button, ButtonView, new Model( {} ) );
 	} );
 
 	describe( 'constructor', () => {
@@ -52,24 +62,16 @@ describe( 'ClassicEditorUI', () => {
 	} );
 
 	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 );
 		} );
 	} );
+
+	describe( '_createToolbar', () => {
+		it( 'passes toolbar config to the model', () => {
+			expect( editorUI.toolbar.model.config ).to.have.members( [ 'foo', 'bar' ] );
+		} );
+	} );
 } );