2013-11-27 21:57:45 +00:00
|
|
|
( function ( mw, $ ) {
|
2014-01-23 21:44:26 +00:00
|
|
|
QUnit.module( 'mmv', QUnit.newMwEnvironment() );
|
2013-11-27 21:57:45 +00:00
|
|
|
|
2014-01-07 19:58:29 +00:00
|
|
|
QUnit.test( 'Metadata div is only animated once', 4, function ( assert ) {
|
2014-02-18 09:01:37 +00:00
|
|
|
localStorage.removeItem( 'mmv.hasOpenedMetadata' );
|
|
|
|
|
2014-01-07 19:58:29 +00:00
|
|
|
var viewer = new mw.MultimediaViewer(),
|
|
|
|
backupAnimation = $.fn.animate,
|
|
|
|
animationRan = false;
|
|
|
|
|
|
|
|
$.fn.animate = function () {
|
|
|
|
animationRan = true;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.animateMetadataDivOnce();
|
|
|
|
assert.strictEqual( viewer.hasAnimatedMetadata, true, 'The first call to animateMetadataDivOnce set hasAnimatedMetadata to true' );
|
|
|
|
assert.strictEqual( animationRan, true, 'The first call to animateMetadataDivOnce led to an animation' );
|
|
|
|
|
|
|
|
animationRan = false;
|
|
|
|
viewer.animateMetadataDivOnce();
|
|
|
|
assert.strictEqual( viewer.hasAnimatedMetadata, true, 'The second call to animateMetadataDivOnce did not change the value of hasAnimatedMetadata' );
|
|
|
|
assert.strictEqual( animationRan, false, 'The second call to animateMetadataDivOnce did not lead to an animation' );
|
|
|
|
|
|
|
|
$.fn.animate = backupAnimation;
|
2014-01-31 09:29:39 +00:00
|
|
|
} );
|
2014-02-13 09:52:40 +00:00
|
|
|
|
|
|
|
QUnit.test( 'eachPrealoadableLightboxIndex()', 11, function ( assert ) {
|
|
|
|
var viewer = mw.mediaViewer,
|
|
|
|
oldLightbox,
|
|
|
|
oldPreloadDistance,
|
|
|
|
oldPosition,
|
2014-02-17 15:09:23 +00:00
|
|
|
oldThumbs,
|
2014-02-13 09:52:40 +00:00
|
|
|
expectedIndices,
|
|
|
|
i;
|
|
|
|
|
|
|
|
oldLightbox = viewer.lightbox;
|
|
|
|
viewer.lightbox = viewer.lightbox || {}; // might not be set up at this point
|
|
|
|
oldPreloadDistance = viewer.preloadDistance;
|
|
|
|
oldPosition = viewer.lightbox.currentIndex;
|
2014-02-17 15:09:23 +00:00
|
|
|
oldThumbs = viewer.thumbs;
|
2014-02-13 09:52:40 +00:00
|
|
|
|
|
|
|
viewer.preloadDistance = 3;
|
2014-02-17 15:09:23 +00:00
|
|
|
viewer.thumbs = [];
|
|
|
|
|
|
|
|
// 0..10
|
|
|
|
for ( i = 0; i < 11; i++ ) {
|
|
|
|
viewer.thumbs.push( { image : false } );
|
|
|
|
}
|
2014-02-13 09:52:40 +00:00
|
|
|
|
|
|
|
viewer.lightbox.currentIndex = 2;
|
|
|
|
i = 0;
|
|
|
|
expectedIndices = [2, 3, 1, 4, 0, 5];
|
|
|
|
viewer.eachPrealoadableLightboxIndex( function( index ) {
|
|
|
|
assert.strictEqual( index, expectedIndices[i++], 'preload on left edge');
|
|
|
|
} );
|
|
|
|
|
|
|
|
viewer.lightbox.currentIndex = 9;
|
|
|
|
i = 0;
|
|
|
|
expectedIndices = [9, 10, 8, 7, 6];
|
|
|
|
viewer.eachPrealoadableLightboxIndex( function( index ) {
|
|
|
|
assert.strictEqual( index, expectedIndices[i++], 'preload on right edge');
|
|
|
|
} );
|
|
|
|
|
|
|
|
viewer.lightbox = oldLightbox;
|
|
|
|
viewer.preloadDistance = oldPreloadDistance;
|
2014-02-17 15:09:23 +00:00
|
|
|
viewer.thumbs = oldThumbs;
|
|
|
|
|
2014-02-13 09:52:40 +00:00
|
|
|
if ( viewer.lightbox ) {
|
|
|
|
viewer.lightbox.currentIndex = oldPosition;
|
|
|
|
}
|
|
|
|
} );
|
2013-11-27 21:57:45 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|