Просмотр исходного кода

add _ to private methods in core, remove prefixes in core test names, remove update-meta event test

Artur Paikin 7 лет назад
Родитель
Сommit
e3495668c5
2 измененных файлов с 27 добавлено и 55 удалено
  1. 18 22
      src/core/Core.js
  2. 9 33
      src/core/Core.test.js

+ 18 - 22
src/core/Core.js

@@ -246,13 +246,22 @@ class Uppy {
     })
     })
   }
   }
 
 
+  /**
+   * Get a file object.
+   *
+   * @param {string} fileID The ID of the file object to return.
+   */
+  getFile (fileID) {
+    return this.getState().files[fileID]
+  }
+
   /**
   /**
   * Check if minNumberOfFiles restriction is reached before uploading
   * Check if minNumberOfFiles restriction is reached before uploading
   *
   *
   * @return {boolean}
   * @return {boolean}
   * @private
   * @private
   */
   */
-  checkMinNumberOfFiles () {
+  _checkMinNumberOfFiles () {
     const {minNumberOfFiles} = this.opts.restrictions
     const {minNumberOfFiles} = this.opts.restrictions
     if (Object.keys(this.getState().files).length < minNumberOfFiles) {
     if (Object.keys(this.getState().files).length < minNumberOfFiles) {
       this.info(`${this.i18n('youHaveToAtLeastSelectX', {smart_count: minNumberOfFiles})}`, 'error', 5000)
       this.info(`${this.i18n('youHaveToAtLeastSelectX', {smart_count: minNumberOfFiles})}`, 'error', 5000)
@@ -269,7 +278,7 @@ class Uppy {
   * @return {boolean}
   * @return {boolean}
   * @private
   * @private
   */
   */
-  checkRestrictions (file) {
+  _checkRestrictions (file) {
     const {maxFileSize, maxNumberOfFiles, allowedFileTypes} = this.opts.restrictions
     const {maxFileSize, maxNumberOfFiles, allowedFileTypes} = this.opts.restrictions
 
 
     if (maxNumberOfFiles) {
     if (maxNumberOfFiles) {
@@ -355,7 +364,7 @@ class Uppy {
           preview: file.preview
           preview: file.preview
         }
         }
 
 
-        const isFileAllowed = this.checkRestrictions(newFile)
+        const isFileAllowed = this._checkRestrictions(newFile)
         if (!isFileAllowed) return Promise.reject(new Error('File not allowed'))
         if (!isFileAllowed) return Promise.reject(new Error('File not allowed'))
 
 
         updatedFiles[fileID] = newFile
         updatedFiles[fileID] = newFile
@@ -393,15 +402,6 @@ class Uppy {
     this.log(`Removed file: ${fileID}`)
     this.log(`Removed file: ${fileID}`)
   }
   }
 
 
-  /**
-   * Get a file object.
-   *
-   * @param {string} fileID The ID of the file object to return.
-   */
-  getFile (fileID) {
-    return this.getState().files[fileID]
-  }
-
   /**
   /**
    * Generate a preview image for the given file, if possible.
    * Generate a preview image for the given file, if possible.
    */
    */
@@ -513,7 +513,7 @@ class Uppy {
     this.emit('retry-all', filesToRetry)
     this.emit('retry-all', filesToRetry)
 
 
     const uploadID = this.createUpload(filesToRetry)
     const uploadID = this.createUpload(filesToRetry)
-    return this.runUpload(uploadID)
+    return this._runUpload(uploadID)
   }
   }
 
 
   retryUpload (fileID) {
   retryUpload (fileID) {
@@ -529,7 +529,7 @@ class Uppy {
     this.emit('upload-retry', fileID)
     this.emit('upload-retry', fileID)
 
 
     const uploadID = this.createUpload([ fileID ])
     const uploadID = this.createUpload([ fileID ])
-    return this.runUpload(uploadID)
+    return this._runUpload(uploadID)
   }
   }
 
 
   reset () {
   reset () {
@@ -670,10 +670,6 @@ class Uppy {
       this.calculateTotalProgress()
       this.calculateTotalProgress()
     })
     })
 
 
-    this.on('update-meta', (fileID, data) => {
-      this.setFileMeta(fileID, data)
-    })
-
     this.on('preprocess-progress', (fileID, progress) => {
     this.on('preprocess-progress', (fileID, progress) => {
       this.setFileState(fileID, {
       this.setFileState(fileID, {
         progress: Object.assign({}, this.getState().files[fileID].progress, {
         progress: Object.assign({}, this.getState().files[fileID].progress, {
@@ -960,7 +956,7 @@ class Uppy {
       return Promise.reject(new Error('Nonexistent upload'))
       return Promise.reject(new Error('Nonexistent upload'))
     }
     }
 
 
-    return this.runUpload(uploadID)
+    return this._runUpload(uploadID)
   }
   }
 
 
   /**
   /**
@@ -1008,7 +1004,7 @@ class Uppy {
    *
    *
    * @private
    * @private
    */
    */
-  runUpload (uploadID) {
+  _runUpload (uploadID) {
     const uploadData = this.getState().currentUploads[uploadID]
     const uploadData = this.getState().currentUploads[uploadID]
     const fileIDs = uploadData.fileIDs
     const fileIDs = uploadData.fileIDs
     const restoreStep = uploadData.step
     const restoreStep = uploadData.step
@@ -1074,7 +1070,7 @@ class Uppy {
       this.log('No uploader type plugins are used', 'warning')
       this.log('No uploader type plugins are used', 'warning')
     }
     }
 
 
-    const isMinNumberOfFilesReached = this.checkMinNumberOfFiles()
+    const isMinNumberOfFilesReached = this._checkMinNumberOfFiles()
     if (!isMinNumberOfFilesReached) {
     if (!isMinNumberOfFilesReached) {
       return Promise.reject(new Error('Minimum number of files has not been reached'))
       return Promise.reject(new Error('Minimum number of files has not been reached'))
     }
     }
@@ -1097,7 +1093,7 @@ class Uppy {
       })
       })
 
 
       const uploadID = this.createUpload(waitingFileIDs)
       const uploadID = this.createUpload(waitingFileIDs)
-      return this.runUpload(uploadID)
+      return this._runUpload(uploadID)
     })
     })
   }
   }
 }
 }

+ 9 - 33
src/core/Core.test.js

@@ -312,7 +312,7 @@ describe('src/Core', () => {
         })
         })
     })
     })
 
 
