mocks.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if ( this.uploadStartedCallback ) {
  18. this.uploadStartedCallback();
  19. }
  20. } );
  21. }
  22. abort() {
  23. this._rejectCallback( 'aborted' );
  24. }
  25. mockError( error ) {
  26. this._rejectCallback( error );
  27. }
  28. mockSuccess( data ) {
  29. this._resolveCallback( data );
  30. }
  31. mockProgress( uploaded, total ) {
  32. this.loader.uploaded = uploaded;
  33. this.loader.uploadTotal = total;
  34. }
  35. }
  36. export class NativeFileReaderMock {
  37. readAsDataURL() {}
  38. abort() {
  39. this.mockAbort();
  40. }
  41. mockSuccess( result ) {
  42. this.result = result;
  43. this.onload();
  44. }
  45. mockError( error ) {
  46. this.error = error;
  47. this.onerror();
  48. }
  49. mockAbort() {
  50. this.onabort();
  51. }
  52. mockProgress( progress ) {
  53. this.onprogress( { loaded: progress } );
  54. }
  55. }