Added warning for improper ending of a token
[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 assert.throws( function () {
9 api.upload();
10 } );
11 } );
12
13 QUnit.test( 'Set up iframe upload', function ( assert ) {
14 QUnit.expect( 5 );
15 var $iframe, $form, $input,
16 api = new mw.Api();
17
18 this.sandbox.stub( api, 'getEditToken', function () {
19 return $.Deferred().promise();
20 } );
21
22 api.uploadWithIframe( $( '<input>' )[ 0 ], { filename: 'Testing API upload.jpg' } );
23
24 $iframe = $( 'iframe' );
25 $form = $( 'form.mw-api-upload-form' );
26 $input = $form.find( 'input[name=filename]' );
27
28 assert.ok( $form.length > 0 );
29 assert.ok( $input.length > 0 );
30 assert.ok( $iframe.length > 0 );
31 assert.strictEqual( $form.prop( 'target' ), $iframe.prop( 'id' ) );
32 assert.strictEqual( $input.val(), 'Testing API upload.jpg' );
33 } );
34
35 }( mediaWiki, jQuery ) );