filedialogbuttonview.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 FileDialogButtonView from '../../src/ui/filedialogbuttonview';
  8. describe( 'FileDialogButtonView', () => {
  9. let view, editor;
  10. beforeEach( () => {
  11. const editorElement = document.createElement( 'div' );
  12. document.body.appendChild( editorElement );
  13. return ClassicEditor.create( editorElement )
  14. .then( newEditor => {
  15. editor = newEditor;
  16. view = new FileDialogButtonView( editor.locale );
  17. } );
  18. } );
  19. it( 'should append input view to document body', () => {
  20. expect( view.fileInputView.element.parentNode ).to.equal( document.body );
  21. } );
  22. it( 'should remove input view from body after destroy', () => {
  23. return view.destroy().then( () => {
  24. expect( view.fileInputView.element.parentNode ).to.be.null;
  25. } );
  26. } );
  27. it( 'should open file dialog on execute', () => {
  28. const spy = sinon.spy( view.fileInputView, 'open' );
  29. view.fire( 'execute' );
  30. sinon.assert.calledOnce( spy );
  31. } );
  32. it( 'should pass acceptedType to input view', () => {
  33. view.set( { acceptedType: 'audio/*' } );
  34. expect( view.fileInputView.acceptedType ).to.equal( 'audio/*' );
  35. } );
  36. it( 'should pass allowMultipleFiles to input view', () => {
  37. view.set( { allowMultipleFiles: true } );
  38. expect( view.fileInputView.allowMultipleFiles ).to.be.true;
  39. } );
  40. it( 'should delegate input view done event', done => {
  41. const files = [];
  42. view.on( 'done', ( evt, data ) => {
  43. expect( data ).to.equal( files );
  44. done();
  45. } );
  46. view.fileInputView.fire( 'done', files );
  47. } );
  48. } );