forked from Tencent/weui.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploader.js
94 lines (85 loc) · 2.65 KB
/
uploader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
describe('uploader', function(){
let beforeQueuedCallback = $.noop,
queuedCallback = $.noop,
progressCallback = $.noop,
successCallback = $.noop,
errorCallback = $.noop;
this.timeout(0);
before(() => {
$('#test').html(`
<div class="weui-uploader" id="uploader">
<div class="weui-uploader__hd">
<p class="weui-uploader__title">图片上传</p>
<div class="weui-uploader__info">0/2</div>
</div>
<div class="weui-uploader__bd">
<ul class="weui-uploader__files" id="uploaderFiles"></ul>
<div class="weui-uploader__input-box">
<input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple>
</div>
</div>
</div>
`);
weui.uploader('#uploader', {
url: 'http://localhost:8081',
type: 'file',
fileVal: 'file',
compress: {
width: 1600,
height: 1600,
quality: .8
},
onBeforeQueued: function () {
return beforeQueuedCallback.call(this);
},
onQueued: function () {
queuedCallback.call(this);
},
onProgress: function (procent) {
progressCallback.call(this, procent);
},
onSuccess: function (ret) {
successCallback.call(this, ret);
},
onError: function (err) {
errorCallback.call(this, err);
}
});
});
it('test onBeforeQueued', (done) => {
beforeQueuedCallback = function(){
assert(this instanceof File);
done();
};
});
it('test onQueued', (done) => {
queuedCallback = function(){
assert(this instanceof Blob);
done();
};
});
/* it('test onProgress', (done) => {
progressCallback = function(procent){
assert(this instanceof Blob);
assert(procent !== undefined);
done();
};
});*/
/* it('test onSuccess', (done) => {
successCallback = function(ret){
assert(this instanceof Blob);
assert(ret !== undefined);
done();
};
});*/
it('test onError', (done) => {
errorCallback = function(err){
assert(this instanceof Blob);
assert(err !== undefined);
done();
};
});
after(() => {
// $('#test').html('');
});
});