2014-03-31 16:08:02 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
( function ( mw, $ ) {
|
2014-11-24 22:09:03 +00:00
|
|
|
QUnit.module( 'mw.mmv.ui.reuse.utils', QUnit.newMwEnvironment() );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'Sanity test, object creation and UI construction', function ( assert ) {
|
2014-09-16 20:33:05 +00:00
|
|
|
var utils = new mw.mmv.ui.Utils();
|
2014-03-31 16:08:02 +00:00
|
|
|
|
|
|
|
assert.ok( utils, 'ReuseUtils object is created.' );
|
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'createPulldownMenu():', function ( assert ) {
|
2014-09-16 20:33:05 +00:00
|
|
|
var utils = new mw.mmv.ui.Utils(),
|
2016-12-14 13:09:10 +00:00
|
|
|
menuItems = [ 'original', 'small', 'medium', 'large' ],
|
|
|
|
def = 'large',
|
|
|
|
menu = utils.createPulldownMenu(
|
2014-03-31 16:08:02 +00:00
|
|
|
menuItems,
|
2014-07-01 00:38:44 +00:00
|
|
|
[ 'mw-mmv-download-size' ],
|
2014-03-31 16:08:02 +00:00
|
|
|
def
|
|
|
|
),
|
2016-12-14 13:09:10 +00:00
|
|
|
options = menu.getMenu().getItems(),
|
|
|
|
i, data;
|
2014-03-31 16:08:02 +00:00
|
|
|
|
|
|
|
assert.strictEqual( options.length, 4, 'Menu has correct number of items.' );
|
|
|
|
|
|
|
|
for ( i = 0; i < menuItems.length; i++ ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
data = options[ i ].getData();
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2016-07-18 13:49:27 +00:00
|
|
|
assert.strictEqual( data.name, menuItems[ i ], 'Correct item name on the list.' );
|
2014-03-31 16:08:02 +00:00
|
|
|
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.' );
|
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'updateMenuOptions():', function ( assert ) {
|
2014-09-16 20:33:05 +00:00
|
|
|
var utils = new mw.mmv.ui.Utils(),
|
2016-12-14 13:09:10 +00:00
|
|
|
menu = utils.createPulldownMenu(
|
2014-03-31 16:08:02 +00:00
|
|
|
[ 'original', 'small', 'medium', 'large' ],
|
2014-07-01 00:38:44 +00:00
|
|
|
[ 'mw-mmv-download-size' ],
|
2014-03-31 16:08:02 +00:00
|
|
|
'original'
|
|
|
|
),
|
2016-12-14 13:09:10 +00:00
|
|
|
options = menu.getMenu().getItems(),
|
|
|
|
width = 700,
|
|
|
|
height = 500,
|
|
|
|
sizes = utils.getPossibleImageSizesForHtml( width, height ),
|
|
|
|
oldMessage = mw.message;
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
mw.message = function ( messageKey ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
assert.ok( messageKey.match( /^multimediaviewer-(small|medium|original|embed-dimensions)/ ), 'messageKey passed correctly.' );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
|
|
|
return { text: $.noop };
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.updateMenuOptions( sizes, options );
|
|
|
|
|
|
|
|
mw.message = oldMessage;
|
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'getPossibleImageSizesForHtml()', function ( assert ) {
|
2014-09-16 20:33:05 +00:00
|
|
|
var utils = new mw.mmv.ui.Utils(),
|
2016-12-14 13:09:10 +00:00
|
|
|
exampleSizes = [
|
2014-03-31 16:08:02 +00:00
|
|
|
// Big wide image
|
2016-12-14 13:09:10 +00:00
|
|
|
{
|
|
|
|
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 }
|
|
|
|
}
|
|
|
|
},
|
2014-03-31 16:08:02 +00:00
|
|
|
|
|
|
|
// Big tall image
|
2016-12-14 13:09:10 +00:00
|
|
|
{
|
|
|
|
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 }
|
|
|
|
}
|
|
|
|
},
|
2014-03-31 16:08:02 +00:00
|
|
|
|
|
|
|
// Very small image
|
2016-12-14 13:09:10 +00:00
|
|
|
{
|
|
|
|
width: 15, height: 20,
|
|
|
|
expected: {
|
|
|
|
original: { width: 15, height: 20 }
|
|
|
|
}
|
2014-03-31 16:08:02 +00:00
|
|
|
}
|
2016-12-14 13:09:10 +00:00
|
|
|
],
|
|
|
|
i, cursize, opts;
|
2014-03-31 16:08:02 +00:00
|
|
|
for ( i = 0; i < exampleSizes.length; i++ ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
cursize = exampleSizes[ i ];
|
2014-03-31 16:08:02 +00:00
|
|
|
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 ) );
|