imageuploadbutton.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/classic';
  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 execute imageUpload command', () => {
  32. const executeStub = sinon.stub( editor, 'execute' );
  33. const button = editor.ui.componentFactory.create( 'insertImage' );
  34. const files = [ createNativeFileMock() ];
  35. button.fire( 'done', files );
  36. sinon.assert.calledOnce( executeStub );
  37. expect( executeStub.firstCall.args[ 0 ] ).to.equal( 'imageUpload' );
  38. expect( executeStub.firstCall.args[ 1 ].file ).to.equal( files[ 0 ] );
  39. } );
  40. } );