8
0

filedialogbuttonview.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  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. view.render();
  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[ 0 ] );
  23. } );
  24. it( 'should open file dialog on execute', () => {
  25. const spy = sinon.spy( view._fileInputView, 'open' );
  26. const stub = sinon.stub( view._fileInputView.element, 'click' );
  27. view.buttonView.fire( 'execute' );
  28. sinon.assert.calledOnce( spy );
  29. stub.restore();
  30. } );
  31. } );
  32. describe( 'file dialog', () => {
  33. it( 'should be rendered', () => {
  34. expect( view._fileInputView ).to.instanceof( View );
  35. expect( view._fileInputView ).to.equal( view.template.children[ 1 ] );
  36. } );
  37. it( 'should be bound to view#acceptedType', () => {
  38. view.set( { acceptedType: 'audio/*' } );
  39. expect( view._fileInputView.acceptedType ).to.equal( 'audio/*' );
  40. } );
  41. it( 'should be bound to view#allowMultipleFiles', () => {
  42. view.set( { allowMultipleFiles: true } );
  43. expect( view._fileInputView.allowMultipleFiles ).to.be.true;
  44. } );
  45. it( 'should delegate done event to view', () => {
  46. const spy = sinon.spy();
  47. const files = [];
  48. view.on( 'done', spy );
  49. view._fileInputView.fire( 'done', files );
  50. sinon.assert.calledOnce( spy );
  51. expect( spy.lastCall.args[ 1 ] ).to.equal( files );
  52. } );
  53. } );
  54. } );
  55. describe( 'focus()', () => {
  56. it( 'should focus view#buttonView', () => {
  57. const spy = sinon.spy( view.buttonView, 'focus' );
  58. view.focus();
  59. sinon.assert.calledOnce( spy );
  60. } );
  61. } );
  62. } );