8
0

imageuploadbutton.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import Image from '@ckeditor/ckeditor5-image/src/image';
  8. import FileDialogButtonView from '../src/ui/filedialogbuttonview';
  9. import ImageUploadButton from '../src/imageuploadbutton';
  10. import ImageUploadEngine from '../src/imageuploadengine';
  11. import { createNativeFileMock } from './_utils/mocks';
  12. describe( 'ImageUploadButton', () => {
  13. let editor;
  14. beforeEach( () => {
  15. const editorElement = document.createElement( 'div' );
  16. document.body.appendChild( editorElement );
  17. return ClassicEditor.create( editorElement, {
  18. plugins: [ Image, ImageUploadButton ]
  19. } )
  20. .then( newEditor => {
  21. editor = newEditor;
  22. } );
  23. } );
  24. it( 'should include ImageUploadEngine', () => {
  25. expect( editor.plugins.get( ImageUploadEngine ) ).to.be.instanceOf( ImageUploadEngine );
  26. } );
  27. it( 'should register insertImage button', () => {
  28. const button = editor.ui.componentFactory.create( 'insertImage' );
  29. expect( button ).to.be.instanceOf( FileDialogButtonView );
  30. } );
  31. it( 'should be disabled while ImageUploadCommand is disabled', () => {
  32. const button = editor.ui.componentFactory.create( 'insertImage' );
  33. const command = editor.commands.get( 'imageUpload' );
  34. command.isEnabled = true;
  35. expect( button.isEnabled ).to.true;
  36. command.isEnabled = false;
  37. expect( button.isEnabled ).to.false;
  38. } );
  39. it( 'should execute imageUpload command', () => {
  40. const executeStub = sinon.stub( editor, 'execute' );
  41. const button = editor.ui.componentFactory.create( 'insertImage' );
  42. const files = [ createNativeFileMock() ];
  43. button.fire( 'done', files );
  44. sinon.assert.calledOnce( executeStub );
  45. expect( executeStub.firstCall.args[ 0 ] ).to.equal( 'imageUpload' );
  46. expect( executeStub.firstCall.args[ 1 ].file ).to.equal( files[ 0 ] );
  47. } );
  48. } );