8
0

filedialogbuttonview.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. 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. 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[ 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. describe( 'focus()', () => {
  54. it( 'should focus view#buttonView', () => {
  55. const spy = sinon.spy( view.buttonView, 'focus' );
  56. view.focus();
  57. sinon.assert.calledOnce( spy );
  58. } );
  59. } );
  60. } );