8
0
Просмотр исходного кода

Merge pull request #534 from ckeditor/i/5980

Fix: Make `BlockToolbar` work with an empty configuration. Closes ckeditor/ckeditor5#5980.
Piotrek Koszuliński 6 лет назад
Родитель
Сommit
c624c7a9d9

+ 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 );
 

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

@@ -55,6 +55,15 @@ describe( 'BlockToolbar', () => {
 		expect( BlockToolbar.pluginName ).to.equal( 'BlockToolbar' );
 	} );
 
+	it( 'should not throw when empty config is provided', async () => {
+		// Remove default editor instance.
+		await editor.destroy();
+
+		editor = await ClassicTestEditor.create( element, {
+			plugins: [ BlockToolbar ]
+		} );
+	} );
+
 	describe( 'child views', () => {
 		describe( 'panelView', () => {
 			it( 'should create a view instance', () => {
@@ -213,6 +222,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;
+			} );
 		} );
 	} );