8
0
Pārlūkot izejas kodu

Make BlockToolbar work with empty configuration.

Maciej Gołaszewski 6 gadi atpakaļ
vecāks
revīzija
5c419e0fe1

+ 1 - 1
packages/ckeditor5-ui/src/toolbar/block/blocktoolbar.js

@@ -149,7 +149,7 @@ export default class BlockToolbar extends Plugin {
 	 */
 	afterInit() {
 		const factory = this.editor.ui.componentFactory;
-		const config = this.editor.config.get( 'blockToolbar' );
+		const config = this.editor.config.get( 'blockToolbar' ) || [];
 
 		this.toolbarView.fillFromConfig( config, factory );
 

+ 23 - 0
packages/ckeditor5-ui/tests/toolbar/block/blocktoolbar.js

@@ -55,6 +55,17 @@ describe( 'BlockToolbar', () => {
 		expect( BlockToolbar.pluginName ).to.equal( 'BlockToolbar' );
 	} );
 
+	it( 'should work with empty config', async () => {
+		// Remove default editor instance.
+		await editor.destroy();
+
+		expect( async () => {
+			editor = await ClassicTestEditor.create( element, {
+				plugins: [ BlockToolbar ]
+			} );
+		} ).to.not.throw();
+	} );
+
 	describe( 'child views', () => {
 		describe( 'panelView', () => {
 			it( 'should create a view instance', () => {
@@ -213,6 +224,18 @@ describe( 'BlockToolbar', () => {
 
 				expect( blockToolbar.buttonView.tooltip ).to.be.false;
 			} );
+
+			it( 'should hide the #button if empty config was passed', async () => {
+				// Remove default editor instance.
+				await editor.destroy();
+
+				editor = await ClassicTestEditor.create( element, {
+					plugins: [ BlockToolbar ]
+				} );
+
+				const blockToolbar = editor.plugins.get( BlockToolbar );
+				expect( blockToolbar.buttonView.isVisible ).to.be.false;
+			} );
 		} );
 	} );