-    it('should update the file progress state when core:preprocess-progress event is fired', () => {
+    it('should update the file progress state when preprocess-progress event is fired', () => {
       const core = new Core()
       const core = new Core()
       core.run()
       core.run()
       return core
       return core
@@ -340,7 +340,7 @@ describe('src/Core', () => {
         })
         })
     })
     })
 
 
-    it('should update the file progress state when core:preprocess-complete event is fired', () => {
+    it('should update the file progress state when preprocess-complete event is fired', () => {
       const core = new Core()
       const core = new Core()
       core.run()
       core.run()
       return core
       return core
@@ -422,7 +422,7 @@ describe('src/Core', () => {
         })
         })
     })
     })
 
 
-    it('should update the file progress state when core:postprocess-progress event is fired', () => {
+    it('should update the file progress state when postprocess-progress event is fired', () => {
       const core = new Core()
       const core = new Core()
       core.run()
       core.run()
       return core
       return core
@@ -450,7 +450,7 @@ describe('src/Core', () => {
         })
         })
     })
     })
 
 
-    it('should update the file progress state when core:postprocess-complete event is fired', () => {
+    it('should update the file progress state when postprocess-complete event is fired', () => {
       const core = new Core()
       const core = new Core()
       core.run()
       core.run()
       return core
       return core
@@ -598,7 +598,7 @@ describe('src/Core', () => {
       })).rejects.toMatchObject({ message: 'onBeforeFileAdded: a plain string' })
       })).rejects.toMatchObject({ message: 'onBeforeFileAdded: a plain string' })
     })
     })
 
 
-    it('should call utils.generatePreview when core:file-added is triggered and thumbnail generation is allowed', () => {
+    it('should call utils.generatePreview when file-added is triggered and thumbnail generation is allowed', () => {
       const core = new Core({
       const core = new Core({
       }).run()
       }).run()
       const file = {
       const file = {
@@ -610,7 +610,7 @@ describe('src/Core', () => {
       expect(utils.createThumbnail.mock.calls[0][1]).toEqual(200)
       expect(utils.createThumbnail.mock.calls[0][1]).toEqual(200)
     })
     })
 
 
-    it('should return an object url of the image when core:file-added is triggered and thumbnail generation is disabled', () => {
+    it('should return an object url of the image when file-added is triggered and thumbnail generation is disabled', () => {
       const core = new Core({
       const core = new Core({
         thumbnailGeneration: false
         thumbnailGeneration: false
       }).run()
       }).run()
@@ -762,30 +762,6 @@ describe('src/Core', () => {
           })
           })
         })
         })
     })
     })
-
-    it('should update meta data for a file by calling core:update-meta', () => {
-      const core = new Core()
-      core.run()
-      return core
-        .addFile({
-          source: 'jest',
-          name: 'foo.jpg',
-          type: 'image/jpeg',
-          data: utils.dataURItoFile(sampleImageDataURI, {})
-        })
-        .then(() => {
-          const fileId = Object.keys(core.state.files)[0]
-          core.emit('update-meta', fileId, { foo: 'bar', bur: 'mur' })
-          core.emit('update-meta', fileId, { boo: 'moo', bur: 'fur' })
-          expect(core.state.files[fileId].meta).toEqual({
-            name: 'foo.jpg',
-            type: 'image/jpeg',
-            foo: 'bar',
-            bur: 'fur',
-            boo: 'moo'
-          })
-        })
-    })
   })
   })
 
 
   describe('progress', () => {
   describe('progress', () => {
@@ -998,14 +974,14 @@ describe('src/Core', () => {
   })
   })
 
 
   describe('actions', () => {
   describe('actions', () => {
-    it('should update the state when receiving the core:error event', () => {
+    it('should update the state when receiving the error event', () => {
       const core = new Core()
       const core = new Core()
       core.run()
       core.run()
       core.emit('error', new Error('foooooo'))
       core.emit('error', new Error('foooooo'))
       expect(core.state.error).toEqual('foooooo')
       expect(core.state.error).toEqual('foooooo')
     })
     })
 
 
-    it('should update the state when receiving the core:upload-error event', () => {
+    it('should update the state when receiving the upload-error event', () => {
       const core = new Core()
       const core = new Core()
       core.run()
       core.run()
       core.state.files['fileId'] = {
       core.state.files['fileId'] = {
@@ -1015,7 +991,7 @@ describe('src/Core', () => {
       expect(core.state.info).toEqual({'message': 'Failed to upload filename', 'details': 'this is the error', 'isHidden': false, 'type': 'error'})
       expect(core.state.info).toEqual({'message': 'Failed to upload filename', 'details': 'this is the error', 'isHidden': false, 'type': 'error'})
     })
     })
 
 
-    it('should reset the error state when receiving the core:upload event', () => {
+    it('should reset the error state when receiving the upload event', () => {
       const core = new Core()
       const core = new Core()
       core.run()
       core.run()
       core.emit('error', { foo: 'bar' })
       core.emit('error', { foo: 'bar' })