@behance/beff
Advanced tools
Comparing version 9.3.4 to 9.3.5
@@ -104,2 +104,4 @@ define([ | ||
this.scaled = []; | ||
// move the drift option to a location that a hacked version of fineuploader can find it | ||
@@ -142,2 +144,7 @@ config.signature.params = config.signature.params || {}; | ||
destroy: function() { | ||
this.scaled = []; | ||
this._super(); | ||
}, | ||
addFiles: function(files) { | ||
@@ -341,5 +348,3 @@ this._uploader.addFiles(files); | ||
return this._uploader.scaleImage(id, _options).then(function(blob) { | ||
return Promise.resolve(blob); | ||
}.bind(this)); | ||
return this._uploader.scaleImage(id, _options); | ||
}, | ||
@@ -349,11 +354,11 @@ | ||
return this._scaleImage(id).then(function(blob) { | ||
this.scaled = blob; | ||
this.scaled.id = this.scaled.id || id; | ||
this.scaled[id] = blob; | ||
this.scaled[id].id = this.scaled[id].id || id; | ||
return new Promise(function(resolve) { | ||
resolve(this._validator(this.scaled)); | ||
resolve(this._validator(this.scaled[id])); | ||
}.bind(this)) | ||
.then(function() { | ||
this.trigger('submit', { | ||
file: this.scaled, | ||
file: this.scaled[id], | ||
id: id, | ||
@@ -378,5 +383,9 @@ name: name | ||
_onProgress: function(id, name, loaded, total) { | ||
if (!this.scaled[id]) { | ||
return; | ||
} | ||
this.trigger('progress', { | ||
id: id, | ||
file: this.scaled, | ||
file: this.scaled[id], | ||
name: name, | ||
@@ -389,2 +398,6 @@ loaded: loaded, | ||
_onComplete: function(id, name, response) { | ||
if (!this.scaled[id]) { | ||
return; | ||
} | ||
this.trigger('complete', { | ||
@@ -394,3 +407,3 @@ response: response, | ||
name: name, | ||
file: this.scaled, | ||
file: this.scaled[id], | ||
uploadEndpoint: this.getUploadEndpoint(), | ||
@@ -397,0 +410,0 @@ uploadPath: this.getUploadPath(id) |
{ | ||
"name": "@behance/beff", | ||
"version": "9.3.4", | ||
"version": "9.3.5", | ||
"description": "Behance Frontend Framework", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -26,2 +26,8 @@ define([ | ||
this.scaled = [ | ||
this._blob, | ||
Object.assign({}, this._blob, { name: 'second image' }), | ||
Object.assign({}, this._blob, { name: 'third image' }), | ||
]; | ||
this._buttons = [{ | ||
@@ -63,5 +69,8 @@ getInput: function() { | ||
scaleImage: function() { | ||
scaleImage: function(id) { | ||
var _id = id || 0; | ||
var mocked = this.scaled[_id] || this.scaled[0]; | ||
return new Promise(function(resolve) { | ||
resolve(this._blob); | ||
resolve(mocked); | ||
}.bind(this)); | ||
@@ -113,2 +122,22 @@ }, | ||
/** | ||
* Fakes a submit then a progress. | ||
* | ||
* @param {id} | ||
* @param {name} | ||
* @param {percent} | ||
* @param {total} | ||
* @return {Promise} | ||
*/ | ||
fakeSubmitAndProgress: function(id, name, percent, total) { | ||
var self = this; | ||
return new Promise(function(resolve) { | ||
self.fakeSubmit(id, name).then(function() { | ||
self.fakeProgress(id, name, percent, total); | ||
resolve(); | ||
}); | ||
}); | ||
}, | ||
/** | ||
* Fakes a complete. Response may be supplied with an error code to simulate a server-invalid upload | ||
@@ -115,0 +144,0 @@ */ |
@@ -108,2 +108,19 @@ define([ | ||
describe('events', function() { | ||
beforeEach(function() { | ||
this.expectedReturns = [ | ||
{ | ||
id: 0, | ||
expectedFileName: fineuploaderMock.scaled[0].name, | ||
}, | ||
{ | ||
id: 1, | ||
expectedFileName: fineuploaderMock.scaled[1].name, | ||
}, | ||
{ | ||
id: 2, | ||
expectedFileName: fineuploaderMock.scaled[2].name, | ||
}, | ||
]; | ||
}); | ||
it('fires the complete event on a successful upload', function(done) { | ||
@@ -125,2 +142,28 @@ spyOn(this.uploader._uploader, 'getKey').and.returnValue('1.jpg'); | ||
it('fires the complete event with the correctly scaled images', function(done) { | ||
Promise.all([ | ||
fineuploaderMock.fakeSubmitAndComplete(this.expectedReturns[0].id, 'foo'), | ||
fineuploaderMock.fakeSubmitAndComplete(this.expectedReturns[1].id, 'foo'), | ||
fineuploaderMock.fakeSubmitAndComplete(this.expectedReturns[2].id, 'foo'), | ||
]).then(function() { | ||
this.uploader.scaled.forEach(function(scaled, index) { | ||
expect(scaled.name).toEqual(this.expectedReturns[index].expectedFileName); | ||
}.bind(this)); | ||
done(); | ||
}.bind(this)); | ||
}); | ||
it('fires the progress event with the correctly scaled images', function(done) { | ||
Promise.all([ | ||
fineuploaderMock.fakeSubmitAndProgress(this.expectedReturns[0].id, 'foo'), | ||
fineuploaderMock.fakeSubmitAndProgress(this.expectedReturns[1].id, 'foo'), | ||
fineuploaderMock.fakeSubmitAndProgress(this.expectedReturns[2].id, 'foo'), | ||
]).then(function() { | ||
this.uploader.scaled.forEach(function(scaled, index) { | ||
expect(scaled.name).toEqual(this.expectedReturns[index].expectedFileName); | ||
}.bind(this)); | ||
done(); | ||
}.bind(this)); | ||
}); | ||
it('fires the allComplete event when all uploads are complete', function(done) { | ||
@@ -127,0 +170,0 @@ this.uploader.on('allComplete', done); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1569764
14208