filedialogbuttonview.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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
  14. .create( editorElement )
  15. .then( newEditor => {
  16. editor = newEditor;
  17. view = new FileDialogButtonView( editor.locale );
  18. } );
  19. } );
  20. it( 'should append input view to document body', () => {
  21. expect( view.fileInputView.element.parentNode ).to.equal( document.body );
  22. } );
  23. it( 'should remove input view from body after destroy', () => {
  24. view.destroy();
  25. expect( view.fileInputView.element.parentNode ).to.be.null;
  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. } );