| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 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 |
|
| 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 |
}() ); |