Skip to content

Commit

Permalink
ADD: test code for _initField
Browse files Browse the repository at this point in the history
  • Loading branch information
farthinker committed Aug 10, 2016
1 parent b4b2e59 commit 767cfb9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
7 changes: 5 additions & 2 deletions dist/qing-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ QingUploader = (function(superClass) {
return _this._initFileField($el);
};
})(this));
return $input;
return this.field = $input;
};

QingUploader.prototype._bind = function() {
Expand Down Expand Up @@ -282,7 +282,10 @@ QingUploader = (function(superClass) {
file = ref[i];
this.cancel(file);
}
return $(window).off('.uploader-' + this.id);
$(window).off('.uploader-' + this.id);
if (this.field) {
return this.field.remove();
}
};

return QingUploader;
Expand Down
2 changes: 1 addition & 1 deletion dist/qing-uploader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/qing-uploader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class QingUploader extends QingModule
$input.on 'change', (e) =>
@upload $input[0].files
@_initFileField $el
$input

@field = $input

_bind: ->
# upload the files in the queue
Expand Down Expand Up @@ -181,5 +182,6 @@ class QingUploader extends QingModule
@queue.length = 0
@cancel file for file in @files
$(window).off '.uploader-' + @id
@field.remove() if @field

module.exports = QingUploader
17 changes: 17 additions & 0 deletions test/qing-uploader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,20 @@ describe 'QingUploader', ->
@uploader.readImageFile file, (img) ->
expect(img).to.be.false
done()

it 'should create input:file if el option is present', ->
$link = $('<a href="javascript:;" class="button-upload">Upload</a>')
.appendTo 'body'

uploader = new QingUploader
el: '.button-upload'
url: '/upload'

$input = $link.find('input:file')
expect($input.get(0)).to.be.equal(uploader.field.get(0))

$input.trigger 'change'
expect($input.get(0)).not.to.be.equal(uploader.field.get(0))

uploader.destroy()
$link.remove()

0 comments on commit 767cfb9

Please sign in to comment.