Debian Codegraph @

extensions/MultimediaViewer/tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js

raw symbols SCIP
1 /*
2 * This file is part of the MediaWiki extension MediaViewer.
3 *
4 * MediaViewer is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * MediaViewer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 const { StripeButtons } = require( 'mmv' );
19
20 ( function () {
21 QUnit.module( 'mmv.ui.StripeButtons', QUnit.newMwEnvironment() );
22
23 function createStripeButtons() {
24 const $fixture = $( '#qunit-fixture' );
25 return new StripeButtons( $fixture );
26 }
27
28 QUnit.test( 'Sense test, object creation and UI construction', ( assert ) => {
29 const oldMwUserIsAnon = mw.user.isAnon;
30
31 // first pretend we are anonymous
32 mw.user.isAnon = () => true;
33 let buttons = createStripeButtons();
34
35 assert.true( buttons instanceof StripeButtons, 'UI element is created.' );
36 assert.strictEqual( buttons.$descriptionPage.length, 1, 'File page button created for anon.' );
37
38 // now pretend we are logged in
39 mw.user.isAnon = () => false;
40 buttons = createStripeButtons();
41
42 assert.strictEqual( buttons.$descriptionPage.length, 1, 'File page button created for logged in.' );
43
44 mw.user.isAnon = oldMwUserIsAnon;
45 } );
46
47 QUnit.test( 'set()/empty() sense test:', ( assert ) => {
48 const buttons = createStripeButtons();
49 const fakeImageInfo = { descriptionUrl: '//commons.wikimedia.org/wiki/File:Foo.jpg' };
50
51 buttons.set( null, fakeImageInfo );
52 buttons.empty();
53
54 assert.true( true, 'No error on set()/empty().' );
55 } );
56
57 QUnit.test( 'Description page button', ( assert ) => {
58 const $qf = $( '#qunit-fixture' );
59 const buttons = new StripeButtons( $qf );
60 const $button = buttons.$descriptionPage;
61 const descriptionUrl = 'http://example.com/desc';
62 const descriptionUrlCommons = 'https://commons.wikimedia.org/desc';
63 const descriptionUrl2 = 'http://example.com/different-desc';
64
65 buttons.set( null, { descriptionUrl } );
66
67 assert.strictEqual( $button.hasClass( 'mw-mmv-repo-button-commons' ), false, 'Button does not have commons class non-Commons files' );
68 assert.strictEqual( $button.find( 'a' ).addBack().filter( 'a' ).attr( 'href' ), descriptionUrl, 'Description page link is correct' );
69
70 buttons.set( null, { descriptionUrl: descriptionUrlCommons } );
71
72 assert.strictEqual( $button.hasClass( 'mw-mmv-repo-button-commons' ), true, 'Button commons class for Commons files' );
73
74 buttons.set( null, {
75 descriptionUrl,
76 pageID: 1,
77 title: { getUrl: () => descriptionUrl2 }
78 } );
79
80 assert.strictEqual(
81 $button.hasClass( 'mw-mmv-repo-button-commons' ), false,
82 'Button does not have commons class for Commons files with local description page'
83 );
84 assert.strictEqual(
85 $button.find( 'a' ).addBack().filter( 'a' ).attr( 'href' ), descriptionUrl2,
86 'Description page link for Commons files with local description page is correct'
87 );
88 } );
89
90 }() );