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
|
/*
* This file is part of the MediaWiki extension UploadWizard.
*
* UploadWizard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* UploadWizard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with UploadWizard. If not, see <http://www.gnu.org/licenses/>.
*/
( function ( $, mw, uw ) {
QUnit.module( 'uw.controller.Upload', QUnit.newMwEnvironment() );
QUnit.test( 'Constructor sanity test', function ( assert ) {
var step = new uw.controller.Upload( new mw.Api(), {
maxUploads: 10,
maxSimultaneousConnections: 3
} );
assert.ok( step );
assert.ok( step instanceof uw.controller.Step );
assert.ok( step.ui );
} );
QUnit.test( 'updateFileCounts', function ( assert ) {
var step = new uw.controller.Upload( new mw.Api(), {
maxUploads: 5,
maxSimultaneousConnections: 3
} ),
ufcStub = this.sandbox.stub( step.ui, 'updateFileCounts' );
step.uploads = [ 1, 2 ];
step.updateFileCounts();
assert.ok( ufcStub.calledWith( true, true ) );
ufcStub.reset();
step.uploads = [];
step.updateFileCounts();
assert.ok( ufcStub.calledWith( false, true ) );
ufcStub.reset();
step.uploads = [ 1, 2, 3, 4, 5, 6 ];
step.updateFileCounts();
assert.ok( ufcStub.calledWith( true, false ) );
} );
QUnit.test( 'canTransition', function ( assert ) {
var upload = {},
step = new uw.controller.Upload( new mw.Api(), {
maxSimultaneousConnections: 1
} );
assert.strictEqual( step.canTransition( upload ), false );
upload.state = 'new';
assert.strictEqual( step.canTransition( upload ), true );
upload.state = 'stashed';
assert.strictEqual( step.canTransition( upload ), false );
} );
QUnit.test( 'transitionOne', function ( assert ) {
var upload = {
start: this.sandbox.stub()
},
step = new uw.controller.Upload( new mw.Api(), {
maxSimultaneousConnections: 1
} );
this.sandbox.stub( step, 'maybeStartProgressBar' );
assert.strictEqual( upload.start.called, false );
step.transitionOne( upload );
assert.ok( upload.start.called );
} );
}( jQuery, mediaWiki, mediaWiki.uploadWizard ) );
|