Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit d231ea6

Browse files
author
Piotr Jasiun
authored
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.
2 parents e1cfc40 + 25a81bd commit d231ea6

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/imageuploadbutton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class ImageUploadButton extends Plugin {
5050
tooltip: true
5151
} );
5252

53-
view.bind( 'isEnabled' ).to( command );
53+
view.buttonView.bind( 'isEnabled' ).to( command );
5454

5555
view.on( 'done', ( evt, files ) => {
5656
for ( const file of Array.from( files ) ) {

tests/imageuploadbutton.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* For licensing, see LICENSE.md.
44
*/
55

6-
/* globals document */
6+
/* globals document, Event */
77

88
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
99

@@ -71,11 +71,28 @@ describe( 'ImageUploadButton', () => {
7171

7272
command.isEnabled = true;
7373

74-
expect( button.isEnabled ).to.true;
74+
expect( button.buttonView.isEnabled ).to.true;
7575

7676
command.isEnabled = false;
7777

78-
expect( button.isEnabled ).to.false;
78+
expect( button.buttonView.isEnabled ).to.false;
79+
} );
80+
81+
// ckeditor5-upload/#77
82+
it( 'should be properly bound with ImageUploadCommand', () => {
83+
const button = editor.ui.componentFactory.create( 'insertImage' );
84+
const command = editor.commands.get( 'imageUpload' );
85+
const spy = sinon.spy();
86+
87+
button.render();
88+
89+
button.buttonView.on( 'execute', spy );
90+
91+
command.isEnabled = false;
92+
93+
button.buttonView.element.dispatchEvent( new Event( 'click' ) );
94+
95+
sinon.assert.notCalled( spy );
7996
} );
8097

8198
it( 'should execute imageUpload command', () => {

0 commit comments

Comments
 (0)