filedialogbuttonview.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import FileDialogButtonView from '../../src/ui/filedialogbuttonview';
  6. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  7. import View from '@ckeditor/ckeditor5-ui/src/view';
  8. describe( 'FileDialogButtonView', () => {
  9. let view, localeMock;
  10. beforeEach( () => {
  11. localeMock = { t: val => val };
  12. view = new FileDialogButtonView( localeMock );
  13. return view.init();
  14. } );
  15. it( 'should be rendered from a template', () => {
  16. expect( view.element.classList.contains( 'ck-file-dialog-button' ) ).to.true;
  17. } );
  18. describe( 'child views', () => {
  19. describe( 'button view', () => {
  20. it( 'should be rendered', () => {
  21. expect( view.buttonView ).to.instanceof( ButtonView );
  22. expect( view.buttonView ).to.equal( view.template.children.get( 0 ) );
  23. } );
  24. it( 'should open file dialog on execute', () => {
  25. const spy = sinon.spy( view._fileInputView, 'open' );
  26. view.buttonView.fire( 'execute' );
  27. sinon.assert.calledOnce( spy );
  28. } );
  29. } );
  30. describe( 'file dialog', () => {
  31. it( 'should be rendered', () => {
  32. expect( view._fileInputView ).to.instanceof( View );
  33. expect( view._fileInputView ).to.equal( view.template.children.get( 1 ) );
  34. } );
  35. it( 'should be bound to view#acceptedType', () => {
  36. view.set( { acceptedType: 'audio/*' } );
  37. expect( view._fileInputView.acceptedType ).to.equal( 'audio/*' );
  38. } );
  39. it( 'should be bound to view#allowMultipleFiles', () => {
  40. view.set( { allowMultipleFiles: true } );
  41. expect( view._fileInputView.allowMultipleFiles ).to.be.true;
  42. } );
  43. it( 'should delegate done event to view', () => {
  44. const spy = sinon.spy();
  45. const files = [];
  46. view.on( 'done', spy );
  47. view._fileInputView.fire( 'done', files );
  48. sinon.assert.calledOnce( spy );
  49. expect( spy.lastCall.args[ 1 ] ).to.equal( files );
  50. } );
  51. } );
  52. } );
  53. } );