2013-12-05 00:30:08 +00:00
|
|
|
( function ( mw, $ ) {
|
2014-01-23 21:44:26 +00:00
|
|
|
QUnit.module( 'multilightbox.interface', QUnit.newMwEnvironment() );
|
2013-12-06 20:10:51 +00:00
|
|
|
|
2014-02-03 11:23:31 +00:00
|
|
|
QUnit.test( 'Sanity test, object creation and ui construction', 9, function ( assert ) {
|
2013-12-05 00:30:08 +00:00
|
|
|
var lightbox = new window.LightboxInterface();
|
|
|
|
|
|
|
|
function checkIfUIAreasAttachedToDocument( inDocument ) {
|
|
|
|
var msg = inDocument === 1 ? ' ' : ' not ';
|
|
|
|
assert.strictEqual( $( '.mlb-wrapper' ).length, inDocument, 'Wrapper area' + msg + 'attached.' );
|
|
|
|
assert.strictEqual( $( '.mlb-main' ).length, inDocument, 'Main area' + msg + 'attached.' );
|
|
|
|
assert.strictEqual( $( '.mlb-overlay' ).length, inDocument, 'Overlay area' + msg + 'attached.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// UI areas not attached to the document yet.
|
|
|
|
checkIfUIAreasAttachedToDocument(0);
|
|
|
|
|
2013-12-11 02:08:07 +00:00
|
|
|
// Attach lightbox to testing fixture to avoid interference with other tests.
|
|
|
|
lightbox.attach( '#qunit-fixture' );
|
2013-12-05 00:30:08 +00:00
|
|
|
|
|
|
|
// UI areas should now be attached to the document.
|
|
|
|
checkIfUIAreasAttachedToDocument(1);
|
|
|
|
|
|
|
|
// Unattach lightbox from document
|
2014-02-03 11:23:31 +00:00
|
|
|
lightbox.unattach();
|
2013-12-05 00:30:08 +00:00
|
|
|
|
2014-02-03 11:23:31 +00:00
|
|
|
checkIfUIAreasAttachedToDocument(0);
|
2013-12-05 00:30:08 +00:00
|
|
|
} );
|
2013-11-21 19:50:27 +00:00
|
|
|
|
|
|
|
QUnit.asyncTest( 'Check we are saving the resize listener', 2, function ( assert ) {
|
|
|
|
var img = new window.LightboxImage('http://en.wikipedia.org/w/skins/vector/images/search-ltr.png'),
|
2013-12-11 02:08:07 +00:00
|
|
|
lightbox = new window.LightboxInterface();
|
2013-11-21 19:50:27 +00:00
|
|
|
|
|
|
|
// resizeListener not saved yet
|
|
|
|
assert.strictEqual( this.resizeListener, undefined, 'Listener is not saved yet' );
|
|
|
|
|
|
|
|
// Save original loadCallback
|
|
|
|
lightbox.originalLoadCallback = lightbox.loadCallback;
|
|
|
|
|
|
|
|
// Mock loadCallback
|
|
|
|
lightbox.loadCallback = function ( image, ele ) {
|
|
|
|
// Call original loadCallback
|
|
|
|
this.originalLoadCallback( image, ele );
|
|
|
|
|
|
|
|
// resizeListener should have been saved
|
|
|
|
assert.notStrictEqual( this.resizeListener, undefined, 'Saved listener !' );
|
|
|
|
QUnit.start();
|
|
|
|
};
|
|
|
|
|
|
|
|
lightbox.load(img);
|
|
|
|
} );
|
|
|
|
|
2014-01-31 09:58:28 +00:00
|
|
|
QUnit.test( 'Fullscreen mode', 8, function ( assert ) {
|
2014-01-27 16:47:23 +00:00
|
|
|
var lightbox = new window.LightboxInterface(),
|
|
|
|
oldFnEnterFullscreen = $.fn.enterFullscreen,
|
2014-01-31 09:58:28 +00:00
|
|
|
oldFnExitFullscreen = $.fn.exitFullscreen,
|
|
|
|
oldSupportFullscreen = $.support.fullscreen;
|
2014-01-27 16:47:23 +00:00
|
|
|
|
|
|
|
// Since we don't want these tests to really open fullscreen
|
|
|
|
// which is subject to user security confirmation,
|
2014-01-30 07:22:26 +00:00
|
|
|
// we use a mock that pretends regular jquery.fullscreen behavior happened
|
|
|
|
$.fn.enterFullscreen = mw.mmvTestHelpers.enterFullscreenMock;
|
|
|
|
$.fn.exitFullscreen = mw.mmvTestHelpers.exitFullscreenMock;
|
2014-01-27 16:47:23 +00:00
|
|
|
|
|
|
|
// Attach lightbox to testing fixture to avoid interference with other tests.
|
|
|
|
lightbox.attach( '#qunit-fixture' );
|
|
|
|
|
2014-01-31 09:58:28 +00:00
|
|
|
$.support.fullscreen = false;
|
|
|
|
lightbox.setupFullscreenButton();
|
|
|
|
|
|
|
|
assert.ok( !lightbox.$fullscreenButton.is(':visible'),
|
|
|
|
'Fullscreen button is hidden when fullscreen mode is unavailable' );
|
|
|
|
|
|
|
|
$.support.fullscreen = true;
|
|
|
|
lightbox.setupFullscreenButton();
|
|
|
|
|
|
|
|
assert.ok( lightbox.$fullscreenButton.is(':visible'),
|
|
|
|
'Fullscreen button is visible when fullscreen mode is available' );
|
|
|
|
|
2014-01-27 16:47:23 +00:00
|
|
|
// Entering fullscreen
|
|
|
|
lightbox.$fullscreenButton.click();
|
|
|
|
|
|
|
|
assert.strictEqual( lightbox.$main.hasClass( 'jq-fullscreened' ) , true,
|
|
|
|
'Fullscreened area has the fullscreen class');
|
|
|
|
assert.strictEqual( lightbox.isFullscreen , true, 'Lightbox knows it\'s in fullscreen mode');
|
|
|
|
|
|
|
|
// Exiting fullscreen
|
|
|
|
lightbox.$fullscreenButton.click();
|
|
|
|
|
|
|
|
assert.strictEqual( lightbox.$main.hasClass( 'jq-fullscreened' ) , false,
|
|
|
|
'Fullscreened area doesn\'t have the fullscreen class anymore');
|
|
|
|
assert.strictEqual( lightbox.isFullscreen , false, 'Lightbox knows it\'s not in fullscreen mode');
|
|
|
|
|
2014-02-03 11:23:31 +00:00
|
|
|
// Entering fullscreen
|
|
|
|
lightbox.$fullscreenButton.click();
|
|
|
|
|
|
|
|
// Hard-exiting fullscreen
|
|
|
|
lightbox.$closeButton.click();
|
|
|
|
|
|
|
|
// Re-attach after hard-exit
|
|
|
|
lightbox.attach( '#qunit-fixture' );
|
|
|
|
|
|
|
|
assert.strictEqual( lightbox.$main.hasClass( 'jq-fullscreened' ) , false,
|
|
|
|
'Fullscreened area doesn\'t have the fullscreen class anymore');
|
|
|
|
assert.strictEqual( lightbox.isFullscreen , false, 'Lightbox knows it\'s not in fullscreen mode');
|
|
|
|
|
|
|
|
// Unattach lightbox from document
|
|
|
|
lightbox.unattach();
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-27 16:47:23 +00:00
|
|
|
$.fn.enterFullscreen = oldFnEnterFullscreen;
|
|
|
|
$.fn.exitFullscreen = oldFnExitFullscreen;
|
2014-01-31 09:58:28 +00:00
|
|
|
$.support.fullscreen = oldSupportFullscreen;
|
2014-01-27 16:47:23 +00:00
|
|
|
} );
|
|
|
|
|
2013-12-05 00:30:08 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|