mocks.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. export const createNativeFileMock = () => ( {
  6. size: 1024
  7. } );
  8. export class AdapterMock {
  9. constructor( loader ) {
  10. this.loader = loader;
  11. }
  12. upload() {
  13. return new Promise( ( resolve, reject ) => {
  14. this._resolveCallback = resolve;
  15. this._rejectCallback = reject;
  16. } );
  17. }
  18. abort() {
  19. this._rejectCallback( 'aborted' );
  20. }
  21. mockError( error ) {
  22. this._rejectCallback( error );
  23. }
  24. mockSuccess( data ) {
  25. this._resolveCallback( data );
  26. }
  27. mockProgress( uploaded, total ) {
  28. this.loader.uploaded = uploaded;
  29. this.loader.uploadTotal = total;
  30. }
  31. }
  32. export class NativeFileReaderMock {
  33. readAsDataURL() {}
  34. abort() {
  35. this.mockAbort();
  36. }
  37. mockSuccess( result ) {
  38. this.result = result;
  39. this.onload();
  40. }
  41. mockError( error ) {
  42. this.error = error;
  43. this.onerror();
  44. };
  45. mockAbort() {
  46. this.onabort();
  47. }
  48. mockProgress( progress ) {
  49. this.onprogress( { loaded: progress } );
  50. }
  51. }