diff --git a/resources/mmv/ui/mmv.ui.metadataPanel.js b/resources/mmv/ui/mmv.ui.metadataPanel.js index db920e8bb..0ae78d4e1 100644 --- a/resources/mmv/ui/mmv.ui.metadataPanel.js +++ b/resources/mmv/ui/mmv.ui.metadataPanel.js @@ -105,10 +105,8 @@ } ).on( 'mmv-metadata-close.mmv-mp', function () { panel.hideTruncatedText(); } ).on( 'mouseleave.mmv-mp', function () { - var duration; - if ( panel.isFullscreened() ) { - duration = parseFloat( panel.$container.css( 'transition-duration' ) ) * 1000 || 0; + var duration = parseFloat( panel.$container.css( 'transition-duration' ) ) * 1000 || 0; panel.panelShrinkTimeout = setTimeout( function () { panel.hideTruncatedText(); }, duration ); @@ -526,13 +524,11 @@ * @return {string} unsafe HTML */ MPP.wrapAuthor = function ( author, authorCount, filepageUrl ) { - var moreText, - $wrapper = $( '' ); - - $wrapper.addClass( 'mw-mmv-author' ); + var $wrapper = $( '' ) + .addClass( 'mw-mmv-author' ); if ( authorCount > 1 ) { - moreText = this.htmlUtils.jqueryToHtml( + var moreText = this.htmlUtils.jqueryToHtml( $( '' ) .addClass( 'mw-mmv-more-authors' ) .text( mw.message( 'multimediaviewer-multiple-authors', authorCount - 1 ).text() ) @@ -713,29 +709,26 @@ * @param {mw.mmv.model.Image} imageData */ MPP.setLocationData = function ( imageData ) { - var latsec, latitude, latmsg, latdeg, latremain, latmin, - longsec, longitude, longmsg, longdeg, longremain, longmin; - if ( !imageData.hasCoords() ) { return; } - latitude = imageData.latitude >= 0 ? imageData.latitude : imageData.latitude * -1; - latmsg = 'multimediaviewer-geoloc-' + ( imageData.latitude >= 0 ? 'north' : 'south' ); - latdeg = Math.floor( latitude ); - latremain = latitude - latdeg; - latmin = Math.floor( ( latremain ) * 60 ); + var latitude = imageData.latitude >= 0 ? imageData.latitude : imageData.latitude * -1; + var latmsg = 'multimediaviewer-geoloc-' + ( imageData.latitude >= 0 ? 'north' : 'south' ); + var latdeg = Math.floor( latitude ); + var latremain = latitude - latdeg; + var latmin = Math.floor( ( latremain ) * 60 ); - longitude = imageData.longitude >= 0 ? imageData.longitude : imageData.longitude * -1; - longmsg = 'multimediaviewer-geoloc-' + ( imageData.longitude >= 0 ? 'east' : 'west' ); - longdeg = Math.floor( longitude ); - longremain = longitude - longdeg; - longmin = Math.floor( ( longremain ) * 60 ); + var longitude = imageData.longitude >= 0 ? imageData.longitude : imageData.longitude * -1; + var longmsg = 'multimediaviewer-geoloc-' + ( imageData.longitude >= 0 ? 'east' : 'west' ); + var longdeg = Math.floor( longitude ); + var longremain = longitude - longdeg; + var longmin = Math.floor( ( longremain ) * 60 ); longremain -= longmin / 60; latremain -= latmin / 60; - latsec = Math.round( latremain * 100 * 60 * 60 ) / 100; - longsec = Math.round( longremain * 100 * 60 * 60 ) / 100; + var latsec = Math.round( latremain * 100 * 60 * 60 ) / 100; + var longsec = Math.round( longremain * 100 * 60 * 60 ) / 100; this.$location.text( mw.message( 'multimediaviewer-geolocation', @@ -842,8 +835,7 @@ * @return {string} formatted date */ MPP.formatDate = function ( dateString ) { - var date, - lang = mw.config.get( 'wgUserLanguage' ); + var lang = mw.config.get( 'wgUserLanguage' ); if ( lang === 'en' || lang === 'qqx' ) { // prefer "D MMMM YYYY" format // avoid passing invalid "qqx" to native toLocaleString(), @@ -851,7 +843,7 @@ // and thus sometimes cause tests to fail. lang = 'en-GB'; } - date = new Date( dateString ); + var date = new Date( dateString ); try { if ( date instanceof Date && !isNaN( date ) ) { return date.toLocaleString( lang, { diff --git a/tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js b/tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js index 970fa63f0..b9d1e7885 100644 --- a/tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js +++ b/tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js @@ -1,48 +1,46 @@ -( function () { - QUnit.module( 'mmv.logging.ActionLogger', QUnit.newMwEnvironment() ); +QUnit.module( 'mmv.logging.ActionLogger', QUnit.newMwEnvironment() ); - QUnit.test( 'log()', function ( assert ) { - var fakeEventLog = { logEvent: this.sandbox.stub() }, - logger = new mw.mmv.logging.ActionLogger(), - action1key = 'test-1', - action1value = 'Test', - action2key = 'test-2', - action2value = 'Foo $1 $2 bar', - unknownAction = 'test-3', - clock = this.sandbox.useFakeTimers(); +QUnit.test( 'log()', function ( assert ) { + var fakeEventLog = { logEvent: this.sandbox.stub() }; + var logger = new mw.mmv.logging.ActionLogger(); + var action1key = 'test-1'; + var action1value = 'Test'; + var action2key = 'test-2'; + var action2value = 'Foo $1 $2 bar'; + var unknownAction = 'test-3'; + var clock = this.sandbox.useFakeTimers(); - this.sandbox.stub( logger, 'loadDependencies' ).returns( $.Deferred().resolve() ); - this.sandbox.stub( mw, 'log' ); + this.sandbox.stub( logger, 'loadDependencies' ).returns( $.Deferred().resolve() ); + this.sandbox.stub( mw, 'log' ); - logger.samplingFactorMap = { default: 1 }; - logger.setEventLog( fakeEventLog ); - logger.logActions = {}; - logger.logActions[ action1key ] = action1value; - logger.logActions[ action2key ] = action2value; + logger.samplingFactorMap = { default: 1 }; + logger.setEventLog( fakeEventLog ); + logger.logActions = {}; + logger.logActions[ action1key ] = action1value; + logger.logActions[ action2key ] = action2value; - logger.log( unknownAction ); - clock.tick( 10 ); + logger.log( unknownAction ); + clock.tick( 10 ); - assert.strictEqual( mw.log.lastCall.args[ 0 ], unknownAction, 'Log message defaults to unknown key' ); - assert.strictEqual( fakeEventLog.logEvent.called, true, 'event log has been recorded' ); + assert.strictEqual( mw.log.lastCall.args[ 0 ], unknownAction, 'Log message defaults to unknown key' ); + assert.strictEqual( fakeEventLog.logEvent.called, true, 'event log has been recorded' ); - mw.log.reset(); - fakeEventLog.logEvent.reset(); - logger.log( action1key ); - clock.tick( 10 ); + mw.log.reset(); + fakeEventLog.logEvent.reset(); + logger.log( action1key ); + clock.tick( 10 ); - assert.strictEqual( mw.log.lastCall.args[ 0 ], action1value, 'Log message is translated to its text' ); - assert.strictEqual( fakeEventLog.logEvent.called, true, 'event log has been recorded' ); + assert.strictEqual( mw.log.lastCall.args[ 0 ], action1value, 'Log message is translated to its text' ); + assert.strictEqual( fakeEventLog.logEvent.called, true, 'event log has been recorded' ); - mw.log.reset(); - fakeEventLog.logEvent.reset(); - logger.samplingFactorMap = { default: 0 }; - logger.log( action1key, true ); - clock.tick( 10 ); + mw.log.reset(); + fakeEventLog.logEvent.reset(); + logger.samplingFactorMap = { default: 0 }; + logger.log( action1key, true ); + clock.tick( 10 ); - assert.strictEqual( mw.log.called, false, 'No logging when disabled' ); - assert.strictEqual( fakeEventLog.logEvent.called, true, 'event log has been recorded' ); + assert.strictEqual( mw.log.called, false, 'No logging when disabled' ); + assert.strictEqual( fakeEventLog.logEvent.called, true, 'event log has been recorded' ); - clock.restore(); - } ); -}() ); + clock.restore(); +} ); diff --git a/tests/qunit/mmv/logging/mmv.logging.AttributionLogger.test.js b/tests/qunit/mmv/logging/mmv.logging.AttributionLogger.test.js index 01cc3fa80..c335841ae 100644 --- a/tests/qunit/mmv/logging/mmv.logging.AttributionLogger.test.js +++ b/tests/qunit/mmv/logging/mmv.logging.AttributionLogger.test.js @@ -1,22 +1,20 @@ -( function () { - QUnit.module( 'mmv.logging.AttributionLogger', QUnit.newMwEnvironment() ); +QUnit.module( 'mmv.logging.AttributionLogger', QUnit.newMwEnvironment() ); - QUnit.test( 'log()', function ( assert ) { - var fakeEventLog = { logEvent: this.sandbox.stub() }, - logger = new mw.mmv.logging.AttributionLogger(), - image = { author: 'foo', source: 'bar', license: {} }, - emptyImage = {}; +QUnit.test( 'log()', function ( assert ) { + var fakeEventLog = { logEvent: this.sandbox.stub() }; + var logger = new mw.mmv.logging.AttributionLogger(); + var image = { author: 'foo', source: 'bar', license: {} }; + var emptyImage = {}; - this.sandbox.stub( logger, 'loadDependencies' ).returns( $.Deferred().resolve() ); - this.sandbox.stub( mw, 'log' ); + this.sandbox.stub( logger, 'loadDependencies' ).returns( $.Deferred().resolve() ); + this.sandbox.stub( mw, 'log' ); - logger.samplingFactor = 1; - logger.setEventLog( fakeEventLog ); + logger.samplingFactor = 1; + logger.setEventLog( fakeEventLog ); - logger.logAttribution( image ); - assert.ok( true, 'logDimensions() did not throw errors' ); + logger.logAttribution( image ); + assert.ok( true, 'logDimensions() did not throw errors' ); - logger.logAttribution( emptyImage ); - assert.ok( true, 'logDimensions() did not throw errors for empty image' ); - } ); -}() ); + logger.logAttribution( emptyImage ); + assert.ok( true, 'logDimensions() did not throw errors for empty image' ); +} ); diff --git a/tests/qunit/mmv/logging/mmv.logging.DimensionLogger.test.js b/tests/qunit/mmv/logging/mmv.logging.DimensionLogger.test.js index 4a89cecc8..9409dd660 100644 --- a/tests/qunit/mmv/logging/mmv.logging.DimensionLogger.test.js +++ b/tests/qunit/mmv/logging/mmv.logging.DimensionLogger.test.js @@ -1,17 +1,15 @@ -( function () { - QUnit.module( 'mmv.logging.DimensionLogger', QUnit.newMwEnvironment() ); +QUnit.module( 'mmv.logging.DimensionLogger', QUnit.newMwEnvironment() ); - QUnit.test( 'log()', function ( assert ) { - var fakeEventLog = { logEvent: this.sandbox.stub() }, - logger = new mw.mmv.logging.DimensionLogger(); +QUnit.test( 'log()', function ( assert ) { + var fakeEventLog = { logEvent: this.sandbox.stub() }; + var logger = new mw.mmv.logging.DimensionLogger(); - this.sandbox.stub( logger, 'loadDependencies' ).returns( $.Deferred().resolve() ); - this.sandbox.stub( mw, 'log' ); + this.sandbox.stub( logger, 'loadDependencies' ).returns( $.Deferred().resolve() ); + this.sandbox.stub( mw, 'log' ); - logger.samplingFactor = 1; - logger.setEventLog( fakeEventLog ); + logger.samplingFactor = 1; + logger.setEventLog( fakeEventLog ); - logger.logDimensions( 640, 480, 200, 'resize' ); - assert.ok( true, 'logDimensions() did not throw errors' ); - } ); -}() ); + logger.logDimensions( 640, 480, 200, 'resize' ); + assert.ok( true, 'logDimensions() did not throw errors' ); +} ); diff --git a/tests/qunit/mmv/mmv.lightboximage.test.js b/tests/qunit/mmv/mmv.lightboximage.test.js index e95376df6..ce58c27b9 100644 --- a/tests/qunit/mmv/mmv.lightboximage.test.js +++ b/tests/qunit/mmv/mmv.lightboximage.test.js @@ -1,10 +1,7 @@ -( function () { - QUnit.module( 'mmv.lightboximage', QUnit.newMwEnvironment() ); +QUnit.module( 'mmv.lightboximage', QUnit.newMwEnvironment() ); - QUnit.test( 'Sense test, object creation', function ( assert ) { - var lightboxImage = new mw.mmv.LightboxImage( 'foo.png' ); +QUnit.test( 'Sense test', function ( assert ) { + var lightboxImage = new mw.mmv.LightboxImage( 'foo.png' ); - assert.ok( lightboxImage, 'Object created !' ); - } ); - -}() ); + assert.ok( lightboxImage, 'Object created' ); +} ); diff --git a/tests/qunit/mmv/mmv.testhelpers.js b/tests/qunit/mmv/mmv.testhelpers.js index 61f610e14..9dc91ec26 100644 --- a/tests/qunit/mmv/mmv.testhelpers.js +++ b/tests/qunit/mmv/mmv.testhelpers.js @@ -126,15 +126,15 @@ * @return {Function} */ MTH.asyncMethod = function ( object, method, assert ) { + var helpers = this; return function () { // apply arguments to original promise - var promise = object[ method ].apply( object, arguments ), - done; + var promise = object[ method ].apply( object, arguments ); - this.asyncPromises.push( promise ); + helpers.asyncPromises.push( promise ); if ( assert ) { - done = assert.async(); + var done = assert.async(); // use setTimeout to ensure `done` is not the first callback handler // to execute (possibly ending the test's wait right before // the result of the promise is executed) @@ -142,7 +142,7 @@ } return promise; - }.bind( this ); + }; }; /** diff --git a/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js b/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js index 57522a29b..8abbbb5d4 100644 --- a/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js @@ -1,189 +1,203 @@ -( function () { - var thingsShouldBeEmptied = [ - '$license', - '$title', - '$location', - '$datetime' - ], +QUnit.module( 'mmv.ui.metadataPanel', QUnit.newMwEnvironment() ); - thingsShouldHaveEmptyClass = [ - '$licenseLi', - '$credit', - '$locationLi', - '$datetimeLi' - ]; +QUnit.test( '.empty()', function ( assert ) { + var $qf = $( '#qunit-fixture' ); + var panel = new mw.mmv.ui.MetadataPanel( + $qf, + $( '
' ).appendTo( $qf ), + mw.storage, + new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) + ); + panel.empty(); - QUnit.module( 'mmv.ui.metadataPanel', QUnit.newMwEnvironment() ); - - QUnit.test( 'The panel is emptied properly when necessary', function ( assert ) { - var i, - $qf = $( '#qunit-fixture' ), - panel = new mw.mmv.ui.MetadataPanel( $qf, $( '
' ).appendTo( $qf ), mw.storage, new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) ); - - panel.empty(); - - for ( i = 0; i < thingsShouldBeEmptied.length; i++ ) { - assert.strictEqual( panel[ thingsShouldBeEmptied[ i ] ].text(), '', 'We successfully emptied the ' + thingsShouldBeEmptied[ i ] + ' element' ); - } - - for ( i = 0; i < thingsShouldHaveEmptyClass.length; i++ ) { - assert.strictEqual( panel[ thingsShouldHaveEmptyClass[ i ] ].hasClass( 'empty' ), true, 'We successfully applied the empty class to the ' + thingsShouldHaveEmptyClass[ i ] + ' element' ); - } + [ + '$license', + '$title', + '$location', + '$datetime' + ].forEach( function ( thing ) { + assert.strictEqual( panel[ thing ].text(), '', thing + ' empty text' ); } ); - QUnit.test( 'Setting location information works as expected', function ( assert ) { - var $qf = $( '#qunit-fixture' ), - panel = new mw.mmv.ui.MetadataPanel( $qf, $( '
' ).appendTo( $qf ), mw.storage, new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) ), - 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(), - '(multimediaviewer-geolocation: (multimediaviewer-geoloc-coords: (multimediaviewer-geoloc-coord: 12, 20, 44.44, (multimediaviewer-geoloc-north)), (multimediaviewer-geoloc-coord: 98, 45, 55.56, (multimediaviewer-geoloc-east))))', - '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=qqx', - 'Location URL is set as expected' - ); - - latitude = -latitude; - longitude = -longitude; - imageData.latitude = latitude; - imageData.longitude = longitude; - panel.setLocationData( imageData ); - - assert.strictEqual( - panel.$location.text(), - '(multimediaviewer-geolocation: (multimediaviewer-geoloc-coords: (multimediaviewer-geoloc-coord: 12, 20, 44.44, (multimediaviewer-geoloc-south)), (multimediaviewer-geoloc-coord: 98, 45, 55.56, (multimediaviewer-geoloc-west))))', - '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=qqx', - 'Location URL is set as expected' - ); - - latitude = 0; - longitude = 0; - imageData.latitude = latitude; - imageData.longitude = longitude; - panel.setLocationData( imageData ); - - assert.strictEqual( - panel.$location.text(), - '(multimediaviewer-geolocation: (multimediaviewer-geoloc-coords: (multimediaviewer-geoloc-coord: 0, 0, 0, (multimediaviewer-geoloc-north)), (multimediaviewer-geoloc-coord: 0, 0, 0, (multimediaviewer-geoloc-east))))', - '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=qqx', - 'Location URL is set as expected' - ); + [ + '$licenseLi', + '$credit', + '$locationLi', + '$datetimeLi' + ].forEach( function ( thing ) { + assert.true( panel[ thing ].hasClass( 'empty' ), thing + ' empty class' ); } ); +} ); - QUnit.test( 'Setting image information works as expected', function ( assert ) { - var creditPopupText, - $qf = $( '#qunit-fixture' ), - panel = new mw.mmv.ui.MetadataPanel( $qf, $( '
' ).appendTo( $qf ), mw.storage, new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) ), - 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; } - }, - clock = this.sandbox.useFakeTimers(); +QUnit.test( '.setLocationData()', function ( assert ) { + var $qf = $( '#qunit-fixture' ); + var panel = new mw.mmv.ui.MetadataPanel( + $qf, + $( '
' ).appendTo( $qf ), + mw.storage, + new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) + ); + var fileName = 'Foobar.jpg'; + var latitude = 12.3456789; + var longitude = 98.7654321; + var imageData = { + latitude: latitude, + longitude: longitude, + hasCoords: function () { return true; }, + title: mw.Title.newFromText( 'File:Foobar.jpg' ) + }; - panel.setImageInfo( image, imageData, repoData ); + panel.setLocationData( imageData ); - assert.strictEqual( panel.$title.text(), title, 'Title is correctly set' ); - assert.ok( panel.$credit.text(), 'Default credit is shown' ); - assert.strictEqual( panel.$license.prop( 'href' ), imageData.descriptionUrl, - 'User is directed to file page for license information' ); - assert.notOk( panel.$license.prop( 'target' ), 'License information opens in same window' ); - assert.strictEqual( panel.$datetimeLi.hasClass( 'empty' ), true, 'Date/Time is empty' ); - assert.strictEqual( panel.$locationLi.hasClass( 'empty' ), true, 'Location is empty' ); + assert.strictEqual( + panel.$location.text(), + '(multimediaviewer-geolocation: (multimediaviewer-geoloc-coords: (multimediaviewer-geoloc-coord: 12, 20, 44.44, (multimediaviewer-geoloc-north)), (multimediaviewer-geoloc-coord: 98, 45, 55.56, (multimediaviewer-geoloc-east))))', + '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=qqx', + 'Location URL is set as expected' + ); - 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/' ); - imageData.restrictions = [ 'trademarked', 'default', 'insignia' ]; + latitude = -latitude; + longitude = -longitude; + imageData.latitude = latitude; + imageData.longitude = longitude; + panel.setLocationData( imageData ); - panel.setImageInfo( image, imageData, repoData ); - creditPopupText = panel.creditField.$element.attr( 'original-title' ); - clock.tick( 10 ); + assert.strictEqual( + panel.$location.text(), + '(multimediaviewer-geolocation: (multimediaviewer-geoloc-coords: (multimediaviewer-geoloc-coord: 12, 20, 44.44, (multimediaviewer-geoloc-south)), (multimediaviewer-geoloc-coord: 98, 45, 55.56, (multimediaviewer-geoloc-west))))', + '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=qqx', + 'Location URL is set as expected' + ); - assert.strictEqual( panel.$title.text(), title, 'Title is correctly set' ); - assert.strictEqual( panel.$credit.hasClass( 'empty' ), false, 'Credit is not empty' ); - assert.strictEqual( panel.$datetimeLi.hasClass( 'empty' ), false, 'Date/Time is not empty' ); - assert.strictEqual( panel.creditField.$element.find( '.mw-mmv-author' ).text(), imageData.author, 'Author text is correctly set' ); - assert.strictEqual( panel.creditField.$element.find( '.mw-mmv-source' ).html(), 'LostBar', 'Source text is correctly set' ); - // Either multimediaviewer-credit-popup-text or multimediaviewer-credit-popup-text-more. - assert.ok( creditPopupText === '(multimediaviewer-credit-popup-text)' || creditPopupText === '(multimediaviewer-credit-popup-text-more)', 'Source tooltip is correctly set' ); - assert.strictEqual( panel.$datetime.text(), '(multimediaviewer-datetime-created: 26 August 2013)', 'Correct date is displayed' ); - assert.strictEqual( panel.$license.text(), '(multimediaviewer-license-cc-by-2.0)', 'License is correctly set' ); - assert.ok( panel.$license.prop( 'target' ), 'License information opens in new window' ); - assert.strictEqual( panel.$restrictions.children().last().children().hasClass( 'mw-mmv-restriction-default' ), true, 'Default restriction is correctly displayed last' ); + latitude = 0; + longitude = 0; + imageData.latitude = latitude; + imageData.longitude = longitude; + panel.setLocationData( imageData ); - imageData.creationDateTime = undefined; - panel.setImageInfo( image, imageData, repoData ); - clock.tick( 10 ); + assert.strictEqual( + panel.$location.text(), + '(multimediaviewer-geolocation: (multimediaviewer-geoloc-coords: (multimediaviewer-geoloc-coord: 0, 0, 0, (multimediaviewer-geoloc-north)), (multimediaviewer-geoloc-coord: 0, 0, 0, (multimediaviewer-geoloc-east))))', + '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=qqx', + 'Location URL is set as expected' + ); +} ); - assert.strictEqual( panel.$datetime.text(), '(multimediaviewer-datetime-uploaded: 25 August 2013)', 'Correct date is displayed' ); +QUnit.test( '.setImageInfo()', function ( assert ) { + var $qf = $( '#qunit-fixture' ); + var panel = new mw.mmv.ui.MetadataPanel( + $qf, + $( '
' ).appendTo( $qf ), + mw.storage, + new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) + ); + var title = 'Foo bar'; + var image = { + filePageTitle: mw.Title.newFromText( 'File:' + title + '.jpg' ) + }; + var 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; } + }; + var repoData = { + getArticlePath: function () { return 'Foo'; }, + isCommons: function () { return false; } + }; + var clock = this.sandbox.useFakeTimers(); - clock.restore(); - } ); + panel.setImageInfo( image, imageData, repoData ); - QUnit.test( 'Setting permission information works as expected', function ( assert ) { - var $qf = $( '#qunit-fixture' ), - panel = new mw.mmv.ui.MetadataPanel( $qf, $( '
' ).appendTo( $qf ), mw.storage, new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) ); + assert.strictEqual( panel.$title.text(), title, 'Title is correctly set' ); + assert.ok( panel.$credit.text(), 'Default credit is shown' ); + assert.strictEqual( panel.$license.prop( 'href' ), imageData.descriptionUrl, + 'User is directed to file page for license information' ); + assert.notOk( panel.$license.prop( 'target' ), 'License information opens in same window' ); + assert.true( panel.$datetimeLi.hasClass( 'empty' ), 'Date/Time is empty' ); + assert.true( panel.$locationLi.hasClass( 'empty' ), 'Location is empty' ); - panel.setLicense( null, 'http://example.com' ); // make sure license is visible as it contains the permission - panel.setPermission( 'Look at me, I am a permission!' ); - assert.strictEqual( panel.$permissionLink.is( ':visible' ), true ); - } ); + 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/' ); + imageData.restrictions = [ 'trademarked', 'default', 'insignia' ]; - QUnit.test( 'Date formatting', function ( assert ) { - var $qf = $( '#qunit-fixture' ), - panel = new mw.mmv.ui.MetadataPanel( $qf, $( '
' ).appendTo( $qf ), mw.storage, new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) ), - date1 = 'Garbage', - result = panel.formatDate( date1 ); + panel.setImageInfo( image, imageData, repoData ); + var creditPopupText = panel.creditField.$element.attr( 'original-title' ); + clock.tick( 10 ); - assert.strictEqual( result, date1, 'Invalid date is correctly ignored' ); - } ); + assert.strictEqual( panel.$title.text(), title, 'Title is correctly set' ); + assert.false( panel.$credit.hasClass( 'empty' ), 'Credit is not empty' ); + assert.false( panel.$datetimeLi.hasClass( 'empty' ), 'Date/Time is not empty' ); + assert.strictEqual( panel.creditField.$element.find( '.mw-mmv-author' ).text(), imageData.author, 'Author text is correctly set' ); + assert.strictEqual( panel.creditField.$element.find( '.mw-mmv-source' ).html(), 'LostBar', 'Source text is correctly set' ); + // Either multimediaviewer-credit-popup-text or multimediaviewer-credit-popup-text-more. + assert.ok( creditPopupText === '(multimediaviewer-credit-popup-text)' || creditPopupText === '(multimediaviewer-credit-popup-text-more)', 'Source tooltip is correctly set' ); + assert.strictEqual( panel.$datetime.text(), '(multimediaviewer-datetime-created: 26 August 2013)', 'Correct date is displayed' ); + assert.strictEqual( panel.$license.text(), '(multimediaviewer-license-cc-by-2.0)', 'License is correctly set' ); + assert.ok( panel.$license.prop( 'target' ), 'License information opens in new window' ); + assert.true( panel.$restrictions.children().last().children().hasClass( 'mw-mmv-restriction-default' ), 'Default restriction is correctly displayed last' ); - QUnit.test( 'About links', function ( assert ) { - var $qf = $( '#qunit-fixture' ); + imageData.creationDateTime = undefined; + panel.setImageInfo( image, imageData, repoData ); + clock.tick( 10 ); - this.sandbox.stub( mw.user, 'isAnon' ); - // eslint-disable-next-line no-new - new mw.mmv.ui.MetadataPanel( $qf.empty(), $( '
' ).appendTo( $qf ), mw.storage, new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) ); + assert.strictEqual( panel.$datetime.text(), '(multimediaviewer-datetime-uploaded: 25 August 2013)', 'Correct date is displayed' ); - assert.strictEqual( $qf.find( '.mw-mmv-about-link' ).length, 1, 'About link is created.' ); - } ); -}() ); + clock.restore(); +} ); + +QUnit.test( 'Setting permission information works as expected', function ( assert ) { + var $qf = $( '#qunit-fixture' ); + var panel = new mw.mmv.ui.MetadataPanel( + $qf, + $( '
' ).appendTo( $qf ), + mw.storage, + new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) + ); + + // make sure license is visible as it contains the permission + panel.setLicense( null, 'http://example.com' ); + panel.setPermission( 'Look at me, I am a permission!' ); + assert.true( panel.$permissionLink.is( ':visible' ) ); +} ); + +QUnit.test( 'Date formatting', function ( assert ) { + var $qf = $( '#qunit-fixture' ); + var panel = new mw.mmv.ui.MetadataPanel( + $qf, + $( '
' ).appendTo( $qf ), + mw.storage, + new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) + ); + var date1 = 'Garbage'; + var result = panel.formatDate( date1 ); + + assert.strictEqual( result, date1, 'Invalid date is correctly ignored' ); +} ); + +QUnit.test( 'About links', function ( assert ) { + var $qf = $( '#qunit-fixture' ); + + this.sandbox.stub( mw.user, 'isAnon' ); + // eslint-disable-next-line no-new + new mw.mmv.ui.MetadataPanel( $qf.empty(), $( '
' ).appendTo( $qf ), mw.storage, new mw.mmv.Config( {}, mw.config, mw.user, new mw.Api(), mw.storage ) ); + + assert.strictEqual( $qf.find( '.mw-mmv-about-link' ).length, 1, 'About link is created.' ); +} );