mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-17 21:04:11 +00:00
035afe6d36
And stop showing when the user has opened the metadata once Change-Id: Iefce36acf1b78301584ca8c1359fac94956a9440 Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/213
74 lines
2.2 KiB
JavaScript
74 lines
2.2 KiB
JavaScript
( function ( mw, $ ) {
|
|
QUnit.module( 'mmv', QUnit.newMwEnvironment() );
|
|
|
|
QUnit.test( 'Metadata div is only animated once', 4, function ( assert ) {
|
|
localStorage.removeItem( 'mmv.hasOpenedMetadata' );
|
|
|
|
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;
|
|
} );
|
|
|
|
QUnit.test( 'eachPrealoadableLightboxIndex()', 11, function ( assert ) {
|
|
var viewer = mw.mediaViewer,
|
|
oldLightbox,
|
|
oldPreloadDistance,
|
|
oldPosition,
|
|
oldThumbs,
|
|
expectedIndices,
|
|
i;
|
|
|
|
oldLightbox = viewer.lightbox;
|
|
viewer.lightbox = viewer.lightbox || {}; // might not be set up at this point
|
|
oldPreloadDistance = viewer.preloadDistance;
|
|
oldPosition = viewer.lightbox.currentIndex;
|
|
oldThumbs = viewer.thumbs;
|
|
|
|
viewer.preloadDistance = 3;
|
|
viewer.thumbs = [];
|
|
|
|
// 0..10
|
|
for ( i = 0; i < 11; i++ ) {
|
|
viewer.thumbs.push( { image : false } );
|
|
}
|
|
|
|
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;
|
|
viewer.thumbs = oldThumbs;
|
|
|
|
if ( viewer.lightbox ) {
|
|
viewer.lightbox.currentIndex = oldPosition;
|
|
}
|
|
} );
|
|
}( mediaWiki, jQuery ) );
|