mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-29 18:34:25 +00:00
961d47432b
* Following design, use split button to display a pulldown menu with possible image sizes. The download happens by sending the special "download" parameter to the server. * Offer link to preview image in the browser. Change-Id: Ic9d895fead04c9128186c7376a0bb09f3596335c Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/79
118 lines
3.6 KiB
JavaScript
118 lines
3.6 KiB
JavaScript
/*
|
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
|
*
|
|
* MultimediaViewer 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.
|
|
*
|
|
* MultimediaViewer 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 MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
( function ( mw, $ ) {
|
|
QUnit.module( 'mw.mmv.ui.reuse.Utils', QUnit.newMwEnvironment() );
|
|
|
|
QUnit.test( 'Sanity test, object creation and UI construction', 1, function ( assert ) {
|
|
var utils = new mw.mmv.ui.reuse.Utils();
|
|
|
|
assert.ok( utils, 'ReuseUtils object is created.' );
|
|
} );
|
|
|
|
QUnit.test( 'createPulldownMenu():', 14, function ( assert ) {
|
|
var utils = new mw.mmv.ui.reuse.Utils(),
|
|
menuItems = [ 'original', 'small', 'medium', 'large' ],
|
|
def = 'large',
|
|
menu = utils.createPulldownMenu(
|
|
menuItems,
|
|
[ 'mw-mlb-download-size' ],
|
|
def
|
|
),
|
|
options = menu.getMenu().getItems(),
|
|
i, data;
|
|
|
|
assert.strictEqual( options.length, 4, 'Menu has correct number of items.' );
|
|
|
|
for ( i = 0; i < menuItems.length; i++ ) {
|
|
data = options[i].getData();
|
|
|
|
assert.strictEqual( data.name, menuItems[i], 'Correct item name on the list.' );
|
|
assert.strictEqual( data.height, null, 'Correct item height on the list.' );
|
|
assert.strictEqual( data.width, null, 'Correct item width on the list.' );
|
|
}
|
|
|
|
assert.strictEqual( menu.getMenu().getSelectedItem(), options[ 3 ], 'Default set correctly.' );
|
|
} );
|
|
|
|
QUnit.test( 'updateMenuOptions():', 9, function ( assert ) {
|
|
var utils = new mw.mmv.ui.reuse.Utils(),
|
|
menu = utils.createPulldownMenu(
|
|
[ 'original', 'small', 'medium', 'large' ],
|
|
[ 'mw-mlb-download-size' ],
|
|
'original'
|
|
),
|
|
options = menu.getMenu().getItems(),
|
|
width = 700,
|
|
height = 500,
|
|
sizes = utils.getPossibleImageSizesForHtml( width, height ),
|
|
oldMessage = mw.message;
|
|
|
|
mw.message = function( messageKey ) {
|
|
assert.ok( messageKey.match(/^multimediaviewer-(small|medium|original|embed-dimensions)/), 'messageKey passed correctly.' );
|
|
|
|
return { text: $.noop };
|
|
};
|
|
|
|
utils.updateMenuOptions( sizes, options );
|
|
|
|
mw.message = oldMessage;
|
|
} );
|
|
|
|
QUnit.test( 'getPossibleImageSizesForHtml()', 3, function ( assert ) {
|
|
var utils = new mw.mmv.ui.reuse.Utils(),
|
|
exampleSizes = [
|
|
// Big wide image
|
|
{
|
|
width: 2048, height: 1536,
|
|
expected: {
|
|
small: { width: 193, height: 145 },
|
|
medium: { width: 640, height: 480 },
|
|
large: { width: 1200, height: 900 },
|
|
original: { width: 2048, height: 1536 }
|
|
}
|
|
},
|
|
|
|
// Big tall image
|
|
{
|
|
width: 201, height: 1536,
|
|
expected: {
|
|
small: { width: 19, height: 145 },
|
|
medium: { width: 63, height: 480 },
|
|
large: { width: 118, height: 900 },
|
|
original: { width: 201, height: 1536 }
|
|
}
|
|
},
|
|
|
|
// Very small image
|
|
{
|
|
width: 15, height: 20,
|
|
expected: {
|
|
original: { width: 15, height: 20 }
|
|
}
|
|
}
|
|
],
|
|
i, cursize, opts;
|
|
for ( i = 0; i < exampleSizes.length; i++ ) {
|
|
cursize = exampleSizes[i];
|
|
opts = utils.getPossibleImageSizesForHtml( cursize.width, cursize.height );
|
|
assert.deepEqual( opts, cursize.expected, 'We got the expected results out of the size calculation function.' );
|
|
}
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|