mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-24 08:13:38 +00:00
Add test for clicking prev/next
Change-Id: I02653d97500d5a876f142a518d9b53b0d4746aef Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/145
This commit is contained in:
parent
fedaa553b4
commit
a82728ccdb
|
@ -139,6 +139,7 @@ class MultimediaViewerHooks {
|
|||
'tests/qunit/mmv/provider/mmv.provider.UserInfo.test.js',
|
||||
'tests/qunit/mmv/provider/mmv.provider.Image.test.js',
|
||||
'tests/qunit/mmv/ui/mmv.ui.test.js',
|
||||
'tests/qunit/mmv/ui/mmv.ui.buttons.test.js',
|
||||
'tests/qunit/mmv/ui/mmv.ui.canvas.test.js',
|
||||
'tests/qunit/mmv/ui/mmv.ui.categories.test.js',
|
||||
'tests/qunit/mmv/ui/mmv.ui.description.test.js',
|
||||
|
|
|
@ -1,23 +1,31 @@
|
|||
( function ( mw, $ ) {
|
||||
var oldSetupEventHandlers;
|
||||
|
||||
QUnit.module( 'mmv', QUnit.newMwEnvironment() );
|
||||
|
||||
// Because we don't want that throwaway instance to listen to events, could interfere with other tests
|
||||
function newViewer() {
|
||||
oldSetupEventHandlers = mw.mmv.MultimediaViewer.prototype.setupEventHandlers;
|
||||
mw.mmv.MultimediaViewer.prototype.setupEventHandlers = $.noop;
|
||||
return new mw.mmv.MultimediaViewer();
|
||||
}
|
||||
|
||||
function cleanNewViewer() {
|
||||
mw.mmv.MultimediaViewer.prototype.setupEventHandlers = oldSetupEventHandlers;
|
||||
}
|
||||
|
||||
QUnit.test( 'Metadata div is only animated once', 4, function ( assert ) {
|
||||
localStorage.removeItem( 'mmv.hasOpenedMetadata' );
|
||||
|
||||
var viewer,
|
||||
var viewer = newViewer(),
|
||||
backupAnimation = $.fn.animate,
|
||||
animationRan = false,
|
||||
oldSetupEventHandlers = mw.mmv.MultimediaViewer.prototype.setupEventHandlers;
|
||||
animationRan = false;
|
||||
|
||||
$.fn.animate = function () {
|
||||
animationRan = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
// Because we don't want that throwaway instance to listen to events, could interfere with other tests
|
||||
mw.mmv.MultimediaViewer.prototype.setupEventHandlers = $.noop;
|
||||
viewer = new mw.mmv.MultimediaViewer();
|
||||
|
||||
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' );
|
||||
|
@ -29,7 +37,7 @@
|
|||
|
||||
$.fn.animate = backupAnimation;
|
||||
|
||||
mw.mmv.MultimediaViewer.prototype.setupEventHandlers = oldSetupEventHandlers;
|
||||
cleanNewViewer();
|
||||
} );
|
||||
|
||||
QUnit.test( 'eachPrealoadableLightboxIndex()', 11, function ( assert ) {
|
||||
|
@ -155,7 +163,7 @@
|
|||
|
||||
QUnit.test( 'Progress', 3, function ( assert ) {
|
||||
var imageDeferred = $.Deferred(),
|
||||
viewer = new mw.mmv.MultimediaViewer(),
|
||||
viewer = newViewer(),
|
||||
oldImageGet = mw.mmv.provider.Image.prototype.get,
|
||||
oldImageInfoGet = mw.mmv.provider.ImageInfo.prototype.get,
|
||||
oldThumbnailInfoGet = mw.mmv.provider.ThumbnailInfo.prototype.get,
|
||||
|
@ -203,10 +211,12 @@
|
|||
mw.mmv.provider.Image.prototype.get = oldImageGet;
|
||||
mw.mmv.provider.ImageInfo.prototype.get = oldImageInfoGet;
|
||||
mw.mmv.provider.ThumbnailInfo.prototype.get = oldThumbnailInfoGet;
|
||||
|
||||
cleanNewViewer();
|
||||
} );
|
||||
|
||||
QUnit.test( 'resetBlurredThumbnailStates', 4, function ( assert ) {
|
||||
var viewer = new mw.mmv.MultimediaViewer();
|
||||
var viewer = newViewer();
|
||||
|
||||
assert.ok( !viewer.realThumbnailShown, 'Real thumbnail state is correct' );
|
||||
assert.ok( !viewer.blurredThumbnailShown, 'Placeholder state is correct' );
|
||||
|
@ -218,10 +228,12 @@
|
|||
|
||||
assert.ok( !viewer.realThumbnailShown, 'Real thumbnail state is correct' );
|
||||
assert.ok( !viewer.blurredThumbnailShown, 'Placeholder state is correct' );
|
||||
|
||||
cleanNewViewer();
|
||||
} );
|
||||
|
||||
QUnit.test( 'Placeholder first, then real thumbnail', 4, function ( assert ) {
|
||||
var viewer = new mw.mmv.MultimediaViewer();
|
||||
var viewer = newViewer();
|
||||
|
||||
viewer.setImage = $.noop;
|
||||
viewer.lightbox = { iface : { canvas : {
|
||||
|
@ -237,10 +249,12 @@
|
|||
|
||||
assert.ok( viewer.realThumbnailShown, 'Real thumbnail state is correct' );
|
||||
assert.ok( viewer.blurredThumbnailShown, 'Placeholder state is correct' );
|
||||
|
||||
cleanNewViewer();
|
||||
} );
|
||||
|
||||
QUnit.test( 'Real thumbnail first, then placeholder', 4, function ( assert ) {
|
||||
var viewer = new mw.mmv.MultimediaViewer();
|
||||
var viewer = newViewer();
|
||||
|
||||
viewer.setImage = $.noop;
|
||||
viewer.lightbox = { iface : {
|
||||
|
@ -256,10 +270,12 @@
|
|||
|
||||
assert.ok( viewer.realThumbnailShown, 'Real thumbnail state is correct' );
|
||||
assert.ok( !viewer.blurredThumbnailShown, 'Placeholder state is correct' );
|
||||
|
||||
cleanNewViewer();
|
||||
} );
|
||||
|
||||
QUnit.test( 'displayRealThumbnail', 1, function ( assert ) {
|
||||
var viewer = new mw.mmv.MultimediaViewer();
|
||||
var viewer = newViewer();
|
||||
|
||||
viewer.setImage = $.noop;
|
||||
viewer.lightbox = { iface : { canvas : {
|
||||
|
@ -276,12 +292,14 @@
|
|||
|
||||
// Should result in an unblur (image didn't come from cache)
|
||||
viewer.displayRealThumbnail( undefined, undefined, undefined, 1000 );
|
||||
|
||||
cleanNewViewer();
|
||||
} );
|
||||
|
||||
QUnit.test( 'New image loaded while another one is loading', 1, function ( assert ) {
|
||||
var imageDeferred,
|
||||
ligthboxInfoDeferred,
|
||||
viewer = new mw.mmv.MultimediaViewer(),
|
||||
viewer = newViewer(),
|
||||
oldImageGet = mw.mmv.provider.Image.prototype.get,
|
||||
oldImageInfoGet = mw.mmv.provider.ImageInfo.prototype.get,
|
||||
oldThumbnailInfoGet = mw.mmv.provider.ThumbnailInfo.prototype.get,
|
||||
|
@ -348,5 +366,7 @@
|
|||
mw.mmv.provider.Image.prototype.get = oldImageGet;
|
||||
mw.mmv.provider.ImageInfo.prototype.get = oldImageInfoGet;
|
||||
mw.mmv.provider.ThumbnailInfo.prototype.get = oldThumbnailInfoGet;
|
||||
|
||||
cleanNewViewer();
|
||||
} );
|
||||
}( mediaWiki, jQuery ) );
|
||||
|
|
40
tests/qunit/mmv/ui/mmv.ui.buttons.test.js
Normal file
40
tests/qunit/mmv/ui/mmv.ui.buttons.test.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of the MediaWiki extension MediaViewer.
|
||||
*
|
||||
* MediaViewer is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MediaViewer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
( function( mw, $ ) {
|
||||
QUnit.module( 'mmv.ui.Buttons', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Prev/Next', 2, function( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
buttons = new mw.mmv.ui.Buttons( $qf, $( '<div>' ), $( '<div>' ) ),
|
||||
viewer = mw.mmv.mediaViewer,
|
||||
oldLoadIndex = viewer.loadIndex,
|
||||
oldLightbox = viewer.lightbox;
|
||||
|
||||
viewer.lightbox = {};
|
||||
|
||||
viewer.loadIndex = function () {
|
||||
assert.ok( true, 'Switched to next/prev image' );
|
||||
};
|
||||
|
||||
buttons.$next.click();
|
||||
buttons.$prev.click();
|
||||
|
||||
viewer.loadIndex = oldLoadIndex;
|
||||
viewer.lightbox = oldLightbox;
|
||||
} );
|
||||
}( mediaWiki, jQuery ) );
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
|
||||
( function( mw, $ ) {
|
||||
QUnit.module( 'mw.mmv.ui.Canvas', QUnit.newMwEnvironment() );
|
||||
QUnit.module( 'mmv.ui.Canvas', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Constructor sanity check', 3, function( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
|
|
Loading…
Reference in a new issue