2014-01-31 02:03:08 +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 { ThumbnailInfo } = require( 'mmv' );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2014-01-31 02:03:08 +00:00
|
|
|
QUnit.module( 'mmv.provider.ThumbnailInfo', QUnit.newMwEnvironment() );
|
|
|
|
|
2021-12-10 00:43:28 +00:00
|
|
|
QUnit.test( 'ThumbnailInfo constructor sense check', function ( assert ) {
|
2015-01-23 12:48:27 +00:00
|
|
|
var api = { get: function () {} },
|
2023-05-20 08:30:52 +00:00
|
|
|
thumbnailInfoProvider = new ThumbnailInfo( api );
|
2014-01-31 02:03:08 +00:00
|
|
|
|
2023-05-20 08:30:52 +00:00
|
|
|
assert.true( thumbnailInfoProvider instanceof ThumbnailInfo );
|
2014-01-31 02:03:08 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-26 00:01:07 +00:00
|
|
|
QUnit.test( 'ThumbnailInfo get test', function ( assert ) {
|
2014-01-31 02:03:08 +00:00
|
|
|
var apiCallCount = 0,
|
2015-01-23 12:48:27 +00:00
|
|
|
api = { get: function () {
|
2014-01-31 02:03:08 +00:00
|
|
|
apiCallCount++;
|
|
|
|
return $.Deferred().resolve( {
|
|
|
|
query: {
|
2023-04-19 20:07:12 +00:00
|
|
|
pages: [
|
|
|
|
{
|
2014-01-31 02:03:08 +00:00
|
|
|
ns: 6,
|
|
|
|
title: 'File:Stuff.jpg',
|
2023-04-19 20:07:12 +00:00
|
|
|
missing: true,
|
2014-01-31 02:03:08 +00:00
|
|
|
imagerepository: 'shared',
|
|
|
|
imageinfo: [
|
|
|
|
{
|
|
|
|
thumburl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Stuff.jpg/51px-Stuff.jpg',
|
2014-02-03 20:42:17 +00:00
|
|
|
thumbwidth: 95,
|
2014-01-31 02:03:08 +00:00
|
|
|
thumbheight: 200,
|
|
|
|
url: 'https://upload.wikimedia.org/wikipedia/commons/1/19/Stuff.jpg',
|
|
|
|
descriptionurl: 'https://commons.wikimedia.org/wiki/File:Stuff.jpg'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-04-19 20:07:12 +00:00
|
|
|
]
|
2014-01-31 02:03:08 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} },
|
|
|
|
file = new mw.Title( 'File:Stuff.jpg' ),
|
2023-05-20 08:30:52 +00:00
|
|
|
thumbnailInfoProvider = new ThumbnailInfo( api );
|
2014-01-31 02:03:08 +00:00
|
|
|
|
2017-07-26 00:01:07 +00:00
|
|
|
return thumbnailInfoProvider.get( file, 100 ).then( function ( thumbnail ) {
|
2014-02-05 01:06:10 +00:00
|
|
|
assert.strictEqual( thumbnail.url,
|
2014-01-31 02:03:08 +00:00
|
|
|
'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Stuff.jpg/51px-Stuff.jpg',
|
|
|
|
'URL is set correctly' );
|
2014-02-05 01:06:10 +00:00
|
|
|
assert.strictEqual( thumbnail.width, 95, 'actual width is set correctly' );
|
|
|
|
assert.strictEqual( thumbnail.height, 200, 'actual height is set correctly' );
|
2015-01-23 12:48:27 +00:00
|
|
|
} ).then( function () {
|
2014-01-31 02:03:08 +00:00
|
|
|
assert.strictEqual( apiCallCount, 1 );
|
|
|
|
// call the data provider a second time to check caching
|
|
|
|
return thumbnailInfoProvider.get( file, 100 );
|
2015-01-23 12:48:27 +00:00
|
|
|
} ).then( function () {
|
2014-01-31 02:03:08 +00:00
|
|
|
assert.strictEqual( apiCallCount, 1 );
|
|
|
|
// call a third time with different size to check caching
|
|
|
|
return thumbnailInfoProvider.get( file, 110 );
|
2015-01-23 12:48:27 +00:00
|
|
|
} ).then( function () {
|
2014-01-31 02:03:08 +00:00
|
|
|
assert.strictEqual( apiCallCount, 2 );
|
2014-02-05 01:06:10 +00:00
|
|
|
// call it again, with a height specified, to check caching
|
|
|
|
return thumbnailInfoProvider.get( file, 110, 100 );
|
2015-01-23 12:48:27 +00:00
|
|
|
} ).then( function () {
|
2014-02-05 01:06:10 +00:00
|
|
|
assert.strictEqual( apiCallCount, 3 );
|
2014-01-31 02:03:08 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2017-07-26 00:01:07 +00:00
|
|
|
QUnit.test( 'ThumbnailInfo fail test', function ( assert ) {
|
2015-01-23 12:48:27 +00:00
|
|
|
var api = { get: function () {
|
2014-01-31 02:03:08 +00:00
|
|
|
return $.Deferred().resolve( {} );
|
|
|
|
} },
|
|
|
|
file = new mw.Title( 'File:Stuff.jpg' ),
|
2017-07-26 00:01:07 +00:00
|
|
|
done = assert.async(),
|
2023-05-20 08:30:52 +00:00
|
|
|
thumbnailInfoProvider = new ThumbnailInfo( api );
|
2014-01-31 02:03:08 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
thumbnailInfoProvider.get( file, 100 ).fail( function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'promise rejected when no data is returned' );
|
2017-07-26 00:01:07 +00:00
|
|
|
done();
|
2014-01-31 02:03:08 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2017-07-26 00:01:07 +00:00
|
|
|
QUnit.test( 'ThumbnailInfo fail test 2', function ( assert ) {
|
2015-01-23 12:48:27 +00:00
|
|
|
var api = { get: function () {
|
2014-01-31 02:03:08 +00:00
|
|
|
return $.Deferred().resolve( {
|
|
|
|
query: {
|
2023-04-19 20:07:12 +00:00
|
|
|
pages: [
|
|
|
|
{
|
2014-01-31 02:03:08 +00:00
|
|
|
title: 'File:Stuff.jpg'
|
|
|
|
}
|
2023-04-19 20:07:12 +00:00
|
|
|
]
|
2014-01-31 02:03:08 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} },
|
|
|
|
file = new mw.Title( 'File:Stuff.jpg' ),
|
2017-07-26 00:01:07 +00:00
|
|
|
done = assert.async(),
|
2023-05-20 08:30:52 +00:00
|
|
|
thumbnailInfoProvider = new ThumbnailInfo( api );
|
2014-01-31 02:03:08 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
thumbnailInfoProvider.get( file, 100 ).fail( function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'promise rejected when imageinfo is missing' );
|
2017-07-26 00:01:07 +00:00
|
|
|
done();
|
2014-01-31 02:03:08 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2017-07-26 00:01:07 +00:00
|
|
|
QUnit.test( 'ThumbnailInfo missing page test', function ( assert ) {
|
2015-01-23 12:48:27 +00:00
|
|
|
var api = { get: function () {
|
2014-01-31 02:03:08 +00:00
|
|
|
return $.Deferred().resolve( {
|
|
|
|
query: {
|
2023-04-19 20:07:12 +00:00
|
|
|
pages: [
|
|
|
|
{
|
2014-01-31 02:03:08 +00:00
|
|
|
title: 'File:Stuff.jpg',
|
2023-04-19 20:07:12 +00:00
|
|
|
missing: true,
|
2014-01-31 02:03:08 +00:00
|
|
|
imagerepository: ''
|
|
|
|
}
|
2023-04-19 20:07:12 +00:00
|
|
|
]
|
2014-01-31 02:03:08 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} },
|
|
|
|
file = new mw.Title( 'File:Stuff.jpg' ),
|
2017-07-26 00:01:07 +00:00
|
|
|
done = assert.async(),
|
2023-05-20 08:30:52 +00:00
|
|
|
thumbnailInfoProvider = new ThumbnailInfo( api );
|
2014-01-31 02:03:08 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
thumbnailInfoProvider.get( file ).fail( function ( errorMessage ) {
|
|
|
|
assert.strictEqual( errorMessage, 'file does not exist: File:Stuff.jpg',
|
|
|
|
'error message is set correctly for missing file' );
|
2017-07-26 00:01:07 +00:00
|
|
|
done();
|
2014-01-31 02:03:08 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-02-05 01:06:10 +00:00
|
|
|
|
2017-07-26 00:01:07 +00:00
|
|
|
QUnit.test( 'ThumbnailInfo fail test 3', function ( assert ) {
|
2015-01-23 12:48:27 +00:00
|
|
|
var api = { get: function () {
|
2014-02-05 01:06:10 +00:00
|
|
|
return $.Deferred().resolve( {
|
|
|
|
query: {
|
2023-04-19 20:07:12 +00:00
|
|
|
pages: [
|
|
|
|
{
|
2014-02-05 01:06:10 +00:00
|
|
|
title: 'File:Stuff.jpg',
|
|
|
|
imageinfo: [
|
|
|
|
{}
|
|
|
|
]
|
|
|
|
}
|
2023-04-19 20:07:12 +00:00
|
|
|
]
|
2014-02-05 01:06:10 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} },
|
|
|
|
file = new mw.Title( 'File:Stuff.jpg' ),
|
2017-07-26 00:01:07 +00:00
|
|
|
done = assert.async(),
|
2023-05-20 08:30:52 +00:00
|
|
|
thumbnailInfoProvider = new ThumbnailInfo( api );
|
2014-02-05 01:06:10 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
thumbnailInfoProvider.get( file, 100 ).fail( function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'promise rejected when thumbnail info is missing' );
|
2017-07-26 00:01:07 +00:00
|
|
|
done();
|
2014-02-05 01:06:10 +00:00
|
|
|
} );
|
|
|
|
} );
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|