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

Merge pull request #78 from ckeditor/t/77

Fix: Fixed incorrect `ImageUploadButton` and `ImageUploadCommand` binding. Closes #77. Closes https://github.com/ckeditor/ckeditor5-ui/issues/357.
Piotr Jasiun 8 лет назад
Родитель
Сommit
4cd952ba35

+ 1 - 1
packages/ckeditor5-upload/src/imageuploadbutton.js

@@ -50,7 +50,7 @@ export default class ImageUploadButton extends Plugin {
 				tooltip: true
 			} );
 
-			view.bind( 'isEnabled' ).to( command );
+			view.buttonView.bind( 'isEnabled' ).to( command );
 
 			view.on( 'done', ( evt, files ) => {
 				for ( const file of Array.from( files ) ) {

+ 20 - 3
packages/ckeditor5-upload/tests/imageuploadbutton.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals document */
+/* globals document, Event */
 
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
 
@@ -71,11 +71,28 @@ describe( 'ImageUploadButton', () => {
 
 		command.isEnabled = true;
 
-		expect( button.isEnabled ).to.true;
+		expect( button.buttonView.isEnabled ).to.true;
 
 		command.isEnabled = false;
 
-		expect( button.isEnabled ).to.false;
+		expect( button.buttonView.isEnabled ).to.false;
+	} );
+
+	// ckeditor5-upload/#77
+	it( 'should be properly bound with ImageUploadCommand', () => {
+		const button = editor.ui.componentFactory.create( 'insertImage' );
+		const command = editor.commands.get( 'imageUpload' );
+		const spy = sinon.spy();
+
+		button.render();
+
+		button.buttonView.on( 'execute', spy );
+
+		command.isEnabled = false;
+
+		button.buttonView.element.dispatchEvent( new Event( 'click' ) );
+
+		sinon.assert.notCalled( spy );
 	} );
 
 	it( 'should execute imageUpload command', () => {