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/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-20 08:30:52 +00:00
|
|
|
const { Utils } = require( 'mmv.ui.ondemandshareddependencies' );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2023-05-20 08:30:52 +00:00
|
|
|
QUnit.module( 'mmv.ui.reuse.utils', QUnit.newMwEnvironment() );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2021-12-10 00:43:28 +00:00
|
|
|
QUnit.test( 'Sense test, object creation and UI construction', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const utils = new Utils();
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2023-05-20 08:30:52 +00:00
|
|
|
assert.true( utils instanceof Utils, 'ReuseUtils object is created.' );
|
2014-03-31 16:08:02 +00:00
|
|
|
} );
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
QUnit.test( 'createSelectMenu():', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const utils = new Utils();
|
|
|
|
const menuItems = [ 'original', 'small', 'medium', 'large' ];
|
|
|
|
const def = 'large';
|
2024-05-04 14:00:17 +00:00
|
|
|
const $select = utils.createSelectMenu(
|
2023-10-24 09:53:23 +00:00
|
|
|
menuItems,
|
|
|
|
def
|
|
|
|
);
|
2024-05-04 14:00:17 +00:00
|
|
|
const $options = $select.children();
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
assert.strictEqual( $options.length, 4, 'Menu has correct number of items.' );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2023-10-24 09:53:23 +00:00
|
|
|
for ( let i = 0; i < menuItems.length; i++ ) {
|
2024-05-04 14:00:17 +00:00
|
|
|
const $option = $( $options[ i ] );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
assert.strictEqual( $option.attr( 'data-name' ), menuItems[ i ], 'Correct item name on the list.' );
|
|
|
|
assert.strictEqual( $option.attr( 'data-height' ), undefined, 'Correct item height on the list.' );
|
|
|
|
assert.strictEqual( $option.attr( 'data-width' ), undefined, 'Correct item width on the list.' );
|
2014-03-31 16:08:02 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
QUnit.test( 'updateSelectOptions():', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const utils = new Utils();
|
2024-05-04 14:00:17 +00:00
|
|
|
const $select = utils.createSelectMenu(
|
2023-10-24 09:53:23 +00:00
|
|
|
[ 'original', 'small', 'medium', 'large' ],
|
|
|
|
'original'
|
|
|
|
);
|
2024-05-04 14:00:17 +00:00
|
|
|
const $options = $select.children();
|
2023-10-24 09:53:23 +00:00
|
|
|
const width = 700;
|
|
|
|
const height = 500;
|
|
|
|
const sizes = utils.getPossibleImageSizesForHtml( width, height );
|
|
|
|
const oldMessage = mw.message;
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
mw.message = function ( messageKey ) {
|
2024-05-04 14:00:17 +00:00
|
|
|
assert.true( /^multimediaviewer-(small|medium|large|original|embed-dimensions)/.test( messageKey ), 'messageKey passed correctly.' );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
2019-02-05 23:59:52 +00:00
|
|
|
return { text: function () {} };
|
2014-03-31 16:08:02 +00:00
|
|
|
};
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
utils.updateSelectOptions( sizes, $options );
|
2014-03-31 16:08:02 +00:00
|
|
|
|
|
|
|
mw.message = oldMessage;
|
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'getPossibleImageSizesForHtml()', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const utils = new Utils();
|
|
|
|
const exampleSizes = [
|
|
|
|
{
|
|
|
|
test: 'Extra large wide image',
|
|
|
|
width: 6000, height: 4000,
|
|
|
|
expected: {
|
|
|
|
small: { width: 640, height: 427 },
|
|
|
|
medium: { width: 1080, height: 720 },
|
|
|
|
large: { width: 1620, height: 1080 },
|
|
|
|
xl: { width: 3240, height: 2160 },
|
|
|
|
original: { width: 6000, height: 4000 }
|
2014-03-31 16:08:02 +00:00
|
|
|
}
|
2023-10-24 09:53:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: 'Big wide image',
|
|
|
|
width: 2048, height: 1536,
|
|
|
|
expected: {
|
|
|
|
small: { width: 640, height: 480 },
|
|
|
|
medium: { width: 960, height: 720 },
|
|
|
|
large: { width: 1440, height: 1080 },
|
|
|
|
original: { width: 2048, height: 1536 }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: 'Big tall image',
|
|
|
|
width: 201, height: 1536,
|
|
|
|
expected: {
|
|
|
|
small: { width: 63, height: 480 },
|
|
|
|
medium: { width: 94, height: 720 },
|
|
|
|
large: { width: 141, height: 1080 },
|
|
|
|
original: { width: 201, height: 1536 }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: 'Very small image',
|
|
|
|
width: 15, height: 20,
|
|
|
|
expected: {
|
|
|
|
original: { width: 15, height: 20 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
for ( let i = 0; i < exampleSizes.length; i++ ) {
|
|
|
|
const cursize = exampleSizes[ i ];
|
|
|
|
const opts = utils.getPossibleImageSizesForHtml( cursize.width, cursize.height );
|
2019-05-18 17:23:46 +00:00
|
|
|
assert.deepEqual( opts, cursize.expected, 'Size calculation for "' + cursize.test + '" gives expected results' );
|
2014-03-31 16:08:02 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|