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/classiceditor';
  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. view.destroy();
  24. expect( view.fileInputView.element.parentNode ).to.be.null;
  25. } );
  26. it( 'should open file dialog on execute', () => {
  27. const spy = sinon.spy( view.fileInputView, 'open' );
  28. view.fire( 'execute' );
  29. sinon.assert.calledOnce( spy );
  30. } );
  31. it( 'should pass acceptedType to input view', () => {
  32. view.set( { acceptedType: 'audio/*' } );
  33. expect( view.fileInputView.acceptedType ).to.equal( 'audio/*' );
  34. } );
  35. it( 'should pass allowMultipleFiles to input view', () => {
  36. view.set( { allowMultipleFiles: true } );
  37. expect( view.fileInputView.allowMultipleFiles ).to.be.true;
  38. } );
  39. it( 'should delegate input view done event', done => {
  40. const files = [];
  41. view.on( 'done', ( evt, data ) => {
  42. expect( data ).to.equal( files );
  43. done();
  44. } );
  45. view.fileInputView.fire( 'done', files );
  46. } );
  47. } );