summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/UploadWizard/tests/qunit/controller/uw.controller.Thanks.test.js
blob: 797de61173c10065e418d6e319f5b71d676ff6a1 (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
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
/*
 * 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.Thanks', QUnit.newMwEnvironment() );

	QUnit.test( 'Constructor sanity test', function ( assert ) {
		var step = new uw.controller.Thanks( new mw.Api(), { display: { thanksLabel: 'Thanks!' } } );
		assert.ok( step );
		assert.ok( step instanceof uw.controller.Step );
		assert.ok( step.ui );
	} );

	QUnit.test( 'load', function ( assert ) {
		var step = new uw.controller.Thanks( new mw.Api(), {} ),
			auStub = this.sandbox.stub( step.ui, 'addUpload' );

		this.sandbox.stub( step.ui, 'load' );
		step.load( [
			{ on: $.noop },
			{ on: $.noop },
			{ on: $.noop }
		] );

		assert.strictEqual( auStub.callCount, 3 );
	} );

	QUnit.test( 'Custom button configuration', function ( assert ) {
		var config = {
				display: {
					homeButton: {
						label: 'This is just a test',
						target: 'https://wiki.example.com/wiki/Main_Page'
					},
					beginButton: {
						label: 'Let me start again',
						target: 'https://commons.wikimedia.org/wiki/Special:UploadWizard'
					}
				}
			},
			uiThanks = new uw.ui.Thanks( config );

		assert.equal(
			uiThanks.homeButton.getLabel(),
			'This is just a test',
			'The label of the home button matches the configured text.'
		);

		assert.equal(
			uiThanks.homeButton.getHref(),
			'https://wiki.example.com/wiki/Main_Page',
			'The target of the home button matches the configured URL.'
		);

		assert.equal(
			uiThanks.beginButton.getLabel(),
			'Let me start again',
			'The label of the begin button matches the configured text.'
		);

		assert.equal(
			uiThanks.beginButton.getHref(),
			'https://commons.wikimedia.org/wiki/Special:UploadWizard',
			'The target of the begin button matches the configured URL.'
		);

	} );

	QUnit.test( 'Method drops the given parameter', function ( assert ) {
		var uiThanks = new uw.ui.Thanks( {} ),
			locationHref = 'https://commons.wikimedia.org/wiki/Special:UploadWizard?campaign=somecampaign&objref=testRef|MyPage|342&updateList=1&somevar=someval';

		assert.equal(
			uiThanks.dropParameterFromURL( locationHref, 'updateList' ),
			'https://commons.wikimedia.org/wiki/Special:UploadWizard?campaign=somecampaign&objref=testRef%7CMyPage%7C342&somevar=someval',
			'The href of the begin button does not contain the updateList parameter.'
		);
	} );

}( jQuery, mediaWiki, mediaWiki.uploadWizard ) );