8
0

mocks.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. type: 'image/jpeg',
  7. size: 1024
  8. } );
  9. export class AdapterMock {
  10. constructor( loader ) {
  11. this.loader = loader;
  12. }
  13. upload() {
  14. return new Promise( ( resolve, reject ) => {
  15. this._resolveCallback = resolve;
  16. this._rejectCallback = reject;
  17. } );
  18. }
  19. abort() {
  20. this._rejectCallback( 'aborted' );
  21. }
  22. mockError( error ) {
  23. this._rejectCallback( error );
  24. }
  25. mockSuccess( data ) {
  26. this._resolveCallback( data );
  27. }
  28. mockProgress( uploaded, total ) {
  29. this.loader.uploaded = uploaded;
  30. this.loader.uploadTotal = total;
  31. }
  32. }
  33. export class NativeFileReaderMock {
  34. readAsDataURL() {}
  35. abort() {
  36. this.mockAbort();
  37. }
  38. mockSuccess( result ) {
  39. this.result = result;
  40. this.onload();
  41. }
  42. mockError( error ) {
  43. this.error = error;
  44. this.onerror();
  45. };
  46. mockAbort() {
  47. this.onabort();
  48. }
  49. mockProgress( progress ) {
  50. this.onprogress( { loaded: progress } );
  51. }
  52. }