Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.upload.test.js
1 ( function ( mw, $ ) {
2 QUnit.module( 'mediawiki.api.upload', QUnit.newMwEnvironment( {} ) );
3
4 QUnit.test( 'Basic functionality', function ( assert ) {
5 QUnit.expect( 2 );
6 var api = new mw.Api();
7 assert.ok( api.upload );
8 // The below will return a rejected deferred, but that's OK.
9 assert.ok( api.upload() );
10 } );
11
12 QUnit.test( 'Set up iframe upload', function ( assert ) {
13 QUnit.expect( 5 );
14 var $iframe, $form, $input,
15 api = new mw.Api();
16
17 this.sandbox.stub( api, 'getEditToken', function () {
18 return $.Deferred().promise();
19 } );
20
21 api.uploadWithIframe( $( '<input>' )[ 0 ], { filename: 'Testing API upload.jpg' } );
22
23 $iframe = $( 'iframe' );
24 $form = $( 'form.mw-api-upload-form' );
25 $input = $form.find( 'input[name=filename]' );
26
27 assert.ok( $form.length > 0 );
28 assert.ok( $input.length > 0 );
29 assert.ok( $iframe.length > 0 );
30 assert.strictEqual( $form.prop( 'target' ), $iframe.prop( 'id' ) );
31 assert.strictEqual( $input.val(), 'Testing API upload.jpg' );
32 } );
33
34 }( mediaWiki, jQuery ) );