From ea02023708a6421017e98aac2f150a987e4f3288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Mon, 16 Dec 2019 18:16:24 +0100 Subject: [PATCH 1/2] Make BlockToolbar work with empty configuration. --- src/toolbar/block/blocktoolbar.js | 2 +- tests/toolbar/block/blocktoolbar.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/toolbar/block/blocktoolbar.js b/src/toolbar/block/blocktoolbar.js index 5dead3ad..85074f65 100644 --- a/src/toolbar/block/blocktoolbar.js +++ b/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 ); diff --git a/tests/toolbar/block/blocktoolbar.js b/tests/toolbar/block/blocktoolbar.js index 2d92a82d..807b21cd 100644 --- a/tests/toolbar/block/blocktoolbar.js +++ b/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; + } ); } ); } ); From 53d35ffa30022b568d95effbcd7bf8cf44ceb2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 19 Dec 2019 16:33:54 +0100 Subject: [PATCH 2/2] Remove asynchronous test code from expect(). --- tests/toolbar/block/blocktoolbar.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/toolbar/block/blocktoolbar.js b/tests/toolbar/block/blocktoolbar.js index 807b21cd..0b50c94c 100644 --- a/tests/toolbar/block/blocktoolbar.js +++ b/tests/toolbar/block/blocktoolbar.js @@ -55,15 +55,13 @@ describe( 'BlockToolbar', () => { expect( BlockToolbar.pluginName ).to.equal( 'BlockToolbar' ); } ); - it( 'should work with empty config', async () => { + it( 'should not throw when empty config is provided', async () => { // Remove default editor instance. await editor.destroy(); - expect( async () => { - editor = await ClassicTestEditor.create( element, { - plugins: [ BlockToolbar ] - } ); - } ).to.not.throw(); + editor = await ClassicTestEditor.create( element, { + plugins: [ BlockToolbar ] + } ); } ); describe( 'child views', () => {