' ).appendTo( $qf ) ),
fileName = 'Foobar.jpg',
latitude = 12.3456789,
longitude = 98.7654321,
imageData = {
latitude: latitude,
longitude: longitude,
hasCoords: function() { return true; },
title: mw.Title.newFromText( 'File:Foobar.jpg' )
};
panel.setLocationData( imageData );
assert.strictEqual(
panel.$location.text(),
'Location: 12° 20′ 44.44″ N, 98° 45′ 55.56″ E',
'Location text is set as expected - if this fails it may be due to i18n issues.'
);
assert.strictEqual(
panel.$location.prop( 'href' ),
'http://tools.wmflabs.org/geohack/geohack.php?pagename=File:' + fileName + '¶ms=' + latitude + '_N_' + longitude + '_E_&language=en',
'Location URL is set as expected'
);
latitude = -latitude;
longitude = -longitude;
imageData.latitude = latitude;
imageData.longitude = longitude;
panel.setLocationData( imageData );
assert.strictEqual(
panel.$location.text(),
'Location: 12° 20′ 44.44″ S, 98° 45′ 55.56″ W',
'Location text is set as expected - if this fails it may be due to i18n issues.'
);
assert.strictEqual(
panel.$location.prop( 'href' ),
'http://tools.wmflabs.org/geohack/geohack.php?pagename=File:' + fileName + '¶ms=' + ( - latitude) + '_S_' + ( - longitude ) + '_W_&language=en',
'Location URL is set as expected'
);
latitude = 0;
longitude = 0;
imageData.latitude = latitude;
imageData.longitude = longitude;
panel.setLocationData( imageData );
assert.strictEqual(
panel.$location.text(),
'Location: 0° 0′ 0″ N, 0° 0′ 0″ E',
'Location text is set as expected - if this fails it may be due to i18n issues.'
);
assert.strictEqual(
panel.$location.prop( 'href' ),
'http://tools.wmflabs.org/geohack/geohack.php?pagename=File:' + fileName + '¶ms=' + latitude + '_N_' + longitude + '_E_&language=en',
'Location URL is set as expected'
);
} );
QUnit.test( 'Setting image information works as expected', 16, function ( assert ) {
var gender,
$qf = $( '#qunit-fixture' ),
panel = new mw.mmv.ui.MetadataPanel( $qf, $( '
' ).appendTo( $qf ) ),
title = 'Foo bar',
image = {
filePageTitle : mw.Title.newFromText( 'File:' + title + '.jpg' )
},
imageData = {
title: image.filePageTitle,
url: 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
descriptionUrl: 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
hasCoords: function() { return false; }
},
repoData = {
getArticlePath : function() { return 'Foo'; },
isCommons: function() { return false; }
},
localUsage = {},
globalUsage = {},
oldMoment = window.moment;
/*window.moment = function( date ) {
// This has no effect for now, since writing this test revealed that our moment.js
// doesn't have any language configuration
return oldMoment( date ).lang( 'fr' );
};*/
panel.setImageInfo( image, imageData, repoData, localUsage, globalUsage, gender );
assert.strictEqual( panel.$title.text(), title, 'Title is correctly set' );
assert.ok( panel.$credit.hasClass( 'empty' ), 'Credit is empty' );
assert.strictEqual( panel.$license.prop( 'href' ), imageData.descriptionUrl,
'User is directed to file page for license information' );
assert.ok( !panel.$license.prop( 'target' ), 'License information opens in same window' );
assert.ok( panel.$usernameLi.hasClass( 'empty' ), 'Username is empty' );
assert.ok( panel.$datetimeLi.hasClass( 'empty' ), 'Date/Time is empty' );
assert.ok( panel.$locationLi.hasClass( 'empty' ), 'Location is empty' );
imageData.creationDateTime = '2013-08-26T14:41:02Z';
imageData.uploadDateTime = '2013-08-25T14:41:02Z';
imageData.source = '
LostBar';
imageData.author = 'Bob';
imageData.license = new mw.mmv.model.License( 'CC-BY-2.0', 'cc-by-2.0',
'Creative Commons Attribution - Share Alike 2.0',
'http://creativecommons.org/licenses/by-sa/2.0/' );
gender = 'female';
imageData.lastUploader = 'Ursula';
panel.setImageInfo( image, imageData, repoData, localUsage, globalUsage, gender );
assert.strictEqual( panel.$title.text(), title, 'Title is correctly set' );
assert.ok( !panel.$credit.hasClass( 'empty' ), 'Credit is not empty' );
assert.ok( !panel.$datetimeLi.hasClass( 'empty' ), 'Date/Time is not empty' );
assert.strictEqual( panel.creditField.$element.html(), '
' + imageData.author + ' -
LostBar', 'Source and author are correctly set' );
assert.ok( panel.$datetime.text().indexOf( 'August 26 2013' ) > 0, 'Correct date is displayed' );
assert.strictEqual( panel.$license.text(), 'CC BY 2.0', 'License is correctly set' );
assert.ok( panel.$license.prop( 'target' ), 'License information opens in new window' );
assert.ok( panel.$username.text().indexOf( imageData.lastUploader ) > 0, 'Correct username is displayed' );
imageData.creationDateTime = undefined;
panel.setImageInfo( image, imageData, repoData, localUsage, globalUsage, gender );
assert.ok( panel.$datetime.text().indexOf( 'August 25 2013' ) > 0, 'Correct date is displayed' );
window.moment = oldMoment;
} );
QUnit.test( 'Setting permission information works as expected', 1, function ( assert ) {
var $qf = $( '#qunit-fixture' ),
panel = new mw.mmv.ui.MetadataPanel( $qf, $( '
' ).appendTo( $qf ) );
panel.setPermission( 'Look at me, I am a permission!' );
assert.ok( panel.$permissionLink.is( ':visible' ) );
} );
QUnit.test( 'Date formatting', 1, function ( assert ) {
var $qf = $( '#qunit-fixture' ),
panel = new mw.mmv.ui.MetadataPanel( $qf, $( '
' ).appendTo( $qf ) ),
date1 = 'Garbage',
promise = panel.formatDate( date1 );
QUnit.stop();
promise.then( function ( result ) {
assert.strictEqual( result, date1, 'Invalid date is correctly ignored' );
QUnit.start();
} );
} );
QUnit.test( 'Repo icon', 4, function ( assert ) {
var $qf = $( '#qunit-fixture' ),
panel = new mw.mmv.ui.MetadataPanel( $qf, $( '
' ).appendTo( $qf ) ),
favIcon = 'http://example.com/foo-fav',
repoData = {
favIcon: favIcon,
getArticlePath : function() { return 'Foo'; },
isCommons: function() { return false; }
};
panel.setRepoDisplay( repoData );
assert.ok( panel.$repoLi.css( 'background-image' ).indexOf( favIcon ) !== -1, 'Repo favicon is correctly applied' );
assert.ok( !panel.$repoLi.hasClass( 'commons' ), 'Repo does not have commons class' );
repoData.isCommons = function() { return true; };
panel.setRepoDisplay( repoData );
assert.ok( panel.$repoLi.css( 'background-image' ).indexOf( 'data:image/svg+xml' ) !== -1, 'Repo favicon is correctly replaced by svg for Commons' );
assert.ok( panel.$repoLi.hasClass( 'commons' ), 'Repo has commons class' );
} );
QUnit.test( 'About links', 9, function ( assert ) {
var panel,
$qf = $( '#qunit-fixture'),
oldWgMediaViewerIsInBeta = mw.config.get( 'wgMediaViewerIsInBeta' );
this.sandbox.stub( mw.user, 'isAnon' );
mw.config.set( 'wgMediaViewerIsInBeta', false );
panel = new mw.mmv.ui.MetadataPanel( $qf.empty(), $( '
' ).appendTo( $qf ) );
assert.strictEqual( $qf.find( '.mw-mmv-about-link' ).length, 1, 'About link is created.' );
assert.strictEqual( $qf.find( '.mw-mmv-discuss-link' ).length, 1, 'Discuss link is created.' );
assert.strictEqual( $qf.find( '.mw-mmv-help-link' ).length, 1, 'Help link is created.' );
assert.strictEqual( $qf.find( '.mw-mmv-optout-link' ).length, 1, 'Opt-out link is created.' );
assert.strictEqual( $qf.find( '.mw-mmv-preference-link' ).length, 0, 'Preferences link is not created when not in beta.' );
mw.config.set( 'wgMediaViewerIsInBeta', true );
mw.user.isAnon.returns( false );
panel = new mw.mmv.ui.MetadataPanel( $qf.empty(), $( '
' ).appendTo( $qf ) );
assert.strictEqual( $qf.find( '.mw-mmv-optout-link' ).length, 0, 'Opt-out link is not created when in beta.' );
assert.strictEqual( $qf.find( '.mw-mmv-preference-link' ).length, 1, 'Preferences link is created for logged-in user.' );
mw.user.isAnon.returns( true );
panel = new mw.mmv.ui.MetadataPanel( $qf.empty(), $( '
' ).appendTo( $qf ) );
assert.strictEqual( $qf.find( '.mw-mmv-optout-link' ).length, 0, 'Opt-out link is not created when in beta.' );
assert.strictEqual( $qf.find( '.mw-mmv-preference-link' ).length, 0, 'Preferences link is not created for anon user.' );
mw.config.set( 'wgMediaViewerIsInBeta', oldWgMediaViewerIsInBeta );
} );
}( mediaWiki, jQuery ) );