summaryrefslogtreecommitdiff
path: root/www/wiki/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.upload.test.js
blob: 788a427e7217074cb705766f950c537aa6f38643 (plain)
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
( function ( mw, $ ) {
	QUnit.module( 'mediawiki.api.upload', QUnit.newMwEnvironment( {} ) );

	QUnit.test( 'Basic functionality', function ( assert ) {
		var api = new mw.Api();
		assert.ok( api.upload );
		assert.throws( function () {
			api.upload();
		} );
	} );

	QUnit.test( 'Set up iframe upload', function ( assert ) {
		var $iframe, $form, $input,
			api = new mw.Api();

		this.sandbox.stub( api, 'getEditToken', function () {
			return $.Deferred().promise();
		} );

		api.uploadWithIframe( $( '<input>' )[ 0 ], { filename: 'Testing API upload.jpg' } );

		$iframe = $( 'iframe:last-child' );
		$form = $( 'form.mw-api-upload-form' );
		$input = $form.find( 'input[name=filename]' );

		assert.ok( $form.length > 0, 'form' );
		assert.ok( $input.length > 0, 'input' );
		assert.ok( $iframe.length > 0, 'frame' );
		assert.strictEqual( $form.prop( 'target' ), $iframe.prop( 'id' ), 'form.target and frame.id ' );
		assert.strictEqual( $input.val(), 'Testing API upload.jpg', 'input value' );
	} );

}( mediaWiki, jQuery ) );