Improve variable declarations in JavaScript
Use the eslint rule "no-var": "error" in resources/.eslintrc.json and in .eslintrc.json to require the use of `const` and `let` instead of `var`. Bug: T337102 Change-Id: I3b3d6d426966a97c13f62494443f62bd5b790920
这个提交包含在:
父节点
db68366fe6
当前提交
3481080251
|
@ -2,5 +2,8 @@
|
|||
"root": true,
|
||||
"extends": [
|
||||
"wikimedia/server"
|
||||
]
|
||||
],
|
||||
"rules": {
|
||||
"no-var": "error"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"wikimedia/mediawiki"
|
||||
],
|
||||
"rules": {
|
||||
"no-var": "off",
|
||||
"no-var": "error",
|
||||
"max-len": "off",
|
||||
"no-jquery/no-class-state": "off",
|
||||
"no-jquery/no-support": "off"
|
||||
|
|
|
@ -306,7 +306,7 @@ const UiElement = require( './ui/mmv.ui.js' );
|
|||
* Enters fullscreen mode.
|
||||
*/
|
||||
enterFullscreen() {
|
||||
var el = this.$main.get( 0 );
|
||||
const el = this.$main.get( 0 );
|
||||
if ( el.requestFullscreen ) {
|
||||
el.requestFullscreen();
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ const { ViewLogger } = require( 'mmv' );
|
|||
} ) );
|
||||
|
||||
QUnit.test( 'focus and blur', function ( assert ) {
|
||||
var $fakeWindow = $( '<div>' ),
|
||||
viewLogger = new ViewLogger( { recordVirtualViewBeaconURI: function () {} }, $fakeWindow, { log: function () {} } );
|
||||
const $fakeWindow = $( '<div>' );
|
||||
const viewLogger = new ViewLogger( { recordVirtualViewBeaconURI: function () {} }, $fakeWindow, { log: function () {} } );
|
||||
|
||||
this.clock.tick( 1 ); // This is just so that the timer ticks up in the fake timer environment
|
||||
|
||||
|
@ -45,7 +45,7 @@ const { ViewLogger } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'stopViewDuration before startViewDuration', function ( assert ) {
|
||||
var viewLogger = new ViewLogger( { recordVirtualViewBeaconURI: function () {} }, {}, { log: function () {} } );
|
||||
const viewLogger = new ViewLogger( { recordVirtualViewBeaconURI: function () {} }, {}, { log: function () {} } );
|
||||
|
||||
this.clock.tick( 1 ); // This is just so that the timer ticks up in the fake timer environment
|
||||
|
||||
|
|
|
@ -22,12 +22,12 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
QUnit.module( 'mmv.Config', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Constructor sense test', function ( assert ) {
|
||||
var config = new Config( {}, {}, {}, {}, null );
|
||||
const config = new Config( {}, {}, {}, {}, null );
|
||||
assert.true( config instanceof Config );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Localstorage get', function ( assert ) {
|
||||
var localStorage, config;
|
||||
let localStorage, config;
|
||||
|
||||
localStorage = getUnsupportedLocalStorage(); // no browser support
|
||||
config = new Config( {}, {}, {}, {}, localStorage );
|
||||
|
@ -53,7 +53,7 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
} );
|
||||
|
||||
QUnit.test( 'Localstorage set', function ( assert ) {
|
||||
var localStorage, config;
|
||||
let localStorage, config;
|
||||
|
||||
localStorage = getUnsupportedLocalStorage(); // no browser support
|
||||
config = new Config( {}, {}, {}, {}, localStorage );
|
||||
|
@ -73,7 +73,7 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
} );
|
||||
|
||||
QUnit.test( 'Localstorage remove', function ( assert ) {
|
||||
var localStorage, config;
|
||||
let localStorage, config;
|
||||
|
||||
localStorage = getUnsupportedLocalStorage(); // no browser support
|
||||
config = new Config( {}, {}, {}, {}, localStorage );
|
||||
|
@ -89,10 +89,10 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
} );
|
||||
|
||||
QUnit.test( 'isMediaViewerEnabledOnClick', function ( assert ) {
|
||||
var localStorage = createLocalStorage( { getItem: this.sandbox.stub() } ),
|
||||
mwConfig = { get: this.sandbox.stub() },
|
||||
mwUser = { isNamed: this.sandbox.stub() },
|
||||
config = new Config( {}, mwConfig, mwUser, {}, localStorage );
|
||||
const localStorage = createLocalStorage( { getItem: this.sandbox.stub() } );
|
||||
const mwConfig = { get: this.sandbox.stub() };
|
||||
const mwUser = { isNamed: this.sandbox.stub() };
|
||||
const config = new Config( {}, mwConfig, mwUser, {}, localStorage );
|
||||
|
||||
mwUser.isNamed.returns( true );
|
||||
mwConfig.get.withArgs( 'wgMediaViewer' ).returns( true );
|
||||
|
@ -133,15 +133,15 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
} );
|
||||
|
||||
QUnit.test( 'setMediaViewerEnabledOnClick sense check', function ( assert ) {
|
||||
var localStorage = createLocalStorage( {
|
||||
getItem: this.sandbox.stub(),
|
||||
setItem: this.sandbox.stub(),
|
||||
removeItem: this.sandbox.stub()
|
||||
} ),
|
||||
mwUser = { isNamed: this.sandbox.stub() },
|
||||
mwConfig = new mw.Map(),
|
||||
api = { saveOption: this.sandbox.stub().returns( $.Deferred().resolve() ) },
|
||||
config = new Config( {}, mwConfig, mwUser, api, localStorage );
|
||||
const localStorage = createLocalStorage( {
|
||||
getItem: this.sandbox.stub(),
|
||||
setItem: this.sandbox.stub(),
|
||||
removeItem: this.sandbox.stub()
|
||||
} );
|
||||
const mwUser = { isNamed: this.sandbox.stub() };
|
||||
const mwConfig = new mw.Map();
|
||||
const api = { saveOption: this.sandbox.stub().returns( $.Deferred().resolve() ) };
|
||||
const config = new Config( {}, mwConfig, mwUser, api, localStorage );
|
||||
mwConfig.set( 'wgMediaViewerEnabledByDefault', false );
|
||||
|
||||
mwUser.isNamed.returns( true );
|
||||
|
@ -159,18 +159,17 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
} );
|
||||
|
||||
QUnit.test( 'shouldShowStatusInfo', function ( assert ) {
|
||||
var config,
|
||||
mwConfig = new mw.Map(),
|
||||
fakeLocalStorage = getFakeLocalStorage(),
|
||||
mwUser = { isNamed: this.sandbox.stub() },
|
||||
api = { saveOption: this.sandbox.stub().returns( $.Deferred().resolve() ) };
|
||||
const mwConfig = new mw.Map();
|
||||
const fakeLocalStorage = getFakeLocalStorage();
|
||||
const mwUser = { isNamed: this.sandbox.stub() };
|
||||
const api = { saveOption: this.sandbox.stub().returns( $.Deferred().resolve() ) };
|
||||
|
||||
mwConfig.set( {
|
||||
wgMediaViewer: true,
|
||||
wgMediaViewerOnClick: true,
|
||||
wgMediaViewerEnabledByDefault: true
|
||||
} );
|
||||
config = new Config( {}, mwConfig, mwUser, api, fakeLocalStorage );
|
||||
const config = new Config( {}, mwConfig, mwUser, api, fakeLocalStorage );
|
||||
mwUser.isNamed.returns( true );
|
||||
|
||||
assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown by default' );
|
||||
|
|
|
@ -5,31 +5,38 @@ const { EmbedFileFormatter } = require( 'mmv.ui.ondemandshareddependencies' );
|
|||
QUnit.module( 'mmv.EmbedFileFormatter', QUnit.newMwEnvironment() );
|
||||
|
||||
function createEmbedFileInfo( options ) {
|
||||
var license = options.licenseShortName ? new License( options.licenseShortName,
|
||||
options.licenseInternalName, options.licenseLongName, options.licenseUrl ) : undefined,
|
||||
imageInfo = new ImageModel(
|
||||
|
||||
options.title,
|
||||
options.title.getNameText(),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
options.imgUrl,
|
||||
options.filePageUrl,
|
||||
options.shortFilePageUrl,
|
||||
42,
|
||||
'repo',
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
options.source,
|
||||
options.author,
|
||||
options.authorCount,
|
||||
license ),
|
||||
repoInfo = { displayName: options.siteName, getSiteLink:
|
||||
function () { return options.siteUrl; } };
|
||||
const license = options.licenseShortName ?
|
||||
new License(
|
||||
options.licenseShortName,
|
||||
options.licenseInternalName,
|
||||
options.licenseLongName,
|
||||
options.licenseUrl
|
||||
) : undefined;
|
||||
const imageInfo = new ImageModel(
|
||||
options.title,
|
||||
options.title.getNameText(),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
options.imgUrl,
|
||||
options.filePageUrl,
|
||||
options.shortFilePageUrl,
|
||||
42,
|
||||
'repo',
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
options.source,
|
||||
options.author,
|
||||
options.authorCount,
|
||||
license
|
||||
);
|
||||
const repoInfo = {
|
||||
displayName: options.siteName,
|
||||
getSiteLink: function () { return options.siteUrl; }
|
||||
};
|
||||
|
||||
return {
|
||||
imageInfo: imageInfo,
|
||||
|
@ -39,19 +46,18 @@ const { EmbedFileFormatter } = require( 'mmv.ui.ondemandshareddependencies' );
|
|||
}
|
||||
|
||||
QUnit.test( 'EmbedFileFormatter constructor sense check', function ( assert ) {
|
||||
var formatter = new EmbedFileFormatter();
|
||||
const formatter = new EmbedFileFormatter();
|
||||
assert.true( formatter instanceof EmbedFileFormatter, 'constructor with no argument works' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'getByline():', function ( assert ) {
|
||||
var formatter = new EmbedFileFormatter(),
|
||||
author = '<span class="mw-mmv-author">Homer</span>',
|
||||
source = '<span class="mw-mmv-source">Iliad</span>',
|
||||
attribution = '<span class="mw-mmv-attr">Cat</span>',
|
||||
byline;
|
||||
const formatter = new EmbedFileFormatter();
|
||||
const author = '<span class="mw-mmv-author">Homer</span>';
|
||||
const source = '<span class="mw-mmv-source">Iliad</span>';
|
||||
const attribution = '<span class="mw-mmv-attr">Cat</span>';
|
||||
|
||||
// Works with no arguments
|
||||
byline = formatter.getByline();
|
||||
let byline = formatter.getByline();
|
||||
assert.strictEqual( byline, undefined, 'No argument case handled correctly.' );
|
||||
|
||||
// Attribution present
|
||||
|
@ -72,44 +78,42 @@ const { EmbedFileFormatter } = require( 'mmv.ui.ondemandshareddependencies' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getSiteLink():', function ( assert ) {
|
||||
var repoInfo = new Repo( 'Wikipedia', '//wikipedia.org/favicon.ico', true ),
|
||||
info = { imageInfo: {}, repoInfo: repoInfo },
|
||||
formatter = new EmbedFileFormatter(),
|
||||
siteUrl = repoInfo.getSiteLink(),
|
||||
siteLink = formatter.getSiteLink( info );
|
||||
const repoInfo = new Repo( 'Wikipedia', '//wikipedia.org/favicon.ico', true );
|
||||
const info = { imageInfo: {}, repoInfo: repoInfo };
|
||||
const formatter = new EmbedFileFormatter();
|
||||
const siteUrl = repoInfo.getSiteLink();
|
||||
const siteLink = formatter.getSiteLink( info );
|
||||
|
||||
assert.notStrictEqual( siteLink.indexOf( 'Wikipedia' ), -1, 'Site name is present in site link' );
|
||||
assert.notStrictEqual( siteLink.indexOf( siteUrl ), -1, 'Site URL is present in site link' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'getThumbnailHtml():', function ( assert ) {
|
||||
var formatter = new EmbedFileFormatter(),
|
||||
titleText = 'Music Room',
|
||||
title = mw.Title.newFromText( titleText ),
|
||||
imgUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
filePageUrl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||
filePageShortUrl = 'https://commons.wikimedia.org/wiki/index.php?curid=42',
|
||||
siteName = 'Site Name',
|
||||
siteUrl = '//site.url/',
|
||||
licenseShortName = 'Public License',
|
||||
licenseInternalName = '-',
|
||||
licenseLongName = 'Public Domain, copyrights have lapsed',
|
||||
licenseUrl = '//example.com/pd',
|
||||
author = '<span class="mw-mmv-author">Homer</span>',
|
||||
source = '<span class="mw-mmv-source">Iliad</span>',
|
||||
thumbUrl = 'https://upload.wikimedia.org/wikipedia/thumb/Foobar.jpg',
|
||||
width = 700,
|
||||
height = 500,
|
||||
info,
|
||||
generatedHtml;
|
||||
const formatter = new EmbedFileFormatter();
|
||||
const titleText = 'Music Room';
|
||||
const title = mw.Title.newFromText( titleText );
|
||||
const imgUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const filePageUrl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
||||
const filePageShortUrl = 'https://commons.wikimedia.org/wiki/index.php?curid=42';
|
||||
const siteName = 'Site Name';
|
||||
const siteUrl = '//site.url/';
|
||||
const licenseShortName = 'Public License';
|
||||
const licenseInternalName = '-';
|
||||
const licenseLongName = 'Public Domain, copyrights have lapsed';
|
||||
const licenseUrl = '//example.com/pd';
|
||||
const author = '<span class="mw-mmv-author">Homer</span>';
|
||||
const source = '<span class="mw-mmv-source">Iliad</span>';
|
||||
const thumbUrl = 'https://upload.wikimedia.org/wikipedia/thumb/Foobar.jpg';
|
||||
const width = 700;
|
||||
const height = 500;
|
||||
|
||||
// Bylines, license and site
|
||||
info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl,
|
||||
let info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl,
|
||||
shortFilePageUrl: filePageShortUrl, siteName: siteName, siteUrl: siteUrl,
|
||||
licenseShortName: licenseShortName, licenseInternalName: licenseInternalName,
|
||||
licenseLongName: licenseLongName, licenseUrl: licenseUrl, author: author, source: source } );
|
||||
|
||||
generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height );
|
||||
let generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height );
|
||||
assert.notStrictEqual( generatedHtml.match( titleText ), null, 'Title appears in generated HTML.' );
|
||||
assert.notStrictEqual( generatedHtml.match( filePageUrl ), null, 'Page url appears in generated HTML.' );
|
||||
assert.notStrictEqual( generatedHtml.match( thumbUrl ), null, 'Thumbnail url appears in generated HTML' );
|
||||
|
@ -176,19 +180,17 @@ const { EmbedFileFormatter } = require( 'mmv.ui.ondemandshareddependencies' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getThumbnailWikitext():', function ( assert ) {
|
||||
var formatter = new EmbedFileFormatter(),
|
||||
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
||||
imgUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
filePageUrl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||
caption = 'Foobar caption.',
|
||||
width = 700,
|
||||
info,
|
||||
wikitext;
|
||||
const formatter = new EmbedFileFormatter();
|
||||
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
||||
const imgUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const filePageUrl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
||||
const caption = 'Foobar caption.';
|
||||
const width = 700;
|
||||
|
||||
// Title, width and caption
|
||||
info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl,
|
||||
let info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl,
|
||||
caption: caption } );
|
||||
wikitext = formatter.getThumbnailWikitextFromEmbedFileInfo( info, width );
|
||||
let wikitext = formatter.getThumbnailWikitextFromEmbedFileInfo( info, width );
|
||||
|
||||
assert.strictEqual(
|
||||
wikitext,
|
||||
|
@ -215,9 +217,9 @@ const { EmbedFileFormatter } = require( 'mmv.ui.ondemandshareddependencies' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getCreditText():', function ( assert ) {
|
||||
var txt, formatter = new EmbedFileFormatter();
|
||||
const formatter = new EmbedFileFormatter();
|
||||
|
||||
txt = formatter.getCreditText( {
|
||||
let txt = formatter.getCreditText( {
|
||||
repoInfo: {
|
||||
displayName: 'Localcommons'
|
||||
},
|
||||
|
@ -258,9 +260,9 @@ const { EmbedFileFormatter } = require( 'mmv.ui.ondemandshareddependencies' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getCreditHtml():', function ( assert ) {
|
||||
var html, formatter = new EmbedFileFormatter();
|
||||
const formatter = new EmbedFileFormatter();
|
||||
|
||||
html = formatter.getCreditHtml( {
|
||||
let html = formatter.getCreditHtml( {
|
||||
repoInfo: {
|
||||
displayName: 'Localcommons',
|
||||
getSiteLink: function () { return 'quux'; }
|
||||
|
|
|
@ -23,11 +23,11 @@ const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|||
QUnit.module( 'mmv.HtmlUtils', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'wrapAndJquerify() for single node', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
$el = $( '<span>' ),
|
||||
el = $( '<span>' ).get( 0 ),
|
||||
html = '<span></span>',
|
||||
invalid = {};
|
||||
const utils = new HtmlUtils();
|
||||
const $el = $( '<span>' );
|
||||
const el = $( '<span>' ).get( 0 );
|
||||
const html = '<span></span>';
|
||||
const invalid = {};
|
||||
|
||||
assert.strictEqual( utils.wrapAndJquerify( $el ).html(), '<span></span>', 'jQuery' );
|
||||
assert.strictEqual( utils.wrapAndJquerify( el ).html(), '<span></span>', 'HTMLElement' );
|
||||
|
@ -39,27 +39,27 @@ const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'wrapAndJquerify() for multiple nodes', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
$el = $( '<span></span><span></span>' ),
|
||||
html = '<span></span><span></span>';
|
||||
const utils = new HtmlUtils();
|
||||
const $el = $( '<span></span><span></span>' );
|
||||
const html = '<span></span><span></span>';
|
||||
|
||||
assert.strictEqual( utils.wrapAndJquerify( $el ).html(), '<span></span><span></span>', 'jQuery' );
|
||||
assert.strictEqual( utils.wrapAndJquerify( html ).html(), '<span></span><span></span>', 'HTML string' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'wrapAndJquerify() for text', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
$el = $( document.createTextNode( 'foo' ) ),
|
||||
html = 'foo';
|
||||
const utils = new HtmlUtils();
|
||||
const $el = $( document.createTextNode( 'foo' ) );
|
||||
const html = 'foo';
|
||||
|
||||
assert.strictEqual( utils.wrapAndJquerify( $el ).html(), 'foo', 'jQuery' );
|
||||
assert.strictEqual( utils.wrapAndJquerify( html ).html(), 'foo', 'HTML string' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'wrapAndJquerify() does not change original', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
$el = $( '<span>' ),
|
||||
el = $( '<span>' ).get( 0 );
|
||||
const utils = new HtmlUtils();
|
||||
const $el = $( '<span>' );
|
||||
const el = $( '<span>' ).get( 0 );
|
||||
|
||||
utils.wrapAndJquerify( $el ).find( 'span' ).prop( 'data-x', 1 );
|
||||
utils.wrapAndJquerify( el ).find( 'span' ).prop( 'data-x', 1 );
|
||||
|
@ -68,13 +68,13 @@ const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'filterInvisible()', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
$visibleChild = $( '<div><span></span></div>' ),
|
||||
$invisibleChild = $( '<div><span style="display: none"></span></div>' ),
|
||||
$styleChild = $( '<div><style></style></div>' ),
|
||||
$invisibleChildInVisibleChild = $( '<div><span><abbr style="display: none"></abbr></span></div>' ),
|
||||
$visibleChildInInvisibleChild = $( '<div><span style="display: none"><abbr></abbr></span></div>' ),
|
||||
$invisibleChildWithVisibleSiblings = $( '<div><span></span><abbr style="display: none"></abbr><b></b></div>' );
|
||||
const utils = new HtmlUtils();
|
||||
const $visibleChild = $( '<div><span></span></div>' );
|
||||
const $invisibleChild = $( '<div><span style="display: none"></span></div>' );
|
||||
const $styleChild = $( '<div><style></style></div>' );
|
||||
const $invisibleChildInVisibleChild = $( '<div><span><abbr style="display: none"></abbr></span></div>' );
|
||||
const $visibleChildInInvisibleChild = $( '<div><span style="display: none"><abbr></abbr></span></div>' );
|
||||
const $invisibleChildWithVisibleSiblings = $( '<div><span></span><abbr style="display: none"></abbr><b></b></div>' );
|
||||
|
||||
utils.filterInvisible( $visibleChild );
|
||||
utils.filterInvisible( $invisibleChild );
|
||||
|
@ -97,12 +97,12 @@ const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'whitelistHtml()', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
$whitelisted = $( '<div>abc<a>def</a>ghi</div>' ),
|
||||
$nonWhitelisted = $( '<div>abc<span>def</span>ghi</div>' ),
|
||||
$nonWhitelistedInWhitelisted = $( '<div>abc<a>d<span>e</span>f</a>ghi</div>' ),
|
||||
$whitelistedInNonWhitelisted = $( '<div>abc<span>d<a>e</a>f</span>ghi</div>' ),
|
||||
$siblings = $( '<div>ab<span>c</span>d<a>e</a>f<span>g</span>hi</div>' );
|
||||
const utils = new HtmlUtils();
|
||||
const $whitelisted = $( '<div>abc<a>def</a>ghi</div>' );
|
||||
const $nonWhitelisted = $( '<div>abc<span>def</span>ghi</div>' );
|
||||
const $nonWhitelistedInWhitelisted = $( '<div>abc<a>d<span>e</span>f</a>ghi</div>' );
|
||||
const $whitelistedInNonWhitelisted = $( '<div>abc<span>d<a>e</a>f</span>ghi</div>' );
|
||||
const $siblings = $( '<div>ab<span>c</span>d<a>e</a>f<span>g</span>hi</div>' );
|
||||
|
||||
utils.whitelistHtml( $whitelisted, 'a' );
|
||||
utils.whitelistHtml( $nonWhitelisted, 'a' );
|
||||
|
@ -121,10 +121,10 @@ const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'appendWhitespaceToBlockElements()', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
$noBlockElement = $( '<div>abc<i>def</i>ghi</div>' ),
|
||||
$blockElement = $( '<div>abc<p>def</p>ghi</div>' ),
|
||||
$linebreak = $( '<div>abc<br>def</div>' );
|
||||
const utils = new HtmlUtils();
|
||||
const $noBlockElement = $( '<div>abc<i>def</i>ghi</div>' );
|
||||
const $blockElement = $( '<div>abc<p>def</p>ghi</div>' );
|
||||
const $linebreak = $( '<div>abc<br>def</div>' );
|
||||
|
||||
utils.appendWhitespaceToBlockElements( $noBlockElement );
|
||||
utils.appendWhitespaceToBlockElements( $blockElement );
|
||||
|
@ -136,7 +136,7 @@ const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'jqueryToHtml()', function ( assert ) {
|
||||
var utils = new HtmlUtils();
|
||||
const utils = new HtmlUtils();
|
||||
|
||||
assert.strictEqual( utils.jqueryToHtml( $( '<a>' ) ), '<a></a>',
|
||||
'works for single element' );
|
||||
|
@ -147,7 +147,7 @@ const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'mergeWhitespace()', function ( assert ) {
|
||||
var utils = new HtmlUtils();
|
||||
const utils = new HtmlUtils();
|
||||
|
||||
assert.strictEqual( utils.mergeWhitespace( ' x \n' ), 'x',
|
||||
'leading/trainling whitespace is trimmed' );
|
||||
|
@ -158,28 +158,28 @@ const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'htmlToText()', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
html = '<table><tr><td>Foo</td><td><a>bar</a></td><td style="display: none">baz</td></tr></table>';
|
||||
const utils = new HtmlUtils();
|
||||
const html = '<table><tr><td>Foo</td><td><a>bar</a></td><td style="display: none">baz</td></tr></table>';
|
||||
|
||||
assert.strictEqual( utils.htmlToText( html ), 'Foo bar', 'works' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'htmlToTextWithLinks()', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
html = '<table><tr><td><b>F</b>o<i>o</i></td><td><a>bar</a></td><td style="display: none">baz</td></tr></table>';
|
||||
const utils = new HtmlUtils();
|
||||
const html = '<table><tr><td><b>F</b>o<i>o</i></td><td><a>bar</a></td><td style="display: none">baz</td></tr></table>';
|
||||
|
||||
assert.strictEqual( utils.htmlToTextWithLinks( html ), 'Foo <a>bar</a>', 'works' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'htmlToTextWithTags()', function ( assert ) {
|
||||
var utils = new HtmlUtils(),
|
||||
html = '<table><tr><td><b>F</b>o<i>o</i><sub>o</sub><sup>o</sup></td><td><a>bar</a></td><td style="display: none">baz</td></tr></table>';
|
||||
const utils = new HtmlUtils();
|
||||
const html = '<table><tr><td><b>F</b>o<i>o</i><sub>o</sub><sup>o</sup></td><td><a>bar</a></td><td style="display: none">baz</td></tr></table>';
|
||||
|
||||
assert.strictEqual( utils.htmlToTextWithTags( html ), '<b>F</b>o<i>o</i><sub>o</sub><sup>o</sup> <a>bar</a>', 'works' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'isJQueryOrHTMLElement()', function ( assert ) {
|
||||
var utils = new HtmlUtils();
|
||||
const utils = new HtmlUtils();
|
||||
|
||||
assert.strictEqual( utils.isJQueryOrHTMLElement( $( '<span>' ) ), true, 'Recognizes jQuery objects correctly' );
|
||||
assert.strictEqual( utils.isJQueryOrHTMLElement( $( '<span>' ).get( 0 ) ), true, 'Recognizes HTMLElements correctly' );
|
||||
|
@ -187,7 +187,7 @@ const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'makeLinkText()', function ( assert ) {
|
||||
var utils = new HtmlUtils();
|
||||
const utils = new HtmlUtils();
|
||||
|
||||
assert.strictEqual( utils.makeLinkText( 'foo', {
|
||||
href: 'http://example.com',
|
||||
|
|
|
@ -4,11 +4,10 @@ const { ThumbnailWidthCalculator } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.ThumbnailWidthCalculator', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'ThumbnailWidthCalculator constructor sense check', function ( assert ) {
|
||||
var badWidthBuckets = [],
|
||||
goodWidthBuckets = [ 1 ],
|
||||
thumbnailWidthCalculator;
|
||||
const badWidthBuckets = [];
|
||||
const goodWidthBuckets = [ 1 ];
|
||||
|
||||
thumbnailWidthCalculator = new ThumbnailWidthCalculator();
|
||||
let thumbnailWidthCalculator = new ThumbnailWidthCalculator();
|
||||
assert.true( thumbnailWidthCalculator instanceof ThumbnailWidthCalculator, 'constructor with no argument works' );
|
||||
|
||||
thumbnailWidthCalculator = new ThumbnailWidthCalculator( {} );
|
||||
|
@ -27,7 +26,7 @@ const { ThumbnailWidthCalculator } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'findNextBucket() test', function ( assert ) {
|
||||
var thumbnailWidthCalculator = new ThumbnailWidthCalculator( {
|
||||
const thumbnailWidthCalculator = new ThumbnailWidthCalculator( {
|
||||
widthBuckets: [ 100, 200 ]
|
||||
} );
|
||||
|
||||
|
@ -46,7 +45,7 @@ const { ThumbnailWidthCalculator } = require( 'mmv' );
|
|||
|
||||
// Old tests for the default bucket sizes. Preserved because why not.
|
||||
QUnit.test( 'We get sensible image sizes when we ask for them', function ( assert ) {
|
||||
var twc = new ThumbnailWidthCalculator();
|
||||
const twc = new ThumbnailWidthCalculator();
|
||||
|
||||
assert.strictEqual( twc.findNextBucket( 200 ), 320, 'Low target size gives us lowest possible size bucket' );
|
||||
assert.strictEqual( twc.findNextBucket( 320 ), 320, 'Asking for a bucket size gives us exactly that bucket size' );
|
||||
|
@ -56,7 +55,7 @@ const { ThumbnailWidthCalculator } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'findNextBucket() test with unordered bucket list', function ( assert ) {
|
||||
var thumbnailWidthCalculator = new ThumbnailWidthCalculator( {
|
||||
const thumbnailWidthCalculator = new ThumbnailWidthCalculator( {
|
||||
widthBuckets: [ 200, 100 ]
|
||||
} );
|
||||
|
||||
|
@ -71,9 +70,9 @@ const { ThumbnailWidthCalculator } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'calculateFittingWidth() test', function ( assert ) {
|
||||
var boundingWidth = 100,
|
||||
boundingHeight = 200,
|
||||
thumbnailWidthCalculator = new ThumbnailWidthCalculator( { widthBuckets: [ 1 ] } );
|
||||
const boundingWidth = 100;
|
||||
const boundingHeight = 200;
|
||||
const thumbnailWidthCalculator = new ThumbnailWidthCalculator( { widthBuckets: [ 1 ] } );
|
||||
|
||||
// 50x10 image in 100x200 box - need to scale up 2x
|
||||
assert.strictEqual(
|
||||
|
@ -92,16 +91,15 @@ const { ThumbnailWidthCalculator } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'calculateWidths() test', function ( assert ) {
|
||||
var boundingWidth = 100,
|
||||
boundingHeight = 200,
|
||||
thumbnailWidthCalculator = new ThumbnailWidthCalculator( {
|
||||
widthBuckets: [ 8, 16, 32, 64, 128, 256, 512 ],
|
||||
devicePixelRatio: 1
|
||||
} ),
|
||||
widths;
|
||||
const boundingWidth = 100;
|
||||
const boundingHeight = 200;
|
||||
const thumbnailWidthCalculator = new ThumbnailWidthCalculator( {
|
||||
widthBuckets: [ 8, 16, 32, 64, 128, 256, 512 ],
|
||||
devicePixelRatio: 1
|
||||
} );
|
||||
|
||||
// 50x10 image in 100x200 box - image size should be 100x20, thumbnail should be 128x25.6
|
||||
widths = thumbnailWidthCalculator.calculateWidths( boundingWidth, boundingHeight, 50, 10 );
|
||||
let widths = thumbnailWidthCalculator.calculateWidths( boundingWidth, boundingHeight, 50, 10 );
|
||||
assert.strictEqual( widths.cssWidth, 100, 'css width is correct when limited by width' );
|
||||
assert.strictEqual( widths.cssHeight, 20, 'css height is correct when limited by width' );
|
||||
assert.strictEqual( widths.real, 128, 'real width is correct when limited by width' );
|
||||
|
@ -120,16 +118,15 @@ const { ThumbnailWidthCalculator } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'calculateWidths() test with non-standard device pixel ratio', function ( assert ) {
|
||||
var boundingWidth = 100,
|
||||
boundingHeight = 200,
|
||||
thumbnailWidthCalculator = new ThumbnailWidthCalculator( {
|
||||
widthBuckets: [ 8, 16, 32, 64, 128, 256, 512 ],
|
||||
devicePixelRatio: 2
|
||||
} ),
|
||||
widths;
|
||||
const boundingWidth = 100;
|
||||
const boundingHeight = 200;
|
||||
const thumbnailWidthCalculator = new ThumbnailWidthCalculator( {
|
||||
widthBuckets: [ 8, 16, 32, 64, 128, 256, 512 ],
|
||||
devicePixelRatio: 2
|
||||
} );
|
||||
|
||||
// 50x10 image in 100x200 box - image size should be 100x20, thumbnail should be 256x51.2
|
||||
widths = thumbnailWidthCalculator.calculateWidths( boundingWidth, boundingHeight, 50, 10 );
|
||||
let widths = thumbnailWidthCalculator.calculateWidths( boundingWidth, boundingHeight, 50, 10 );
|
||||
assert.strictEqual( widths.cssWidth, 100, 'css width is correct when limited by width' );
|
||||
assert.strictEqual( widths.cssHeight, 20, 'css height is correct when limited by width' );
|
||||
assert.strictEqual( widths.real, 256, 'real width is correct when limited by width' );
|
||||
|
|
|
@ -67,10 +67,10 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} ) );
|
||||
|
||||
function createGallery( imageSrc, caption ) {
|
||||
var $div = $( '<div>' ).addClass( 'gallery' ).appendTo( '#qunit-fixture' ),
|
||||
$galleryBox = $( '<div>' ).addClass( 'gallerybox' ).appendTo( $div ),
|
||||
$thumbwrap = $( '<div>' ).addClass( 'thumb' ).appendTo( $galleryBox ),
|
||||
$link = $( '<a>' ).addClass( 'image' ).appendTo( $thumbwrap );
|
||||
const $div = $( '<div>' ).addClass( 'gallery' ).appendTo( '#qunit-fixture' );
|
||||
const $galleryBox = $( '<div>' ).addClass( 'gallerybox' ).appendTo( $div );
|
||||
const $thumbwrap = $( '<div>' ).addClass( 'thumb' ).appendTo( $galleryBox );
|
||||
const $link = $( '<a>' ).addClass( 'image' ).appendTo( $thumbwrap );
|
||||
|
||||
$( '<img>' ).attr( 'src', ( imageSrc || 'thumb.jpg' ) ).appendTo( $link );
|
||||
$( '<div>' ).addClass( 'gallerytext' ).text( caption || 'Foobar' ).appendTo( $galleryBox );
|
||||
|
@ -79,8 +79,8 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
}
|
||||
|
||||
function createThumb( imageSrc, caption, alt ) {
|
||||
var $div = $( '<div>' ).addClass( 'thumb' ).appendTo( '#qunit-fixture' ),
|
||||
$link = $( '<a>' ).addClass( 'image' ).appendTo( $div );
|
||||
const $div = $( '<div>' ).addClass( 'thumb' ).appendTo( '#qunit-fixture' );
|
||||
const $link = $( '<a>' ).addClass( 'image' ).appendTo( $div );
|
||||
|
||||
$( '<div>' ).addClass( 'thumbcaption' ).appendTo( $div ).text( caption );
|
||||
$( '<img>' ).attr( 'src', ( imageSrc || 'thumb.jpg' ) ).attr( 'alt', alt ).appendTo( $link );
|
||||
|
@ -89,19 +89,18 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
}
|
||||
|
||||
function createNormal( imageSrc, caption ) {
|
||||
var $link = $( '<a>' ).prop( 'title', caption ).addClass( 'image' ).appendTo( '#qunit-fixture' );
|
||||
const $link = $( '<a>' ).prop( 'title', caption ).addClass( 'image' ).appendTo( '#qunit-fixture' );
|
||||
$( '<img>' ).prop( 'src', ( imageSrc || 'thumb.jpg' ) ).appendTo( $link );
|
||||
return $link;
|
||||
}
|
||||
|
||||
function createMultipleImage( images ) {
|
||||
var i, $div, $thumbimage, $link,
|
||||
$contain = $( '<div>' ).addClass( 'thumb' ),
|
||||
$thumbinner = $( '<div>' ).addClass( 'thumbinner' ).appendTo( $contain );
|
||||
for ( i = 0; i < images.length; ++i ) {
|
||||
$div = $( '<div>' ).appendTo( $thumbinner );
|
||||
$thumbimage = $( '<div>' ).addClass( 'thumbimage' ).appendTo( $div );
|
||||
$link = $( '<a>' ).addClass( 'image' ).appendTo( $thumbimage );
|
||||
const $contain = $( '<div>' ).addClass( 'thumb' );
|
||||
const $thumbinner = $( '<div>' ).addClass( 'thumbinner' ).appendTo( $contain );
|
||||
for ( let i = 0; i < images.length; ++i ) {
|
||||
const $div = $( '<div>' ).appendTo( $thumbinner );
|
||||
const $thumbimage = $( '<div>' ).addClass( 'thumbimage' ).appendTo( $div );
|
||||
const $link = $( '<a>' ).addClass( 'image' ).appendTo( $thumbimage );
|
||||
$( '<img>' ).prop( 'src', images[ i ][ 0 ] ).appendTo( $link );
|
||||
$( '<div>' ).addClass( 'thumbcaption' ).text( images[ i ][ 1 ] ).appendTo( $div );
|
||||
}
|
||||
|
@ -109,7 +108,7 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
}
|
||||
|
||||
function createBootstrap( viewer ) {
|
||||
var bootstrap = new MultimediaViewerBootstrap();
|
||||
const bootstrap = new MultimediaViewerBootstrap();
|
||||
|
||||
bootstrap.processThumbs( $( '#qunit-fixture' ) );
|
||||
|
||||
|
@ -130,8 +129,8 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
}
|
||||
|
||||
function hashTest( prefix, bootstrap, assert ) {
|
||||
var hash = prefix + '/foo',
|
||||
callCount = 0;
|
||||
const hash = prefix + '/foo';
|
||||
let callCount = 0;
|
||||
|
||||
bootstrap.loadViewer = function () {
|
||||
callCount++;
|
||||
|
@ -161,15 +160,14 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
}
|
||||
|
||||
QUnit.test( 'Promise does not hang on ResourceLoader errors', function ( assert ) {
|
||||
var bootstrap,
|
||||
errorMessage = 'loading failed',
|
||||
done = assert.async();
|
||||
const errorMessage = 'loading failed';
|
||||
const done = assert.async();
|
||||
|
||||
this.sandbox.stub( mw.loader, 'using' )
|
||||
.callsArgWith( 2, new Error( errorMessage, [ 'mmv' ] ) )
|
||||
.withArgs( 'mediawiki.notification' ).returns( $.Deferred().reject() ); // needed for mw.notify
|
||||
|
||||
bootstrap = createBootstrap();
|
||||
const bootstrap = createBootstrap();
|
||||
this.sandbox.stub( bootstrap, 'setupOverlay' );
|
||||
this.sandbox.stub( bootstrap, 'cleanupOverlay' );
|
||||
|
||||
|
@ -182,9 +180,8 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} );
|
||||
|
||||
QUnit.test( 'Clicks are not captured once the loading fails', function ( assert ) {
|
||||
var event, returnValue,
|
||||
bootstrap = new MultimediaViewerBootstrap(),
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const bootstrap = new MultimediaViewerBootstrap();
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
this.sandbox.stub( mw.loader, 'using' )
|
||||
.callsArgWith( 2, new Error( 'loading failed', [ 'mmv' ] ) )
|
||||
|
@ -193,8 +190,8 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
|
||||
// trigger first click, which will cause MMV to be loaded (which we've
|
||||
// set up to fail)
|
||||
event = new $.Event( 'click', { button: 0, which: 1 } );
|
||||
returnValue = bootstrap.click( event, mw.Title.newFromText( 'Foo' ) );
|
||||
const event = new $.Event( 'click', { button: 0, which: 1 } );
|
||||
const returnValue = bootstrap.click( event, mw.Title.newFromText( 'Foo' ) );
|
||||
clock.tick( 10 );
|
||||
assert.true( event.isDefaultPrevented(), 'First click is caught' );
|
||||
assert.strictEqual( returnValue, false, 'First click is caught' );
|
||||
|
@ -204,20 +201,19 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
// FIXME: Tests suspended as they do not pass in QUnit 2.x+ – T192932
|
||||
QUnit.skip( 'Check viewer invoked when clicking on valid image links', function ( assert ) {
|
||||
// TODO: Is <div class="gallery"><span class="image"><img/></span></div> valid ???
|
||||
var div, $link, $link2, $link3, $link4, $link5, bootstrap,
|
||||
viewer = { initWithThumbs: function () {}, loadImageByTitle: this.sandbox.stub() },
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const viewer = { initWithThumbs: function () {}, loadImageByTitle: this.sandbox.stub() };
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
// Create gallery with valid link image
|
||||
div = createGallery();
|
||||
$link = div.find( 'a.image' );
|
||||
const div = createGallery();
|
||||
const $link = div.find( 'a.image' );
|
||||
|
||||
// Valid isolated thumbnail
|
||||
$link2 = $( '<a>' ).addClass( 'image' ).appendTo( '#qunit-fixture' );
|
||||
const $link2 = $( '<a>' ).addClass( 'image' ).appendTo( '#qunit-fixture' );
|
||||
$( '<img>' ).attr( 'src', 'thumb2.jpg' ).appendTo( $link2 );
|
||||
|
||||
// Non-valid fragment
|
||||
$link3 = $( '<a>' ).addClass( 'noImage' ).appendTo( div );
|
||||
const $link3 = $( '<a>' ).addClass( 'noImage' ).appendTo( div );
|
||||
$( '<img>' ).attr( 'src', 'thumb3.jpg' ).appendTo( $link3 );
|
||||
|
||||
mw.config.set( 'wgTitle', 'Thumb4.jpg' );
|
||||
|
@ -233,13 +229,13 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
);
|
||||
|
||||
// Create a new bootstrap object to trigger the DOM scan, etc.
|
||||
bootstrap = createBootstrap( viewer );
|
||||
const bootstrap = createBootstrap( viewer );
|
||||
this.sandbox.stub( bootstrap, 'setupOverlay' );
|
||||
|
||||
$link4 = $( '.fullMedia .mw-mmv-view-expanded' );
|
||||
const $link4 = $( '.fullMedia .mw-mmv-view-expanded' );
|
||||
assert.ok( $link4.length, 'Link for viewing expanded file was set up.' );
|
||||
|
||||
$link5 = $( '.fullMedia .mw-mmv-view-config' );
|
||||
const $link5 = $( '.fullMedia .mw-mmv-view-config' );
|
||||
assert.ok( $link5.length, 'Link for opening enable/disable configuration was set up.' );
|
||||
|
||||
// Click on valid link
|
||||
|
@ -294,13 +290,12 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} );
|
||||
|
||||
QUnit.test( 'Skip images with invalid extensions', function ( assert ) {
|
||||
var div, link,
|
||||
viewer = { initWithThumbs: function () {}, loadImageByTitle: this.sandbox.stub() },
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const viewer = { initWithThumbs: function () {}, loadImageByTitle: this.sandbox.stub() };
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
// Create gallery with image that has invalid name extension
|
||||
div = createGallery( 'thumb.badext' );
|
||||
link = div.find( 'a.image' );
|
||||
const div = createGallery( 'thumb.badext' );
|
||||
const link = div.find( 'a.image' );
|
||||
|
||||
// Create a new bootstrap object to trigger the DOM scan, etc.
|
||||
createBootstrap( viewer );
|
||||
|
@ -316,18 +311,17 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
|
||||
// FIXME: Tests suspended as they do not pass in QUnit 2.x+ – T192932
|
||||
QUnit.skip( 'Accept only left clicks without modifier keys, skip the rest', function ( assert ) {
|
||||
var $div, $link, bootstrap,
|
||||
viewer = { initWithThumbs: function () {}, loadImageByTitle: this.sandbox.stub() },
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const viewer = { initWithThumbs: function () {}, loadImageByTitle: this.sandbox.stub() };
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
// Create gallery with image that has valid name extension
|
||||
$div = createGallery();
|
||||
const $div = createGallery();
|
||||
|
||||
// Create a new bootstrap object to trigger the DOM scan, etc.
|
||||
bootstrap = createBootstrap( viewer );
|
||||
const bootstrap = createBootstrap( viewer );
|
||||
this.sandbox.stub( bootstrap, 'setupOverlay' );
|
||||
|
||||
$link = $div.find( 'a.image' );
|
||||
const $link = $div.find( 'a.image' );
|
||||
|
||||
// Handle valid left click, it should try to load the image
|
||||
$link.trigger( { type: 'click', which: 1 } );
|
||||
|
@ -355,12 +349,11 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} );
|
||||
|
||||
QUnit.test( 'Ensure that the correct title is loaded when clicking', function ( assert ) {
|
||||
var bootstrap,
|
||||
viewer = { initWithThumbs: function () {}, loadImageByTitle: this.sandbox.stub() },
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const viewer = { initWithThumbs: function () {}, loadImageByTitle: this.sandbox.stub() };
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
// Create a new bootstrap object to trigger the DOM scan, etc.
|
||||
bootstrap = createBootstrap( viewer );
|
||||
const bootstrap = createBootstrap( viewer );
|
||||
this.sandbox.stub( bootstrap, 'setupOverlay' );
|
||||
|
||||
bootstrap.route( 'File:Foo.jpg' );
|
||||
|
@ -374,25 +367,22 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
|
||||
// FIXME: Tests suspended as they do not pass in QUnit 2.x+ – T192932
|
||||
QUnit.skip( 'Validate new LightboxImage object has sensible constructor parameters', function ( assert ) {
|
||||
var bootstrap,
|
||||
$div,
|
||||
$link,
|
||||
viewer = getMultimediaViewer(),
|
||||
fname = 'valid',
|
||||
imgSrc = '/' + fname + '.jpg/300px-' + fname + '.jpg',
|
||||
imgRegex = new RegExp( imgSrc + '$' ),
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const viewer = getMultimediaViewer();
|
||||
const fname = 'valid';
|
||||
const imgSrc = '/' + fname + '.jpg/300px-' + fname + '.jpg';
|
||||
const imgRegex = new RegExp( imgSrc + '$' );
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
$div = createThumb( imgSrc, 'Blah blah', 'meow' );
|
||||
$link = $div.find( 'a.image' );
|
||||
const $div = createThumb( imgSrc, 'Blah blah', 'meow' );
|
||||
const $link = $div.find( 'a.image' );
|
||||
|
||||
// Create a new bootstrap object to trigger the DOM scan, etc.
|
||||
bootstrap = createBootstrap( viewer );
|
||||
const bootstrap = createBootstrap( viewer );
|
||||
this.sandbox.stub( bootstrap, 'setupOverlay' );
|
||||
this.sandbox.stub( viewer, 'createNewImage' );
|
||||
viewer.loadImage = function () {};
|
||||
viewer.createNewImage = function ( fileLink, filePageLink, fileTitle, index, thumb, caption, alt ) {
|
||||
var html = thumb.outerHTML;
|
||||
const html = thumb.outerHTML;
|
||||
|
||||
// FIXME: fileLink doesn't match imgRegex (null)
|
||||
assert.ok( fileLink.match( imgRegex ), 'Thumbnail URL used in creating new image object' );
|
||||
|
@ -413,31 +403,25 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} );
|
||||
|
||||
QUnit.test( 'Only load the viewer on a valid hash', function ( assert ) {
|
||||
var bootstrap;
|
||||
|
||||
location.hash = '';
|
||||
|
||||
bootstrap = createBootstrap();
|
||||
const bootstrap = createBootstrap();
|
||||
|
||||
return hashTest( '/media', bootstrap, assert );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Load the viewer on a legacy hash', function ( assert ) {
|
||||
var bootstrap;
|
||||
|
||||
location.hash = '';
|
||||
|
||||
bootstrap = createBootstrap();
|
||||
const bootstrap = createBootstrap();
|
||||
|
||||
return hashTest( 'mediaviewer', bootstrap, assert );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Overlay is set up on hash change', function ( assert ) {
|
||||
var bootstrap;
|
||||
|
||||
location.hash = '#/media/foo';
|
||||
|
||||
bootstrap = createBootstrap();
|
||||
const bootstrap = createBootstrap();
|
||||
this.sandbox.stub( bootstrap, 'setupOverlay' );
|
||||
|
||||
bootstrap.hash();
|
||||
|
@ -446,11 +430,9 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} );
|
||||
|
||||
QUnit.test( 'Overlay is not set up on an irrelevant hash change', function ( assert ) {
|
||||
var bootstrap;
|
||||
|
||||
location.hash = '#foo';
|
||||
|
||||
bootstrap = createBootstrap();
|
||||
const bootstrap = createBootstrap();
|
||||
this.sandbox.stub( bootstrap, 'setupOverlay' );
|
||||
bootstrap.loadViewer();
|
||||
bootstrap.setupOverlay.reset();
|
||||
|
@ -461,10 +443,10 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} );
|
||||
|
||||
QUnit.test( 'Restoring article scroll position', function ( assert ) {
|
||||
var stubbedScrollTop,
|
||||
bootstrap = createBootstrap(),
|
||||
$window = $( window ),
|
||||
done = assert.async();
|
||||
let stubbedScrollTop;
|
||||
const bootstrap = createBootstrap();
|
||||
const $window = $( window );
|
||||
const done = assert.async();
|
||||
|
||||
this.sandbox.stub( $.fn, 'scrollTop', function ( scrollTop ) {
|
||||
if ( scrollTop !== undefined ) {
|
||||
|
@ -491,15 +473,14 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} );
|
||||
|
||||
QUnit.test( 'Preload JS/CSS dependencies on thumb hover', function ( assert ) {
|
||||
var $div, bootstrap,
|
||||
clock = this.sandbox.useFakeTimers(),
|
||||
viewer = { initWithThumbs: function () {} };
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
const viewer = { initWithThumbs: function () {} };
|
||||
|
||||
// Create gallery with image that has valid name extension
|
||||
$div = createThumb();
|
||||
const $div = createThumb();
|
||||
|
||||
// Create a new bootstrap object to trigger the DOM scan, etc.
|
||||
bootstrap = createBootstrap( viewer );
|
||||
const bootstrap = createBootstrap( viewer );
|
||||
|
||||
this.sandbox.stub( mw.loader, 'load' );
|
||||
|
||||
|
@ -519,9 +500,9 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} );
|
||||
|
||||
QUnit.test( 'isAllowedThumb', function ( assert ) {
|
||||
var $container = $( '<div>' ),
|
||||
$thumb = $( '<img>' ).appendTo( $container ),
|
||||
bootstrap = createBootstrap();
|
||||
const $container = $( '<div>' );
|
||||
const $thumb = $( '<img>' ).appendTo( $container );
|
||||
const bootstrap = createBootstrap();
|
||||
|
||||
assert.strictEqual( bootstrap.isAllowedThumb( $thumb ), true, 'Normal image in a div is allowed.' );
|
||||
|
||||
|
@ -539,12 +520,15 @@ const { asyncMethod, waitForAsync, getMultimediaViewer } = require( './mmv.testh
|
|||
} );
|
||||
|
||||
QUnit.test( 'findCaption', function ( assert ) {
|
||||
var gallery = createGallery( 'foo.jpg', 'Baz' ),
|
||||
thumb = createThumb( 'foo.jpg', 'Quuuuux' ),
|
||||
link = createNormal( 'foo.jpg', 'Foobar' ),
|
||||
multiple = createMultipleImage( [ [ 'foo.jpg', 'Image #1' ], [ 'bar.jpg', 'Image #2' ],
|
||||
[ 'foobar.jpg', 'Image #3' ] ] ),
|
||||
bootstrap = createBootstrap();
|
||||
const gallery = createGallery( 'foo.jpg', 'Baz' );
|
||||
const thumb = createThumb( 'foo.jpg', 'Quuuuux' );
|
||||
const link = createNormal( 'foo.jpg', 'Foobar' );
|
||||
const multiple = createMultipleImage( [
|
||||
[ 'foo.jpg', 'Image #1' ],
|
||||
[ 'bar.jpg', 'Image #2' ],
|
||||
[ 'foobar.jpg', 'Image #3' ]
|
||||
] );
|
||||
const bootstrap = createBootstrap();
|
||||
|
||||
assert.strictEqual( bootstrap.findCaption( gallery.find( '.thumb' ), gallery.find( 'a.image' ) ), 'Baz', 'A gallery caption is found.' );
|
||||
assert.strictEqual( bootstrap.findCaption( thumb, thumb.find( 'a.image' ) ), 'Quuuuux', 'A thumbnail caption is found.' );
|
||||
|
|
|
@ -3,7 +3,7 @@ const { LightboxImage } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.lightboximage', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Sense test', function ( assert ) {
|
||||
var lightboxImage = new LightboxImage( 'foo.png' );
|
||||
const lightboxImage = new LightboxImage( 'foo.png' );
|
||||
|
||||
assert.true( lightboxImage instanceof LightboxImage, 'Object created' );
|
||||
} );
|
||||
|
|
|
@ -2,7 +2,7 @@ const { LightboxInterface } = require( 'mmv' );
|
|||
const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
||||
|
||||
( function () {
|
||||
var oldScrollTo;
|
||||
let oldScrollTo;
|
||||
|
||||
function stubScrollTo() {
|
||||
oldScrollTo = $.scrollTo;
|
||||
|
@ -23,12 +23,12 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
} ) );
|
||||
|
||||
QUnit.test( 'Sense test, object creation and ui construction', function ( assert ) {
|
||||
var lightbox = new LightboxInterface();
|
||||
const lightbox = new LightboxInterface();
|
||||
|
||||
stubScrollTo();
|
||||
|
||||
function checkIfUIAreasAttachedToDocument( inDocument ) {
|
||||
var msg = ( inDocument === 1 ? ' ' : ' not ' ) + 'attached.';
|
||||
const msg = ( inDocument === 1 ? ' ' : ' not ' ) + 'attached.';
|
||||
assert.strictEqual( $( '.mw-mmv-wrapper' ).length, inDocument, 'Wrapper area' + msg );
|
||||
assert.strictEqual( $( '.mw-mmv-main' ).length, inDocument, 'Main area' + msg );
|
||||
assert.strictEqual( $( '.mw-mmv-title' ).length, inDocument, 'Title area' + msg );
|
||||
|
@ -60,9 +60,9 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Handler registration and clearance work OK', function ( assert ) {
|
||||
var lightbox = new LightboxInterface(),
|
||||
handlerCalls = 0,
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const lightbox = new LightboxInterface();
|
||||
let handlerCalls = 0;
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
function handleEvent() {
|
||||
handlerCalls++;
|
||||
|
@ -83,8 +83,8 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Fullscreen mode init', function ( assert ) {
|
||||
var lightbox = new LightboxInterface(),
|
||||
enterFullscreen = Element.prototype.requestFullscreen;
|
||||
const lightbox = new LightboxInterface();
|
||||
const enterFullscreen = Element.prototype.requestFullscreen;
|
||||
|
||||
// Since we don't want these tests to really open fullscreen
|
||||
// which is subject to user security confirmation,
|
||||
|
@ -135,11 +135,9 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Fullscreen mode', function ( assert ) {
|
||||
var buttonOffset, panelBottom,
|
||||
oldRevealButtonsAndFadeIfNeeded,
|
||||
lightbox = new LightboxInterface(),
|
||||
viewer = getMultimediaViewer(),
|
||||
enterFullscreen = Element.prototype.requestFullscreen;
|
||||
const lightbox = new LightboxInterface();
|
||||
const viewer = getMultimediaViewer();
|
||||
const enterFullscreen = Element.prototype.requestFullscreen;
|
||||
|
||||
stubScrollTo();
|
||||
|
||||
|
@ -164,7 +162,7 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
};
|
||||
|
||||
// Pretend that the mouse cursor is on top of the button
|
||||
buttonOffset = lightbox.buttons.$fullscreen.offset();
|
||||
const buttonOffset = lightbox.buttons.$fullscreen.offset();
|
||||
lightbox.mousePosition = { x: buttonOffset.left, y: buttonOffset.top };
|
||||
|
||||
// Enter fullscreen
|
||||
|
@ -173,7 +171,7 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
lightbox.buttons.fadeOut = function () {};
|
||||
assert.true( lightbox.isFullscreen, 'Lightbox knows that it\'s in fullscreen mode' );
|
||||
|
||||
oldRevealButtonsAndFadeIfNeeded = lightbox.buttons.revealAndFade;
|
||||
const oldRevealButtonsAndFadeIfNeeded = lightbox.buttons.revealAndFade;
|
||||
|
||||
lightbox.buttons.revealAndFade = function ( position ) {
|
||||
assert.true( true, 'Moving the cursor triggers a reveal + fade' );
|
||||
|
@ -186,7 +184,7 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
|
||||
lightbox.buttons.revealAndFadeIfNeeded = function () {};
|
||||
|
||||
panelBottom = $( '.mw-mmv-post-image' ).position().top + $( '.mw-mmv-post-image' ).height();
|
||||
let panelBottom = $( '.mw-mmv-post-image' ).position().top + $( '.mw-mmv-post-image' ).height();
|
||||
|
||||
assert.strictEqual(
|
||||
panelBottom.toFixed(),
|
||||
|
@ -216,7 +214,7 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'isAnyActiveButtonHovered', function ( assert ) {
|
||||
var lightbox = new LightboxInterface();
|
||||
const lightbox = new LightboxInterface();
|
||||
|
||||
stubScrollTo();
|
||||
|
||||
|
@ -224,11 +222,11 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
lightbox.attach( '#qunit-fixture' );
|
||||
|
||||
lightbox.buttons.$buttons.each( function () {
|
||||
var $button = $( this ),
|
||||
offset = $button.show().offset(),
|
||||
width = $button.width(),
|
||||
height = $button.height(),
|
||||
disabled = $button.hasClass( 'disabled' );
|
||||
const $button = $( this );
|
||||
const offset = $button.show().offset();
|
||||
const width = $button.width();
|
||||
const height = $button.height();
|
||||
const disabled = $button.hasClass( 'disabled' );
|
||||
|
||||
assert.strictEqual( lightbox.buttons.isAnyActiveButtonHovered( offset.left, offset.top ),
|
||||
!disabled,
|
||||
|
@ -257,8 +255,8 @@ const { getMultimediaViewer } = require( './mmv.testhelpers.js' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Keyboard prev/next', function ( assert ) {
|
||||
var viewer = getMultimediaViewer(),
|
||||
lightbox = new LightboxInterface();
|
||||
const viewer = getMultimediaViewer();
|
||||
const lightbox = new LightboxInterface();
|
||||
|
||||
viewer.setupEventHandlers();
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} ) );
|
||||
|
||||
QUnit.test( 'eachPreloadableLightboxIndex()', function ( assert ) {
|
||||
var viewer = getMultimediaViewer(),
|
||||
expectedIndices,
|
||||
i;
|
||||
const viewer = getMultimediaViewer();
|
||||
let expectedIndices;
|
||||
let i;
|
||||
|
||||
viewer.preloadDistance = 3;
|
||||
viewer.thumbs = [];
|
||||
|
@ -39,14 +39,14 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Progress', function ( assert ) {
|
||||
var imageDeferred = $.Deferred(),
|
||||
viewer = getMultimediaViewer(),
|
||||
fakeImage = {
|
||||
filePageTitle: new mw.Title( 'File:Stuff.jpg' ),
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
},
|
||||
// custom clock ensures progress handlers execute in correct sequence
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const imageDeferred = $.Deferred();
|
||||
const viewer = getMultimediaViewer();
|
||||
const fakeImage = {
|
||||
filePageTitle: new mw.Title( 'File:Stuff.jpg' ),
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
};
|
||||
// custom clock ensures progress handlers execute in correct sequence
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
viewer.thumbs = [];
|
||||
viewer.displayPlaceholderThumbnail = function () {};
|
||||
|
@ -105,21 +105,21 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Progress when switching images', function ( assert ) {
|
||||
var firstImageDeferred = $.Deferred(),
|
||||
secondImageDeferred = $.Deferred(),
|
||||
firstImage = {
|
||||
index: 1,
|
||||
filePageTitle: new mw.Title( 'File:First.jpg' ),
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
},
|
||||
secondImage = {
|
||||
index: 2,
|
||||
filePageTitle: new mw.Title( 'File:Second.jpg' ),
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
},
|
||||
viewer = getMultimediaViewer(),
|
||||
// custom clock ensures progress handlers execute in correct sequence
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const firstImageDeferred = $.Deferred();
|
||||
const secondImageDeferred = $.Deferred();
|
||||
const firstImage = {
|
||||
index: 1,
|
||||
filePageTitle: new mw.Title( 'File:First.jpg' ),
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
};
|
||||
const secondImage = {
|
||||
index: 2,
|
||||
filePageTitle: new mw.Title( 'File:Second.jpg' ),
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
};
|
||||
const viewer = getMultimediaViewer();
|
||||
// custom clock ensures progress handlers execute in correct sequence
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
// animation would keep running, conflict with other tests
|
||||
this.sandbox.stub( $.fn, 'animate' ).returnsThis();
|
||||
|
@ -225,7 +225,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'resetBlurredThumbnailStates', function ( assert ) {
|
||||
var viewer = getMultimediaViewer();
|
||||
const viewer = getMultimediaViewer();
|
||||
|
||||
// animation would keep running, conflict with other tests
|
||||
this.sandbox.stub( $.fn, 'animate' ).returnsThis();
|
||||
|
@ -243,7 +243,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Placeholder first, then real thumbnail', function ( assert ) {
|
||||
var viewer = getMultimediaViewer();
|
||||
const viewer = getMultimediaViewer();
|
||||
|
||||
viewer.setImage = function () {};
|
||||
viewer.ui = { canvas: {
|
||||
|
@ -265,7 +265,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Placeholder first, then real thumbnail - missing size', function ( assert ) {
|
||||
var viewer = getMultimediaViewer();
|
||||
const viewer = getMultimediaViewer();
|
||||
|
||||
viewer.currentIndex = 1;
|
||||
viewer.setImage = function () {};
|
||||
|
@ -288,7 +288,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Real thumbnail first, then placeholder', function ( assert ) {
|
||||
var viewer = getMultimediaViewer();
|
||||
const viewer = getMultimediaViewer();
|
||||
|
||||
viewer.setImage = function () {};
|
||||
viewer.ui = {
|
||||
|
@ -310,7 +310,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'displayRealThumbnail', function ( assert ) {
|
||||
var viewer = getMultimediaViewer();
|
||||
const viewer = getMultimediaViewer();
|
||||
|
||||
viewer.setImage = function () {};
|
||||
viewer.ui = { canvas: {
|
||||
|
@ -329,23 +329,23 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'New image loaded while another one is loading', function ( assert ) {
|
||||
var viewer = getMultimediaViewer(),
|
||||
firstImageDeferred = $.Deferred(),
|
||||
secondImageDeferred = $.Deferred(),
|
||||
firstLigthboxInfoDeferred = $.Deferred(),
|
||||
secondLigthboxInfoDeferred = $.Deferred(),
|
||||
firstImage = {
|
||||
filePageTitle: new mw.Title( 'File:Foo.jpg' ),
|
||||
index: 0,
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
},
|
||||
secondImage = {
|
||||
filePageTitle: new mw.Title( 'File:Bar.jpg' ),
|
||||
index: 1,
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
},
|
||||
// custom clock ensures progress handlers execute in correct sequence
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
const viewer = getMultimediaViewer();
|
||||
const firstImageDeferred = $.Deferred();
|
||||
const secondImageDeferred = $.Deferred();
|
||||
const firstLigthboxInfoDeferred = $.Deferred();
|
||||
const secondLigthboxInfoDeferred = $.Deferred();
|
||||
const firstImage = {
|
||||
filePageTitle: new mw.Title( 'File:Foo.jpg' ),
|
||||
index: 0,
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
};
|
||||
const secondImage = {
|
||||
filePageTitle: new mw.Title( 'File:Bar.jpg' ),
|
||||
index: 1,
|
||||
extraStatsDeferred: $.Deferred().reject()
|
||||
};
|
||||
// custom clock ensures progress handlers execute in correct sequence
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
viewer.preloadFullscreenThumbnail = function () {};
|
||||
viewer.fetchSizeIndependentLightboxInfo = this.sandbox.stub();
|
||||
|
@ -410,15 +410,14 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Events are not trapped after the viewer is closed', function ( assert ) {
|
||||
var i, j, k, eventParameters,
|
||||
viewer = getMultimediaViewer(),
|
||||
$document = $( document ),
|
||||
$qf = $( '#qunit-fixture' ),
|
||||
eventTypes = [ 'keydown', 'keyup', 'keypress', 'click', 'mousedown', 'mouseup' ],
|
||||
modifiers = [ undefined, 'altKey', 'ctrlKey', 'shiftKey', 'metaKey' ],
|
||||
// Events are async, we need to wait for the last event to be caught before ending the test
|
||||
done = assert.async(),
|
||||
oldScrollTo = $.scrollTo;
|
||||
const viewer = getMultimediaViewer();
|
||||
const $document = $( document );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const eventTypes = [ 'keydown', 'keyup', 'keypress', 'click', 'mousedown', 'mouseup' ];
|
||||
const modifiers = [ undefined, 'altKey', 'ctrlKey', 'shiftKey', 'metaKey' ];
|
||||
// Events are async, we need to wait for the last event to be caught before ending the test
|
||||
const done = assert.async();
|
||||
const oldScrollTo = $.scrollTo;
|
||||
|
||||
assert.expect( 0 );
|
||||
|
||||
|
@ -466,11 +465,11 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
}
|
||||
}
|
||||
|
||||
for ( j = 0; j < eventTypes.length; j++ ) {
|
||||
for ( let j = 0; j < eventTypes.length; j++ ) {
|
||||
$document.on( eventTypes[ j ] + '.mmvtest', eventHandler );
|
||||
|
||||
eventloop:
|
||||
for ( i = 0; i < 256; i++ ) {
|
||||
for ( let i = 0; i < 256; i++ ) {
|
||||
// Save some time by not testing unlikely values for mouse events
|
||||
if ( i > 32 ) {
|
||||
switch ( eventTypes[ j ] ) {
|
||||
|
@ -481,8 +480,8 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
}
|
||||
}
|
||||
|
||||
for ( k = 0; k < modifiers.length; k++ ) {
|
||||
eventParameters = { which: i };
|
||||
for ( let k = 0; k < modifiers.length; k++ ) {
|
||||
const eventParameters = { which: i };
|
||||
if ( modifiers[ k ] !== undefined ) {
|
||||
eventParameters[ modifiers[ k ] ] = true;
|
||||
}
|
||||
|
@ -493,10 +492,10 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Refuse to load too-big thumbnails', function ( assert ) {
|
||||
var title, expectedWidth,
|
||||
reuestedWidth = 1000,
|
||||
originalWidth = 50,
|
||||
viewer = getMultimediaViewer();
|
||||
let expectedWidth;
|
||||
const reuestedWidth = 1000;
|
||||
const originalWidth = 50;
|
||||
const viewer = getMultimediaViewer();
|
||||
|
||||
viewer.thumbnailInfoProvider.get = function ( fileTitle, width ) {
|
||||
assert.strictEqual( width, expectedWidth );
|
||||
|
@ -504,7 +503,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
};
|
||||
|
||||
// non-vector should be capped to original size
|
||||
title = mw.Title.newFromText( 'File:Foobar.png' );
|
||||
let title = mw.Title.newFromText( 'File:Foobar.png' );
|
||||
expectedWidth = originalWidth;
|
||||
viewer.fetchThumbnail( title, reuestedWidth, null, originalWidth, 60 );
|
||||
|
||||
|
@ -515,21 +514,29 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'fetchThumbnail()', function ( assert ) {
|
||||
var guessedThumbnailInfoStub,
|
||||
thumbnailInfoStub,
|
||||
imageStub,
|
||||
promise,
|
||||
useThumbnailGuessing,
|
||||
viewer = new MultimediaViewer( { imageQueryParameter: function () {}, language: function () {}, recordVirtualViewBeaconURI: function () {}, extensions: function () { return { jpg: 'default' }; }, useThumbnailGuessing: () => useThumbnailGuessing } ),
|
||||
sandbox = this.sandbox,
|
||||
file = new mw.Title( 'File:Copyleft.svg' ),
|
||||
sampleURL = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png',
|
||||
width = 100,
|
||||
originalWidth = 1000,
|
||||
originalHeight = 1000,
|
||||
image = {},
|
||||
// custom clock ensures progress handlers execute in correct sequence
|
||||
clock = this.sandbox.useFakeTimers();
|
||||
let guessedThumbnailInfoStub;
|
||||
let thumbnailInfoStub;
|
||||
let imageStub;
|
||||
let promise;
|
||||
let useThumbnailGuessing;
|
||||
const viewer = new MultimediaViewer( {
|
||||
imageQueryParameter: function () {},
|
||||
language: function () {},
|
||||
recordVirtualViewBeaconURI: function () {},
|
||||
extensions: function () {
|
||||
return { jpg: 'default' };
|
||||
},
|
||||
useThumbnailGuessing: () => useThumbnailGuessing
|
||||
} );
|
||||
const sandbox = this.sandbox;
|
||||
const file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const sampleURL = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png';
|
||||
const width = 100;
|
||||
const originalWidth = 1000;
|
||||
const originalHeight = 1000;
|
||||
const image = {};
|
||||
// custom clock ensures progress handlers execute in correct sequence
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
function setupStubs() {
|
||||
guessedThumbnailInfoStub = viewer.guessedThumbnailInfoProvider.get = sandbox.stub();
|
||||
|
@ -627,10 +634,10 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'document.title', function ( assert ) {
|
||||
var viewer = getMultimediaViewer(),
|
||||
bootstrap = new MultimediaViewerBootstrap(),
|
||||
title = new mw.Title( 'File:This_should_show_up_in_document_title.png' ),
|
||||
oldDocumentTitle = document.title;
|
||||
const viewer = getMultimediaViewer();
|
||||
const bootstrap = new MultimediaViewerBootstrap();
|
||||
const title = new mw.Title( 'File:This_should_show_up_in_document_title.png' );
|
||||
const oldDocumentTitle = document.title;
|
||||
|
||||
this.sandbox.stub( mw.loader, 'using' ).returns( $.Deferred().resolve( viewer ) );
|
||||
viewer.currentImageFileTitle = title;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { MultimediaViewer } = require( 'mmv' );
|
||||
|
||||
( function () {
|
||||
var MTH = {};
|
||||
const MTH = {};
|
||||
|
||||
/**
|
||||
* Returns the exception thrown by callback, or undefined if no exception was thrown.
|
||||
|
@ -10,7 +10,7 @@ const { MultimediaViewer } = require( 'mmv' );
|
|||
* @return {Error}
|
||||
*/
|
||||
MTH.getException = function ( callback ) {
|
||||
var ex;
|
||||
let ex;
|
||||
try {
|
||||
callback();
|
||||
} catch ( e ) {
|
||||
|
@ -44,7 +44,7 @@ const { MultimediaViewer } = require( 'mmv' );
|
|||
* @return {mw.SafeStorage} Local storage-like object
|
||||
*/
|
||||
MTH.getDisabledLocalStorage = function () {
|
||||
var e = function () {
|
||||
const e = function () {
|
||||
throw new Error( 'Error' );
|
||||
};
|
||||
|
||||
|
@ -62,7 +62,7 @@ const { MultimediaViewer } = require( 'mmv' );
|
|||
* @return {mw.SafeStorage} Local storage-like object
|
||||
*/
|
||||
MTH.getFakeLocalStorage = function ( initialData ) {
|
||||
var bag = new mw.Map();
|
||||
const bag = new mw.Map();
|
||||
bag.set( initialData );
|
||||
|
||||
return MTH.createLocalStorage( {
|
||||
|
@ -116,15 +116,15 @@ const { MultimediaViewer } = require( 'mmv' );
|
|||
* @return {Function}
|
||||
*/
|
||||
MTH.asyncMethod = function ( object, method, assert ) {
|
||||
var helpers = this;
|
||||
const helpers = this;
|
||||
return function () {
|
||||
// apply arguments to original promise
|
||||
var promise = object[ method ].apply( object, arguments );
|
||||
const promise = object[ method ].apply( object, arguments );
|
||||
|
||||
helpers.asyncPromises.push( promise );
|
||||
|
||||
if ( assert ) {
|
||||
var done = assert.async();
|
||||
const done = assert.async();
|
||||
// use setTimeout to ensure `done` is not the first callback handler
|
||||
// to execute (possibly ending the test's wait right before
|
||||
// the result of the promise is executed)
|
||||
|
@ -143,7 +143,7 @@ const { MultimediaViewer } = require( 'mmv' );
|
|||
* @return {jQuery.Promise}
|
||||
*/
|
||||
MTH.waitForAsync = function () {
|
||||
var deferred = $.Deferred();
|
||||
const deferred = $.Deferred();
|
||||
|
||||
// it's possible that, before this function call, some code was executed
|
||||
// that triggers async code that will eventually end up `asyncPromises`
|
||||
|
|
|
@ -21,37 +21,36 @@ const { ImageModel, License } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.model.Image', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Image model constructor sense check', function ( assert ) {
|
||||
var
|
||||
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
||||
name = 'Foo bar',
|
||||
size = 100,
|
||||
width = 10,
|
||||
height = 15,
|
||||
mime = 'image/jpeg',
|
||||
url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
pageID = 42,
|
||||
descurl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||
descShortUrl = '',
|
||||
repo = 'wikimediacommons',
|
||||
datetime = '2011-07-04T23:31:14Z',
|
||||
anondatetime = '20110704000000',
|
||||
origdatetime = '2010-07-04T23:31:14Z',
|
||||
description = 'This is a test file.',
|
||||
source = 'WMF',
|
||||
author = 'Ryan Kaldari',
|
||||
authorCount = 1,
|
||||
permission = 'only use for good, not evil',
|
||||
deletionReason = 'poor quality',
|
||||
license = new License( 'cc0' ),
|
||||
attribution = 'Created by my cats on a winter morning',
|
||||
latitude = 39.12381283,
|
||||
longitude = 100.983829,
|
||||
restrictions = [ 'trademarked' ],
|
||||
imageData = new ImageModel(
|
||||
title, name, size, width, height, mime, url,
|
||||
descurl, descShortUrl, pageID, repo, datetime, anondatetime, origdatetime,
|
||||
description, source, author, authorCount, license, permission, attribution,
|
||||
deletionReason, latitude, longitude, restrictions );
|
||||
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
||||
const name = 'Foo bar';
|
||||
const size = 100;
|
||||
const width = 10;
|
||||
const height = 15;
|
||||
const mime = 'image/jpeg';
|
||||
const url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const pageID = 42;
|
||||
const descurl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
||||
const descShortUrl = '';
|
||||
const repo = 'wikimediacommons';
|
||||
const datetime = '2011-07-04T23:31:14Z';
|
||||
const anondatetime = '20110704000000';
|
||||
const origdatetime = '2010-07-04T23:31:14Z';
|
||||
const description = 'This is a test file.';
|
||||
const source = 'WMF';
|
||||
const author = 'Ryan Kaldari';
|
||||
const authorCount = 1;
|
||||
const permission = 'only use for good, not evil';
|
||||
const deletionReason = 'poor quality';
|
||||
const license = new License( 'cc0' );
|
||||
const attribution = 'Created by my cats on a winter morning';
|
||||
const latitude = 39.12381283;
|
||||
const longitude = 100.983829;
|
||||
const restrictions = [ 'trademarked' ];
|
||||
const imageData = new ImageModel(
|
||||
title, name, size, width, height, mime, url,
|
||||
descurl, descShortUrl, pageID, repo, datetime, anondatetime, origdatetime,
|
||||
description, source, author, authorCount, license, permission, attribution,
|
||||
deletionReason, latitude, longitude, restrictions );
|
||||
|
||||
assert.strictEqual( imageData.title, title, 'Title is set correctly' );
|
||||
assert.strictEqual( imageData.name, name, 'Name is set correctly' );
|
||||
|
@ -81,39 +80,38 @@ const { ImageModel, License } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'hasCoords()', function ( assert ) {
|
||||
var
|
||||
firstImageData = new ImageModel(
|
||||
mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 'Foo bar',
|
||||
10, 10, 10, 'image/jpeg', 'http://example.org', 'http://example.com', 42,
|
||||
'example', 'tester', '2013-11-10', '20131110', '2013-11-09', 'Blah blah blah',
|
||||
'A person', 'Another person', 1, 'CC-BY-SA-3.0', 'Permitted', 'My cat'
|
||||
),
|
||||
secondImageData = new ImageModel(
|
||||
mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 'Foo bar',
|
||||
10, 10, 10, 'image/jpeg', 'http://example.org', 'http://example.com', 42,
|
||||
'example', 'tester', '2013-11-10', '20131110', '2013-11-09', 'Blah blah blah',
|
||||
'A person', 'Another person', 1, 'CC-BY-SA-3.0', 'Permitted', 'My cat',
|
||||
undefined, '39.91820938', '78.09812938'
|
||||
);
|
||||
const firstImageData = new ImageModel(
|
||||
mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 'Foo bar',
|
||||
10, 10, 10, 'image/jpeg', 'http://example.org', 'http://example.com', 42,
|
||||
'example', 'tester', '2013-11-10', '20131110', '2013-11-09', 'Blah blah blah',
|
||||
'A person', 'Another person', 1, 'CC-BY-SA-3.0', 'Permitted', 'My cat'
|
||||
);
|
||||
const secondImageData = new ImageModel(
|
||||
mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 'Foo bar',
|
||||
10, 10, 10, 'image/jpeg', 'http://example.org', 'http://example.com', 42,
|
||||
'example', 'tester', '2013-11-10', '20131110', '2013-11-09', 'Blah blah blah',
|
||||
'A person', 'Another person', 1, 'CC-BY-SA-3.0', 'Permitted', 'My cat',
|
||||
undefined, '39.91820938', '78.09812938'
|
||||
);
|
||||
|
||||
assert.strictEqual( firstImageData.hasCoords(), false, 'No coordinates present means hasCoords returns false.' );
|
||||
assert.strictEqual( secondImageData.hasCoords(), true, 'Coordinates present means hasCoords returns true.' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'parseExtmeta()', function ( assert ) {
|
||||
var stringData = { value: 'foo' },
|
||||
plaintextData = { value: 'fo<b>o</b>' },
|
||||
integerData = { value: 3 },
|
||||
integerStringData = { value: '3' },
|
||||
zeroPrefixedIntegerStringData = { value: '03' },
|
||||
floatData = { value: 1.23 },
|
||||
floatStringData = { value: '1.23' },
|
||||
booleanData = { value: 'yes' },
|
||||
wrongBooleanData = { value: 'blah' },
|
||||
listDataEmpty = { value: '' },
|
||||
listDataSingle = { value: 'foo' },
|
||||
listDataMultiple = { value: 'foo|bar|baz' },
|
||||
missingData;
|
||||
const stringData = { value: 'foo' };
|
||||
const plaintextData = { value: 'fo<b>o</b>' };
|
||||
const integerData = { value: 3 };
|
||||
const integerStringData = { value: '3' };
|
||||
const zeroPrefixedIntegerStringData = { value: '03' };
|
||||
const floatData = { value: 1.23 };
|
||||
const floatStringData = { value: '1.23' };
|
||||
const booleanData = { value: 'yes' };
|
||||
const wrongBooleanData = { value: 'blah' };
|
||||
const listDataEmpty = { value: '' };
|
||||
const listDataSingle = { value: 'foo' };
|
||||
const listDataMultiple = { value: 'foo|bar|baz' };
|
||||
const missingData = undefined;
|
||||
|
||||
assert.strictEqual( ImageModel.parseExtmeta( stringData, 'string' ), 'foo',
|
||||
'Extmeta string parsed correctly.' );
|
||||
|
|
|
@ -21,21 +21,21 @@ const { IwTitle } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.model.IwTitle', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'constructor sense test', function ( assert ) {
|
||||
var namespace = 4,
|
||||
fullPageName = 'User_talk:John_Doe',
|
||||
domain = 'en.wikipedia.org',
|
||||
url = 'https://en.wikipedia.org/wiki/User_talk:John_Doe',
|
||||
title = new IwTitle( namespace, fullPageName, domain, url );
|
||||
const namespace = 4;
|
||||
const fullPageName = 'User_talk:John_Doe';
|
||||
const domain = 'en.wikipedia.org';
|
||||
const url = 'https://en.wikipedia.org/wiki/User_talk:John_Doe';
|
||||
const title = new IwTitle( namespace, fullPageName, domain, url );
|
||||
|
||||
assert.true( title instanceof IwTitle );
|
||||
} );
|
||||
|
||||
QUnit.test( 'getters', function ( assert ) {
|
||||
var namespace = 4,
|
||||
fullPageName = 'User_talk:John_Doe',
|
||||
domain = 'en.wikipedia.org',
|
||||
url = 'https://en.wikipedia.org/wiki/User_talk:John_Doe',
|
||||
title = new IwTitle( namespace, fullPageName, domain, url );
|
||||
const namespace = 4;
|
||||
const fullPageName = 'User_talk:John_Doe';
|
||||
const domain = 'en.wikipedia.org';
|
||||
const url = 'https://en.wikipedia.org/wiki/User_talk:John_Doe';
|
||||
const title = new IwTitle( namespace, fullPageName, domain, url );
|
||||
|
||||
assert.strictEqual( title.getUrl(), url, 'getUrl()' );
|
||||
assert.strictEqual( title.getDomain(), domain, 'getDomain()' );
|
||||
|
|
|
@ -22,13 +22,12 @@ const { License } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.model.License', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'License constructor sense check', function ( assert ) {
|
||||
var license,
|
||||
shortName = 'CC-BY-SA-3.0',
|
||||
internalName = 'cc-by-sa-3.0',
|
||||
longName = 'Creative Commons Attribution--Share-Alike 3.0',
|
||||
url = 'http://creativecommons.org/licenses/by-sa/3.0/';
|
||||
const shortName = 'CC-BY-SA-3.0';
|
||||
const internalName = 'cc-by-sa-3.0';
|
||||
const longName = 'Creative Commons Attribution--Share-Alike 3.0';
|
||||
const url = 'http://creativecommons.org/licenses/by-sa/3.0/';
|
||||
|
||||
license = new License( shortName );
|
||||
let license = new License( shortName );
|
||||
assert.true( license instanceof License, 'License created successfully' );
|
||||
assert.strictEqual( license.shortName, shortName, 'License has correct short name' );
|
||||
assert.strictEqual( license.internalName, undefined, 'License has no internal name' );
|
||||
|
@ -48,13 +47,13 @@ const { License } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getShortName()', function ( assert ) {
|
||||
var existingMessageKey = 'Internal name that does exist',
|
||||
nonExistingMessageKey = 'Internal name that does not exist',
|
||||
license1 = new License( 'Shortname' ),
|
||||
license2 = new License( 'Shortname', nonExistingMessageKey ),
|
||||
license3 = new License( 'Shortname', existingMessageKey ),
|
||||
oldMwMessage = mw.message,
|
||||
oldMwMessagesExists = mw.messages.exists;
|
||||
const existingMessageKey = 'Internal name that does exist';
|
||||
const nonExistingMessageKey = 'Internal name that does not exist';
|
||||
const license1 = new License( 'Shortname' );
|
||||
const license2 = new License( 'Shortname', nonExistingMessageKey );
|
||||
const license3 = new License( 'Shortname', existingMessageKey );
|
||||
const oldMwMessage = mw.message;
|
||||
const oldMwMessagesExists = mw.messages.exists;
|
||||
|
||||
mw.message = function ( name ) {
|
||||
return name === 'multimediaviewer-license-' + existingMessageKey ?
|
||||
|
@ -78,12 +77,11 @@ const { License } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getShortLink()', function ( assert ) {
|
||||
var $html,
|
||||
license1 = new License( 'lorem ipsum' ),
|
||||
license2 = new License( 'lorem ipsum', 'lipsum' ),
|
||||
license3 = new License( 'lorem ipsum', 'lipsum', 'Lorem ipsum dolor sit amet' ),
|
||||
license4 = new License( 'lorem ipsum', 'lipsum', 'Lorem ipsum dolor sit amet',
|
||||
'http://www.lipsum.com/' );
|
||||
const license1 = new License( 'lorem ipsum' );
|
||||
const license2 = new License( 'lorem ipsum', 'lipsum' );
|
||||
const license3 = new License( 'lorem ipsum', 'lipsum', 'Lorem ipsum dolor sit amet' );
|
||||
const license4 = new License( 'lorem ipsum', 'lipsum', 'Lorem ipsum dolor sit amet',
|
||||
'http://www.lipsum.com/' );
|
||||
|
||||
assert.strictEqual( license1.getShortLink(), 'lorem ipsum',
|
||||
'Code for license without link is formatted correctly' );
|
||||
|
@ -92,7 +90,7 @@ const { License } = require( 'mmv' );
|
|||
assert.strictEqual( license3.getShortLink(), 'lorem ipsum',
|
||||
'Code for license without link is formatted correctly' );
|
||||
|
||||
$html = $( license4.getShortLink() );
|
||||
const $html = $( license4.getShortLink() );
|
||||
assert.strictEqual( $html.text(), 'lorem ipsum',
|
||||
'Text for license with link is formatted correctly' );
|
||||
assert.strictEqual( $html.prop( 'href' ), 'http://www.lipsum.com/',
|
||||
|
@ -102,9 +100,7 @@ const { License } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'isCc()', function ( assert ) {
|
||||
var license;
|
||||
|
||||
license = new License( 'CC-BY-SA-2.0', 'cc-by-sa-2.0',
|
||||
let license = new License( 'CC-BY-SA-2.0', 'cc-by-sa-2.0',
|
||||
'Creative Commons Attribution - ShareAlike 2.0',
|
||||
'http://creativecommons.org/licenses/by-sa/2.0/' );
|
||||
assert.strictEqual( license.isCc(), true, 'CC license recognized' );
|
||||
|
@ -118,9 +114,7 @@ const { License } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'isPd()', function ( assert ) {
|
||||
var license;
|
||||
|
||||
license = new License( 'Public Domain', 'pd',
|
||||
let license = new License( 'Public Domain', 'pd',
|
||||
'Public Domain for lack of originality' );
|
||||
assert.strictEqual( license.isPd(), true, 'PD license recognized' );
|
||||
|
||||
|
@ -134,9 +128,7 @@ const { License } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'isFree()', function ( assert ) {
|
||||
var license;
|
||||
|
||||
license = new License( 'CC-BY-SA-2.0', 'cc-by-sa-2.0',
|
||||
let license = new License( 'CC-BY-SA-2.0', 'cc-by-sa-2.0',
|
||||
'Creative Commons Attribution - ShareAlike 2.0',
|
||||
'http://creativecommons.org/licenses/by-sa/2.0/' );
|
||||
assert.strictEqual( license.isFree(), true, 'Licenses default to free' );
|
||||
|
@ -147,9 +139,7 @@ const { License } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'needsAttribution()', function ( assert ) {
|
||||
var license;
|
||||
|
||||
license = new License( 'CC-BY-SA-2.0', 'cc-by-sa-2.0',
|
||||
let license = new License( 'CC-BY-SA-2.0', 'cc-by-sa-2.0',
|
||||
'Creative Commons Attribution - ShareAlike 2.0',
|
||||
'http://creativecommons.org/licenses/by-sa/2.0/' );
|
||||
assert.strictEqual( license.needsAttribution(), true, 'Licenses assumed to need attribution by default' );
|
||||
|
|
|
@ -21,16 +21,16 @@ const { Repo, ForeignApiRepo, ForeignDbRepo } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.model.Repo', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Repo constructor sense check', function ( assert ) {
|
||||
var displayName = 'Wikimedia Commons',
|
||||
favicon = '//commons.wikimedia.org/favicon.ico',
|
||||
apiUrl = '//commons.wikimedia.org/w/api.php',
|
||||
server = '//commons.wikimedia.org',
|
||||
articlePath = '//commons.wikimedia.org/wiki/$1',
|
||||
descBaseUrl = '//commons.wikimedia.org/wiki/File:',
|
||||
localRepo = new Repo( displayName, favicon, true ),
|
||||
foreignApiRepo = new ForeignApiRepo( displayName, favicon,
|
||||
false, apiUrl, server, articlePath ),
|
||||
foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl );
|
||||
const displayName = 'Wikimedia Commons';
|
||||
const favicon = '//commons.wikimedia.org/favicon.ico';
|
||||
const apiUrl = '//commons.wikimedia.org/w/api.php';
|
||||
const server = '//commons.wikimedia.org';
|
||||
const articlePath = '//commons.wikimedia.org/wiki/$1';
|
||||
const descBaseUrl = '//commons.wikimedia.org/wiki/File:';
|
||||
const localRepo = new Repo( displayName, favicon, true );
|
||||
const foreignApiRepo = new ForeignApiRepo( displayName, favicon,
|
||||
false, apiUrl, server, articlePath );
|
||||
const foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl );
|
||||
|
||||
assert.true( localRepo instanceof Repo, 'Local repo creation works' );
|
||||
assert.true( foreignApiRepo instanceof ForeignApiRepo,
|
||||
|
@ -39,20 +39,20 @@ const { Repo, ForeignApiRepo, ForeignDbRepo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getArticlePath()', function ( assert ) {
|
||||
var displayName = 'Wikimedia Commons',
|
||||
favicon = '//commons.wikimedia.org/favicon.ico',
|
||||
apiUrl = '//commons.wikimedia.org/w/api.php',
|
||||
server = '//commons.wikimedia.org',
|
||||
articlePath = '/wiki/$1',
|
||||
descBaseUrl = '//commons.wikimedia.org/wiki/File:',
|
||||
localRepo = new Repo( displayName, favicon, true ),
|
||||
foreignApiRepo = new ForeignApiRepo( displayName, favicon,
|
||||
false, apiUrl, server, articlePath ),
|
||||
foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl ),
|
||||
expectedLocalArticlePath = '/wiki/$1',
|
||||
expectedFullArticlePath = '//commons.wikimedia.org/wiki/$1',
|
||||
oldWgArticlePath = mw.config.get( 'wgArticlePath' ),
|
||||
oldWgServer = mw.config.get( 'wgServer' );
|
||||
const displayName = 'Wikimedia Commons';
|
||||
const favicon = '//commons.wikimedia.org/favicon.ico';
|
||||
const apiUrl = '//commons.wikimedia.org/w/api.php';
|
||||
const server = '//commons.wikimedia.org';
|
||||
const articlePath = '/wiki/$1';
|
||||
const descBaseUrl = '//commons.wikimedia.org/wiki/File:';
|
||||
const localRepo = new Repo( displayName, favicon, true );
|
||||
const foreignApiRepo = new ForeignApiRepo( displayName, favicon,
|
||||
false, apiUrl, server, articlePath );
|
||||
const foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl );
|
||||
const expectedLocalArticlePath = '/wiki/$1';
|
||||
const expectedFullArticlePath = '//commons.wikimedia.org/wiki/$1';
|
||||
const oldWgArticlePath = mw.config.get( 'wgArticlePath' );
|
||||
const oldWgServer = mw.config.get( 'wgServer' );
|
||||
|
||||
mw.config.set( 'wgArticlePath', '/wiki/$1' );
|
||||
mw.config.set( 'wgServer', server );
|
||||
|
@ -71,19 +71,19 @@ const { Repo, ForeignApiRepo, ForeignDbRepo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getSiteLink()', function ( assert ) {
|
||||
var displayName = 'Wikimedia Commons',
|
||||
favicon = '//commons.wikimedia.org/favicon.ico',
|
||||
apiUrl = '//commons.wikimedia.org/w/api.php',
|
||||
server = '//commons.wikimedia.org',
|
||||
articlePath = '/wiki/$1',
|
||||
descBaseUrl = '//commons.wikimedia.org/wiki/File:',
|
||||
localRepo = new Repo( displayName, favicon, true ),
|
||||
foreignApiRepo = new ForeignApiRepo( displayName, favicon,
|
||||
false, apiUrl, server, articlePath ),
|
||||
foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl ),
|
||||
expectedSiteLink = '//commons.wikimedia.org/wiki/',
|
||||
oldWgArticlePath = mw.config.get( 'wgArticlePath' ),
|
||||
oldWgServer = mw.config.get( 'wgServer' );
|
||||
const displayName = 'Wikimedia Commons';
|
||||
const favicon = '//commons.wikimedia.org/favicon.ico';
|
||||
const apiUrl = '//commons.wikimedia.org/w/api.php';
|
||||
const server = '//commons.wikimedia.org';
|
||||
const articlePath = '/wiki/$1';
|
||||
const descBaseUrl = '//commons.wikimedia.org/wiki/File:';
|
||||
const localRepo = new Repo( displayName, favicon, true );
|
||||
const foreignApiRepo = new ForeignApiRepo( displayName, favicon,
|
||||
false, apiUrl, server, articlePath );
|
||||
const foreignDbRepo = new ForeignDbRepo( displayName, favicon, false, descBaseUrl );
|
||||
const expectedSiteLink = '//commons.wikimedia.org/wiki/';
|
||||
const oldWgArticlePath = mw.config.get( 'wgArticlePath' );
|
||||
const oldWgServer = mw.config.get( 'wgServer' );
|
||||
|
||||
mw.config.set( 'wgArticlePath', '/wiki/$1' );
|
||||
mw.config.set( 'wgServer', server );
|
||||
|
|
|
@ -21,13 +21,13 @@ const { TaskQueue } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.model.TaskQueue', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'TaskQueue constructor sense check', function ( assert ) {
|
||||
var taskQueue = new TaskQueue();
|
||||
const taskQueue = new TaskQueue();
|
||||
|
||||
assert.true( taskQueue instanceof TaskQueue, 'TaskQueue created successfully' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Queue length check', function ( assert ) {
|
||||
var taskQueue = new TaskQueue();
|
||||
const taskQueue = new TaskQueue();
|
||||
|
||||
assert.strictEqual( taskQueue.queue.length, 0, 'queue is initially empty' );
|
||||
|
||||
|
@ -37,16 +37,15 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'State check', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
task = $.Deferred(),
|
||||
promise;
|
||||
const taskQueue = new TaskQueue();
|
||||
const task = $.Deferred();
|
||||
|
||||
taskQueue.push( () => task );
|
||||
|
||||
assert.strictEqual( taskQueue.state, TaskQueue.State.NOT_STARTED,
|
||||
'state is initially NOT_STARTED' );
|
||||
|
||||
promise = taskQueue.execute().then( function () {
|
||||
const promise = taskQueue.execute().then( function () {
|
||||
assert.strictEqual( taskQueue.state, TaskQueue.State.FINISHED,
|
||||
'state is FINISHED after execution finished' );
|
||||
} );
|
||||
|
@ -60,8 +59,8 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'State check for cancellation', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
task = $.Deferred();
|
||||
const taskQueue = new TaskQueue();
|
||||
const task = $.Deferred();
|
||||
|
||||
taskQueue.push( () => task );
|
||||
taskQueue.execute();
|
||||
|
@ -72,7 +71,7 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Test executing empty queue', function ( assert ) {
|
||||
var taskQueue = new TaskQueue();
|
||||
const taskQueue = new TaskQueue();
|
||||
|
||||
return taskQueue.execute().done( function () {
|
||||
assert.true( true, 'Queue promise resolved' );
|
||||
|
@ -80,8 +79,8 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Simple execution test', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
called = false;
|
||||
const taskQueue = new TaskQueue();
|
||||
let called = false;
|
||||
|
||||
taskQueue.push( function () {
|
||||
called = true;
|
||||
|
@ -93,15 +92,15 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Task execution order test', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
order = [];
|
||||
const taskQueue = new TaskQueue();
|
||||
const order = [];
|
||||
|
||||
taskQueue.push( function () {
|
||||
order.push( 1 );
|
||||
} );
|
||||
|
||||
taskQueue.push( function () {
|
||||
var deferred = $.Deferred();
|
||||
const deferred = $.Deferred();
|
||||
|
||||
order.push( 2 );
|
||||
|
||||
|
@ -122,8 +121,8 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Double execution test', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
called = 0;
|
||||
const taskQueue = new TaskQueue();
|
||||
let called = 0;
|
||||
|
||||
taskQueue.push( function () {
|
||||
called++;
|
||||
|
@ -137,8 +136,8 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Parallel execution test', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
called = 0;
|
||||
const taskQueue = new TaskQueue();
|
||||
let called = 0;
|
||||
|
||||
taskQueue.push( function () {
|
||||
called++;
|
||||
|
@ -153,7 +152,7 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Test push after execute', function ( assert ) {
|
||||
var taskQueue = new TaskQueue();
|
||||
const taskQueue = new TaskQueue();
|
||||
|
||||
taskQueue.execute();
|
||||
|
||||
|
@ -163,7 +162,7 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Test failed task', function ( assert ) {
|
||||
var taskQueue = new TaskQueue();
|
||||
const taskQueue = new TaskQueue();
|
||||
|
||||
taskQueue.push( function () {
|
||||
return $.Deferred().reject();
|
||||
|
@ -175,12 +174,12 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Test that tasks wait for each other', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
longRunningTaskFinished = false,
|
||||
seenFinished = false;
|
||||
const taskQueue = new TaskQueue();
|
||||
let longRunningTaskFinished = false;
|
||||
let seenFinished = false;
|
||||
|
||||
taskQueue.push( function () {
|
||||
var deferred = $.Deferred();
|
||||
const deferred = $.Deferred();
|
||||
|
||||
setTimeout( function () {
|
||||
longRunningTaskFinished = true;
|
||||
|
@ -200,11 +199,11 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Test cancellation before start', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
triggered = false,
|
||||
verificationTask = function () {
|
||||
triggered = true;
|
||||
};
|
||||
const taskQueue = new TaskQueue();
|
||||
let triggered = false;
|
||||
const verificationTask = function () {
|
||||
triggered = true;
|
||||
};
|
||||
|
||||
taskQueue.push( verificationTask );
|
||||
|
||||
|
@ -222,11 +221,11 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Test cancellation within callback', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
triggered = false,
|
||||
verificationTask = function () {
|
||||
triggered = true;
|
||||
};
|
||||
const taskQueue = new TaskQueue();
|
||||
let triggered = false;
|
||||
const verificationTask = function () {
|
||||
triggered = true;
|
||||
};
|
||||
|
||||
taskQueue.push( function () {
|
||||
taskQueue.cancel();
|
||||
|
@ -245,12 +244,12 @@ const { TaskQueue } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Test cancellation from task', function ( assert ) {
|
||||
var taskQueue = new TaskQueue(),
|
||||
triggered = false,
|
||||
task1 = $.Deferred(),
|
||||
verificationTask = function () {
|
||||
triggered = true;
|
||||
};
|
||||
const taskQueue = new TaskQueue();
|
||||
let triggered = false;
|
||||
const task1 = $.Deferred();
|
||||
const verificationTask = function () {
|
||||
triggered = true;
|
||||
};
|
||||
|
||||
taskQueue.push( function () {
|
||||
return task1;
|
||||
|
|
|
@ -21,10 +21,10 @@ const { Thumbnail, ThumbnailWidth } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.model', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Thumbnail constructor sense check', function ( assert ) {
|
||||
var width = 23,
|
||||
height = 42,
|
||||
url = 'http://example.com/foo.jpg',
|
||||
thumbnail = new Thumbnail( url, width, height );
|
||||
const width = 23;
|
||||
const height = 42;
|
||||
const url = 'http://example.com/foo.jpg';
|
||||
let thumbnail = new Thumbnail( url, width, height );
|
||||
|
||||
assert.strictEqual( thumbnail.url, url, 'Url is set correctly' );
|
||||
assert.strictEqual( thumbnail.width, width, 'Width is set correctly' );
|
||||
|
@ -36,12 +36,12 @@ const { Thumbnail, ThumbnailWidth } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'ThumbnailWidth constructor sense check', function ( assert ) {
|
||||
var cssWidth = 23,
|
||||
cssHeight = 29,
|
||||
screenWidth = 42,
|
||||
realWidth = 123,
|
||||
thumbnailWidth = new ThumbnailWidth(
|
||||
cssWidth, cssHeight, screenWidth, realWidth );
|
||||
const cssWidth = 23;
|
||||
const cssHeight = 29;
|
||||
const screenWidth = 42;
|
||||
const realWidth = 123;
|
||||
let thumbnailWidth = new ThumbnailWidth(
|
||||
cssWidth, cssHeight, screenWidth, realWidth );
|
||||
|
||||
assert.strictEqual( thumbnailWidth.cssWidth, cssWidth, 'Width is set correctly' );
|
||||
assert.strictEqual( thumbnailWidth.cssHeight, cssHeight, 'Height is set correctly' );
|
||||
|
|
|
@ -21,19 +21,19 @@ const { Api } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.provider.Api', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Api constructor sense check', function ( assert ) {
|
||||
var api = { get: function () {} },
|
||||
options = {},
|
||||
apiProvider = new Api( api, options ),
|
||||
ApiProviderWithNoOptions = new Api( api );
|
||||
const api = { get: function () {} };
|
||||
const options = {};
|
||||
const apiProvider = new Api( api, options );
|
||||
const ApiProviderWithNoOptions = new Api( api );
|
||||
|
||||
assert.true( apiProvider instanceof Api );
|
||||
assert.true( ApiProviderWithNoOptions instanceof Api );
|
||||
} );
|
||||
|
||||
QUnit.test( 'apiGetWithMaxAge()', function ( assert ) {
|
||||
var api = {},
|
||||
options = {},
|
||||
apiProvider = new Api( api, options );
|
||||
const api = {};
|
||||
let options = {};
|
||||
let apiProvider = new Api( api, options );
|
||||
|
||||
api.get = this.sandbox.stub();
|
||||
apiProvider.apiGetWithMaxAge( {} );
|
||||
|
@ -60,17 +60,16 @@ const { Api } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getCachedPromise success', function ( assert ) {
|
||||
var api = { get: function () {} },
|
||||
apiProvider = new Api( api ),
|
||||
oldMwLog = mw.log,
|
||||
promiseSource,
|
||||
promiseShouldBeCached = false;
|
||||
const api = { get: function () {} };
|
||||
const apiProvider = new Api( api );
|
||||
const oldMwLog = mw.log;
|
||||
let promiseShouldBeCached = false;
|
||||
|
||||
mw.log = function () {
|
||||
assert.true( false, 'mw.log should not have been called' );
|
||||
};
|
||||
|
||||
promiseSource = function ( result ) {
|
||||
const promiseSource = function ( result ) {
|
||||
return function () {
|
||||
assert.strictEqual( promiseShouldBeCached, false, 'promise was not cached' );
|
||||
return $.Deferred().resolve( result );
|
||||
|
@ -94,17 +93,16 @@ const { Api } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getCachedPromise failure', function ( assert ) {
|
||||
var api = { get: function () {} },
|
||||
apiProvider = new Api( api ),
|
||||
oldMwLog = mw.log,
|
||||
promiseSource,
|
||||
promiseShouldBeCached = false;
|
||||
const api = { get: function () {} };
|
||||
const apiProvider = new Api( api );
|
||||
const oldMwLog = mw.log;
|
||||
let promiseShouldBeCached = false;
|
||||
|
||||
mw.log = function () {
|
||||
assert.true( true, 'mw.log was called' );
|
||||
};
|
||||
|
||||
promiseSource = function ( result ) {
|
||||
const promiseSource = function ( result ) {
|
||||
return function () {
|
||||
assert.strictEqual( promiseShouldBeCached, false, 'promise was not cached' );
|
||||
return $.Deferred().reject( result );
|
||||
|
@ -128,11 +126,10 @@ const { Api } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getErrorMessage', function ( assert ) {
|
||||
var api = { get: function () {} },
|
||||
apiProvider = new Api( api ),
|
||||
errorMessage;
|
||||
const api = { get: function () {} };
|
||||
const apiProvider = new Api( api );
|
||||
|
||||
errorMessage = apiProvider.getErrorMessage( {
|
||||
const errorMessage = apiProvider.getErrorMessage( {
|
||||
servedby: 'mw1194',
|
||||
error: {
|
||||
code: 'unknown_action',
|
||||
|
@ -147,12 +144,11 @@ const { Api } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getQueryField', function ( assert ) {
|
||||
var api = { get: function () {} },
|
||||
apiProvider = new Api( api ),
|
||||
done = assert.async( 3 ),
|
||||
data;
|
||||
const api = { get: function () {} };
|
||||
const apiProvider = new Api( api );
|
||||
const done = assert.async( 3 );
|
||||
|
||||
data = {
|
||||
const data = {
|
||||
query: {
|
||||
imageusage: [
|
||||
{
|
||||
|
@ -180,12 +176,11 @@ const { Api } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getQueryPage', function ( assert ) {
|
||||
var api = { get: function () {} },
|
||||
apiProvider = new Api( api ),
|
||||
done = assert.async( 5 ),
|
||||
data;
|
||||
const api = { get: function () {} };
|
||||
const apiProvider = new Api( api );
|
||||
const done = assert.async( 5 );
|
||||
|
||||
data = {
|
||||
const data = {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
|
|
|
@ -21,64 +21,64 @@ const { FileRepoInfo } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.provider.FileRepoInfo', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'FileRepoInfo constructor sense check', function ( assert ) {
|
||||
var api = { get: function () {} },
|
||||
fileRepoInfoProvider = new FileRepoInfo( api );
|
||||
const api = { get: function () {} };
|
||||
const fileRepoInfoProvider = new FileRepoInfo( api );
|
||||
|
||||
assert.true( fileRepoInfoProvider instanceof FileRepoInfo );
|
||||
} );
|
||||
|
||||
QUnit.test( 'FileRepoInfo get test', function ( assert ) {
|
||||
var apiCallCount = 0,
|
||||
api = { get: function () {
|
||||
apiCallCount++;
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
repos: [
|
||||
{
|
||||
name: 'shared',
|
||||
displayname: 'Wikimedia Commons',
|
||||
rootUrl: '//upload.beta.wmflabs.org/wikipedia/commons',
|
||||
local: false,
|
||||
url: '//upload.beta.wmflabs.org/wikipedia/commons',
|
||||
thumbUrl: '//upload.beta.wmflabs.org/wikipedia/commons/thumb',
|
||||
initialCapital: true,
|
||||
descBaseUrl: '//commons.wikimedia.beta.wmflabs.org/wiki/File:',
|
||||
scriptDirUrl: '//commons.wikimedia.beta.wmflabs.org/w',
|
||||
fetchDescription: true,
|
||||
favicon: 'http://en.wikipedia.org/favicon.ico'
|
||||
},
|
||||
{
|
||||
name: 'wikimediacommons',
|
||||
displayname: 'Wikimedia Commons',
|
||||
rootUrl: '//upload.beta.wmflabs.org/wikipedia/en',
|
||||
local: false,
|
||||
url: '//upload.beta.wmflabs.org/wikipedia/en',
|
||||
thumbUrl: '//upload.beta.wmflabs.org/wikipedia/en/thumb',
|
||||
initialCapital: true,
|
||||
scriptDirUrl: 'http://commons.wikimedia.org/w',
|
||||
fetchDescription: true,
|
||||
descriptionCacheExpiry: 43200,
|
||||
apiurl: 'http://commons.wikimedia.org/w/api.php',
|
||||
articlepath: '/wiki/$1',
|
||||
server: '//commons.wikimedia.org',
|
||||
favicon: '//commons.wikimedia.org/favicon.ico'
|
||||
},
|
||||
{
|
||||
name: 'local',
|
||||
displayname: null,
|
||||
rootUrl: '//upload.beta.wmflabs.org/wikipedia/en',
|
||||
local: true,
|
||||
url: '//upload.beta.wmflabs.org/wikipedia/en',
|
||||
thumbUrl: '//upload.beta.wmflabs.org/wikipedia/en/thumb',
|
||||
initialCapital: true,
|
||||
scriptDirUrl: '/w',
|
||||
favicon: 'http://en.wikipedia.org/favicon.ico'
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} },
|
||||
fileRepoInfoProvider = new FileRepoInfo( api );
|
||||
let apiCallCount = 0;
|
||||
const api = { get: function () {
|
||||
apiCallCount++;
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
repos: [
|
||||
{
|
||||
name: 'shared',
|
||||
displayname: 'Wikimedia Commons',
|
||||
rootUrl: '//upload.beta.wmflabs.org/wikipedia/commons',
|
||||
local: false,
|
||||
url: '//upload.beta.wmflabs.org/wikipedia/commons',
|
||||
thumbUrl: '//upload.beta.wmflabs.org/wikipedia/commons/thumb',
|
||||
initialCapital: true,
|
||||
descBaseUrl: '//commons.wikimedia.beta.wmflabs.org/wiki/File:',
|
||||
scriptDirUrl: '//commons.wikimedia.beta.wmflabs.org/w',
|
||||
fetchDescription: true,
|
||||
favicon: 'http://en.wikipedia.org/favicon.ico'
|
||||
},
|
||||
{
|
||||
name: 'wikimediacommons',
|
||||
displayname: 'Wikimedia Commons',
|
||||
rootUrl: '//upload.beta.wmflabs.org/wikipedia/en',
|
||||
local: false,
|
||||
url: '//upload.beta.wmflabs.org/wikipedia/en',
|
||||
thumbUrl: '//upload.beta.wmflabs.org/wikipedia/en/thumb',
|
||||
initialCapital: true,
|
||||
scriptDirUrl: 'http://commons.wikimedia.org/w',
|
||||
fetchDescription: true,
|
||||
descriptionCacheExpiry: 43200,
|
||||
apiurl: 'http://commons.wikimedia.org/w/api.php',
|
||||
articlepath: '/wiki/$1',
|
||||
server: '//commons.wikimedia.org',
|
||||
favicon: '//commons.wikimedia.org/favicon.ico'
|
||||
},
|
||||
{
|
||||
name: 'local',
|
||||
displayname: null,
|
||||
rootUrl: '//upload.beta.wmflabs.org/wikipedia/en',
|
||||
local: true,
|
||||
url: '//upload.beta.wmflabs.org/wikipedia/en',
|
||||
thumbUrl: '//upload.beta.wmflabs.org/wikipedia/en/thumb',
|
||||
initialCapital: true,
|
||||
scriptDirUrl: '/w',
|
||||
favicon: 'http://en.wikipedia.org/favicon.ico'
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} };
|
||||
const fileRepoInfoProvider = new FileRepoInfo( api );
|
||||
|
||||
return fileRepoInfoProvider.get().then( function ( repos ) {
|
||||
assert.strictEqual( repos.shared.displayName,
|
||||
|
@ -114,11 +114,11 @@ const { FileRepoInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'FileRepoInfo fail test', function ( assert ) {
|
||||
var api = { get: function () {
|
||||
return $.Deferred().resolve( {} );
|
||||
} },
|
||||
done = assert.async(),
|
||||
fileRepoInfoProvider = new FileRepoInfo( api );
|
||||
const api = { get: function () {
|
||||
return $.Deferred().resolve( {} );
|
||||
} };
|
||||
const done = assert.async();
|
||||
const fileRepoInfoProvider = new FileRepoInfo( api );
|
||||
|
||||
fileRepoInfoProvider.get().fail( function () {
|
||||
assert.true( true, 'promise rejected when no data is returned' );
|
||||
|
|
|
@ -21,23 +21,22 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.provider.GuessedThumbnailInfo', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Constructor sense check', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo();
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
assert.true( provider instanceof GuessedThumbnailInfo, 'Constructor call successful' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'get()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' ),
|
||||
sampleUrl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/180px-Copyleft.svg.png',
|
||||
width = 300,
|
||||
originalWidth = 512,
|
||||
originalHeight = 512,
|
||||
resultUrl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png',
|
||||
done = assert.async(),
|
||||
result;
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
const file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const sampleUrl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/180px-Copyleft.svg.png';
|
||||
const width = 300;
|
||||
const originalWidth = 512;
|
||||
const originalHeight = 512;
|
||||
const resultUrl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png';
|
||||
const done = assert.async();
|
||||
|
||||
provider.getUrl = () => resultUrl;
|
||||
result = provider.get( file, sampleUrl, width, originalWidth, originalHeight );
|
||||
let result = provider.get( file, sampleUrl, width, originalWidth, originalHeight );
|
||||
assert.true( typeof result.then === 'function', 'Result is a promise' );
|
||||
assert.strictEqual( result.state(), 'resolved', 'Result is resolved' );
|
||||
result.then( function ( thumbnailInfo ) {
|
||||
|
@ -54,19 +53,15 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getUrl()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Elizabeth_I_George_Gower.jpg' ),
|
||||
originalWidth = 922,
|
||||
originalHeight = 968,
|
||||
width,
|
||||
sampleUrl,
|
||||
expectedUrl,
|
||||
resultUrl;
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
let file = new mw.Title( 'File:Elizabeth_I_George_Gower.jpg' );
|
||||
let originalWidth = 922;
|
||||
let originalHeight = 968;
|
||||
|
||||
sampleUrl = 'http://upload.wikimedia.org/wikipedia/commons/7/78/Elizabeth_I_George_Gower.jpg';
|
||||
width = 1000;
|
||||
expectedUrl = 'http://upload.wikimedia.org/wikipedia/commons/7/78/Elizabeth_I_George_Gower.jpg';
|
||||
resultUrl = provider.getUrl( file, sampleUrl, width, originalWidth, originalHeight );
|
||||
let sampleUrl = 'http://upload.wikimedia.org/wikipedia/commons/7/78/Elizabeth_I_George_Gower.jpg';
|
||||
let width = 1000;
|
||||
let expectedUrl = 'http://upload.wikimedia.org/wikipedia/commons/7/78/Elizabeth_I_George_Gower.jpg';
|
||||
let resultUrl = provider.getUrl( file, sampleUrl, width, originalWidth, originalHeight );
|
||||
assert.strictEqual( resultUrl, expectedUrl, 'Simple case - full image, needs no resize' );
|
||||
|
||||
sampleUrl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/7/78/Elizabeth_I_George_Gower.jpg/180px-Elizabeth_I_George_Gower.jpg';
|
||||
|
@ -107,8 +102,8 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'needsOriginal()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
let file = new mw.Title( 'File:Copyleft.svg' );
|
||||
|
||||
assert.strictEqual( provider.needsOriginal( file, 100, 1000 ), false, 'Thumbnail of an SVG smaller than the original size doesn\'t need original' );
|
||||
assert.strictEqual( provider.needsOriginal( file, 1000, 1000 ), false, 'Thumbnail of an SVG equal to the original size doesn\'t need original' );
|
||||
|
@ -122,8 +117,8 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'isFullSizeUrl()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
const file = new mw.Title( 'File:Copyleft.svg' );
|
||||
|
||||
assert.strictEqual( provider.isFullSizeUrl( 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png', file ),
|
||||
false,
|
||||
|
@ -134,8 +129,8 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'obscureFilename()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
let file = new mw.Title( 'File:Copyleft.svg' );
|
||||
|
||||
assert.strictEqual( provider.obscureFilename( 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png', file ),
|
||||
'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/<filename>/300px-<filename>.png', 'Filename correctly obscured' );
|
||||
|
@ -147,8 +142,8 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'restoreFilename()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
const file = new mw.Title( 'File:Copyleft.svg' );
|
||||
|
||||
assert.strictEqual( provider.restoreFilename( 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/<filename>/300px-<filename>.png', file ),
|
||||
'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png', 'Filename correctly restored' );
|
||||
|
@ -156,8 +151,8 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'canHaveLargerThumbnailThanOriginal()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
let file = new mw.Title( 'File:Copyleft.svg' );
|
||||
|
||||
assert.strictEqual( provider.canHaveLargerThumbnailThanOriginal( file ), true, 'SVG can have a larger thumbnail than the original' );
|
||||
|
||||
|
@ -183,8 +178,8 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'canBeDisplayedInBrowser()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
let file = new mw.Title( 'File:Copyleft.svg' );
|
||||
|
||||
assert.strictEqual( provider.canBeDisplayedInBrowser( file ), false, 'SVG can\'t be displayed as-is in the browser' );
|
||||
|
||||
|
@ -210,8 +205,8 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'guessWidth()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
let file = new mw.Title( 'File:Copyleft.svg' );
|
||||
|
||||
assert.strictEqual( provider.guessWidth( file, 100, 1000 ), 100, 'Width correctly guessed for SVG thumbnail smaller than the original' );
|
||||
assert.strictEqual( provider.guessWidth( file, 2000, 1000 ), 2000, 'Width correctly guessed for SVG thumbnail bigger than the original' );
|
||||
|
@ -223,8 +218,8 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'guessHeight()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
let file = new mw.Title( 'File:Copyleft.svg' );
|
||||
|
||||
assert.strictEqual( provider.guessHeight( file, 100, 1000, 500 ), 50, 'Height correctly guessed for SVG thumbnail smaller than the original' );
|
||||
assert.strictEqual( provider.guessHeight( file, 2000, 1000, 500 ), 1000, 'Height correctly guessed for SVG thumbnail bigger than the original' );
|
||||
|
@ -236,8 +231,8 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'replaceSize()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' );
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
let file = new mw.Title( 'File:Copyleft.svg' );
|
||||
|
||||
assert.strictEqual( provider.replaceSize( file, 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png', 220 ),
|
||||
'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/220px-Copyleft.svg.png', 'Incorrect size correctly replaced' );
|
||||
|
@ -256,13 +251,12 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'guessFullUrl()', function ( assert ) {
|
||||
var provider = new GuessedThumbnailInfo(),
|
||||
file = new mw.Title( 'File:Copyleft.svg' ),
|
||||
fullUrl = 'http://upload.wikimedia.org/wikipedia/commons/8/8b/Copyleft.svg',
|
||||
sampleUrl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png',
|
||||
result;
|
||||
const provider = new GuessedThumbnailInfo();
|
||||
let file = new mw.Title( 'File:Copyleft.svg' );
|
||||
let fullUrl = 'http://upload.wikimedia.org/wikipedia/commons/8/8b/Copyleft.svg';
|
||||
let sampleUrl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png';
|
||||
|
||||
result = provider.guessFullUrl( file, sampleUrl );
|
||||
let result = provider.guessFullUrl( file, sampleUrl );
|
||||
|
||||
assert.strictEqual( result, fullUrl, 'guessFullUrl returns correct full URL for SVG' );
|
||||
|
||||
|
|
|
@ -21,16 +21,16 @@ const { ImageProvider } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.provider.Image', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Image constructor sense check', function ( assert ) {
|
||||
var imageProvider = new ImageProvider();
|
||||
const imageProvider = new ImageProvider();
|
||||
|
||||
assert.true( imageProvider instanceof ImageProvider );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Image load success', function ( assert ) {
|
||||
var url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0' +
|
||||
const url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0' +
|
||||
'iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH' +
|
||||
'8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC',
|
||||
imageProvider = new ImageProvider();
|
||||
'8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC';
|
||||
const imageProvider = new ImageProvider();
|
||||
|
||||
imageProvider.imagePreloadingSupported = () => false;
|
||||
|
||||
|
@ -42,12 +42,12 @@ const { ImageProvider } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Image caching', function ( assert ) {
|
||||
var url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0' +
|
||||
const url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0' +
|
||||
'iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH' +
|
||||
'8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC',
|
||||
url2 = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
|
||||
result,
|
||||
imageProvider = new ImageProvider();
|
||||
'8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC';
|
||||
const url2 = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
||||
let result;
|
||||
const imageProvider = new ImageProvider();
|
||||
|
||||
imageProvider.imagePreloadingSupported = () => false;
|
||||
|
||||
|
@ -72,10 +72,10 @@ const { ImageProvider } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Image load fail', function ( assert ) {
|
||||
var imageProvider = new ImageProvider(),
|
||||
oldMwLog = mw.log,
|
||||
done = assert.async(),
|
||||
mwLogCalled = false;
|
||||
const imageProvider = new ImageProvider();
|
||||
const oldMwLog = mw.log;
|
||||
const done = assert.async();
|
||||
let mwLogCalled = false;
|
||||
|
||||
imageProvider.imagePreloadingSupported = () => false;
|
||||
mw.log = function () {
|
||||
|
@ -91,9 +91,11 @@ const { ImageProvider } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Image load with preloading supported', function ( assert ) {
|
||||
var url = mw.config.get( 'wgExtensionAssetsPath' ) + '/MultimediaViewer/resources/mmv.bootstrap/img/expand.svg',
|
||||
imageProvider = new ImageProvider(),
|
||||
endsWith = function ( a, b ) { return a.indexOf( b ) === a.length - b.length; };
|
||||
const url = mw.config.get( 'wgExtensionAssetsPath' ) + '/MultimediaViewer/resources/mmv.bootstrap/img/expand.svg';
|
||||
const imageProvider = new ImageProvider();
|
||||
const endsWith = function ( a, b ) {
|
||||
return a.indexOf( b ) === a.length - b.length;
|
||||
};
|
||||
|
||||
imageProvider.imagePreloadingSupported = () => true;
|
||||
imageProvider.performance = {
|
||||
|
@ -107,9 +109,9 @@ const { ImageProvider } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Failed image load with preloading supported', function ( assert ) {
|
||||
var url = 'nosuchimage.png',
|
||||
imageProvider = new ImageProvider(),
|
||||
done = assert.async();
|
||||
const url = 'nosuchimage.png';
|
||||
const imageProvider = new ImageProvider();
|
||||
const done = assert.async();
|
||||
|
||||
imageProvider.imagePreloadingSupported = () => true;
|
||||
imageProvider.performance = {
|
||||
|
@ -123,8 +125,8 @@ const { ImageProvider } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'imageQueryParameter', function ( assert ) {
|
||||
var imageProvider = new ImageProvider( 'foo' ),
|
||||
done = assert.async();
|
||||
const imageProvider = new ImageProvider( 'foo' );
|
||||
const done = assert.async();
|
||||
|
||||
imageProvider.imagePreloadingSupported = () => false;
|
||||
imageProvider.rawGet = function ( url ) {
|
||||
|
|
|
@ -78,127 +78,127 @@ const { ImageInfo } = require( 'mmv' );
|
|||
} ) );
|
||||
|
||||
QUnit.test( 'ImageInfo constructor sense check', function ( assert ) {
|
||||
var api = { get: function () {} },
|
||||
imageInfoProvider = new ImageInfo( api );
|
||||
const api = { get: function () {} };
|
||||
const imageInfoProvider = new ImageInfo( api );
|
||||
|
||||
assert.true( imageInfoProvider instanceof ImageInfo );
|
||||
} );
|
||||
|
||||
QUnit.test( 'ImageInfo get test', function ( assert ) {
|
||||
var apiCallCount = 0,
|
||||
api = { get: function () {
|
||||
apiCallCount++;
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
ns: 6,
|
||||
title: 'File:Stuff.jpg',
|
||||
missing: true,
|
||||
imagerepository: 'shared',
|
||||
imageinfo: [
|
||||
{
|
||||
timestamp: '2013-08-25T14:41:02Z',
|
||||
userid: '3053121',
|
||||
size: 346684,
|
||||
width: 720,
|
||||
height: 1412,
|
||||
comment: 'User created page with UploadWizard',
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/1/19/Stuff.jpg',
|
||||
descriptionurl: 'https://commons.wikimedia.org/wiki/File:Stuff.jpg',
|
||||
sha1: 'a1ba23d471f4dad208b71c143e2e105a0e3032db',
|
||||
metadata: [],
|
||||
extmetadata: {
|
||||
ObjectName: {
|
||||
value: 'Some stuff',
|
||||
source: 'commons-templates'
|
||||
},
|
||||
License: {
|
||||
value: 'cc0',
|
||||
source: 'commons-templates',
|
||||
hidden: ''
|
||||
},
|
||||
LicenseShortName: {
|
||||
value: 'CC0',
|
||||
source: 'commons-templates'
|
||||
},
|
||||
UsageTerms: {
|
||||
value: 'Creative Commons Public Domain Dedication',
|
||||
source: 'commons-templates'
|
||||
},
|
||||
LicenseUrl: {
|
||||
value: 'http://creativecommons.org/publicdomain/zero/1.0/',
|
||||
source: 'commons-templates'
|
||||
},
|
||||
GPSLatitude: {
|
||||
value: '90.000000',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
GPSLongitude: {
|
||||
value: ' 180.000000',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
ImageDescription: {
|
||||
value: 'Wikis stuff',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
DateTimeOriginal: {
|
||||
value: '<time class="dtstart" datetime="2009-02-18">18 February 2009</time>\u00a0(according to <a href="//en.wikipedia.org/wiki/Exchangeable_image_file_format" class="extiw" title="en:Exchangeable image file format">EXIF</a> data)',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
DateTime: {
|
||||
value: '2013-08-25T14:41:02Z',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
Credit: {
|
||||
value: 'Wikipedia',
|
||||
source: 'commons-desc-page',
|
||||
hidden: ''
|
||||
},
|
||||
Artist: {
|
||||
value: 'John Smith',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
AuthorCount: {
|
||||
value: '2',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
Attribution: {
|
||||
value: 'By John Smith',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
Permission: {
|
||||
value: 'Do not use. Ever.',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
AttributionRequired: {
|
||||
value: 'no',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
NonFree: {
|
||||
value: 'yes',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
Restrictions: {
|
||||
value: 'trademarked|insignia',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
DeletionReason: {
|
||||
value: 'copyvio',
|
||||
source: 'commons-desc-page'
|
||||
}
|
||||
let apiCallCount = 0;
|
||||
const api = { get: function () {
|
||||
apiCallCount++;
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
ns: 6,
|
||||
title: 'File:Stuff.jpg',
|
||||
missing: true,
|
||||
imagerepository: 'shared',
|
||||
imageinfo: [
|
||||
{
|
||||
timestamp: '2013-08-25T14:41:02Z',
|
||||
userid: '3053121',
|
||||
size: 346684,
|
||||
width: 720,
|
||||
height: 1412,
|
||||
comment: 'User created page with UploadWizard',
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/1/19/Stuff.jpg',
|
||||
descriptionurl: 'https://commons.wikimedia.org/wiki/File:Stuff.jpg',
|
||||
sha1: 'a1ba23d471f4dad208b71c143e2e105a0e3032db',
|
||||
metadata: [],
|
||||
extmetadata: {
|
||||
ObjectName: {
|
||||
value: 'Some stuff',
|
||||
source: 'commons-templates'
|
||||
},
|
||||
mime: 'image/jpeg',
|
||||
mediatype: 'BITMAP'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} },
|
||||
file = new mw.Title( 'File:Stuff.jpg' ),
|
||||
imageInfoProvider = new ImageInfo( api );
|
||||
License: {
|
||||
value: 'cc0',
|
||||
source: 'commons-templates',
|
||||
hidden: ''
|
||||
},
|
||||
LicenseShortName: {
|
||||
value: 'CC0',
|
||||
source: 'commons-templates'
|
||||
},
|
||||
UsageTerms: {
|
||||
value: 'Creative Commons Public Domain Dedication',
|
||||
source: 'commons-templates'
|
||||
},
|
||||
LicenseUrl: {
|
||||
value: 'http://creativecommons.org/publicdomain/zero/1.0/',
|
||||
source: 'commons-templates'
|
||||
},
|
||||
GPSLatitude: {
|
||||
value: '90.000000',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
GPSLongitude: {
|
||||
value: ' 180.000000',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
ImageDescription: {
|
||||
value: 'Wikis stuff',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
DateTimeOriginal: {
|
||||
value: '<time class="dtstart" datetime="2009-02-18">18 February 2009</time>\u00a0(according to <a href="//en.wikipedia.org/wiki/Exchangeable_image_file_format" class="extiw" title="en:Exchangeable image file format">EXIF</a> data)',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
DateTime: {
|
||||
value: '2013-08-25T14:41:02Z',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
Credit: {
|
||||
value: 'Wikipedia',
|
||||
source: 'commons-desc-page',
|
||||
hidden: ''
|
||||
},
|
||||
Artist: {
|
||||
value: 'John Smith',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
AuthorCount: {
|
||||
value: '2',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
Attribution: {
|
||||
value: 'By John Smith',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
Permission: {
|
||||
value: 'Do not use. Ever.',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
AttributionRequired: {
|
||||
value: 'no',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
NonFree: {
|
||||
value: 'yes',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
Restrictions: {
|
||||
value: 'trademarked|insignia',
|
||||
source: 'commons-desc-page'
|
||||
},
|
||||
DeletionReason: {
|
||||
value: 'copyvio',
|
||||
source: 'commons-desc-page'
|
||||
}
|
||||
},
|
||||
mime: 'image/jpeg',
|
||||
mediatype: 'BITMAP'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} };
|
||||
const file = new mw.Title( 'File:Stuff.jpg' );
|
||||
const imageInfoProvider = new ImageInfo( api );
|
||||
|
||||
return imageInfoProvider.get( file ).then( function ( image ) {
|
||||
assert.strictEqual( image.title.getPrefixedDb(), 'File:Stuff.jpg', 'title is set correctly' );
|
||||
|
@ -238,12 +238,12 @@ const { ImageInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'ImageInfo fail test', function ( assert ) {
|
||||
var api = { get: function () {
|
||||
return $.Deferred().resolve( {} );
|
||||
} },
|
||||
file = new mw.Title( 'File:Stuff.jpg' ),
|
||||
done = assert.async(),
|
||||
imageInfoProvider = new ImageInfo( api );
|
||||
const api = { get: function () {
|
||||
return $.Deferred().resolve( {} );
|
||||
} };
|
||||
const file = new mw.Title( 'File:Stuff.jpg' );
|
||||
const done = assert.async();
|
||||
const imageInfoProvider = new ImageInfo( api );
|
||||
|
||||
imageInfoProvider.get( file ).fail( function () {
|
||||
assert.true( true, 'promise rejected when no data is returned' );
|
||||
|
@ -252,20 +252,20 @@ const { ImageInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'ImageInfo fail test 2', function ( assert ) {
|
||||
var api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg'
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} },
|
||||
file = new mw.Title( 'File:Stuff.jpg' ),
|
||||
done = assert.async(),
|
||||
imageInfoProvider = new ImageInfo( api );
|
||||
const api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg'
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} };
|
||||
const file = new mw.Title( 'File:Stuff.jpg' );
|
||||
const done = assert.async();
|
||||
const imageInfoProvider = new ImageInfo( api );
|
||||
|
||||
imageInfoProvider.get( file ).fail( function () {
|
||||
assert.true( true, 'promise rejected when imageinfo is missing' );
|
||||
|
@ -274,22 +274,22 @@ const { ImageInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'ImageInfo missing page test', function ( assert ) {
|
||||
var api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg',
|
||||
missing: true,
|
||||
imagerepository: ''
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} },
|
||||
file = new mw.Title( 'File:Stuff.jpg' ),
|
||||
done = assert.async(),
|
||||
imageInfoProvider = new ImageInfo( api );
|
||||
const api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg',
|
||||
missing: true,
|
||||
imagerepository: ''
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} };
|
||||
const file = new mw.Title( 'File:Stuff.jpg' );
|
||||
const done = assert.async();
|
||||
const imageInfoProvider = new ImageInfo( api );
|
||||
|
||||
imageInfoProvider.get( file ).fail( function ( errorMessage ) {
|
||||
assert.strictEqual( errorMessage, 'file does not exist: File:Stuff.jpg',
|
||||
|
|
|
@ -78,40 +78,40 @@ const { ThumbnailInfo } = require( 'mmv' );
|
|||
} ) );
|
||||
|
||||
QUnit.test( 'ThumbnailInfo constructor sense check', function ( assert ) {
|
||||
var api = { get: function () {} },
|
||||
thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
const api = { get: function () {} };
|
||||
const thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
|
||||
assert.true( thumbnailInfoProvider instanceof ThumbnailInfo );
|
||||
} );
|
||||
|
||||
QUnit.test( 'ThumbnailInfo get test', function ( assert ) {
|
||||
var apiCallCount = 0,
|
||||
api = { get: function () {
|
||||
apiCallCount++;
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
ns: 6,
|
||||
title: 'File:Stuff.jpg',
|
||||
missing: true,
|
||||
imagerepository: 'shared',
|
||||
imageinfo: [
|
||||
{
|
||||
thumburl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Stuff.jpg/51px-Stuff.jpg',
|
||||
thumbwidth: 95,
|
||||
thumbheight: 200,
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/1/19/Stuff.jpg',
|
||||
descriptionurl: 'https://commons.wikimedia.org/wiki/File:Stuff.jpg'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} },
|
||||
file = new mw.Title( 'File:Stuff.jpg' ),
|
||||
thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
let apiCallCount = 0;
|
||||
const api = { get: function () {
|
||||
apiCallCount++;
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
ns: 6,
|
||||
title: 'File:Stuff.jpg',
|
||||
missing: true,
|
||||
imagerepository: 'shared',
|
||||
imageinfo: [
|
||||
{
|
||||
thumburl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Stuff.jpg/51px-Stuff.jpg',
|
||||
thumbwidth: 95,
|
||||
thumbheight: 200,
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/1/19/Stuff.jpg',
|
||||
descriptionurl: 'https://commons.wikimedia.org/wiki/File:Stuff.jpg'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} };
|
||||
const file = new mw.Title( 'File:Stuff.jpg' );
|
||||
const thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
|
||||
return thumbnailInfoProvider.get( file, 100 ).then( function ( thumbnail ) {
|
||||
assert.strictEqual( thumbnail.url,
|
||||
|
@ -137,12 +137,12 @@ const { ThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'ThumbnailInfo fail test', function ( assert ) {
|
||||
var api = { get: function () {
|
||||
return $.Deferred().resolve( {} );
|
||||
} },
|
||||
file = new mw.Title( 'File:Stuff.jpg' ),
|
||||
done = assert.async(),
|
||||
thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
const api = { get: function () {
|
||||
return $.Deferred().resolve( {} );
|
||||
} };
|
||||
const file = new mw.Title( 'File:Stuff.jpg' );
|
||||
const done = assert.async();
|
||||
const thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
|
||||
thumbnailInfoProvider.get( file, 100 ).fail( function () {
|
||||
assert.true( true, 'promise rejected when no data is returned' );
|
||||
|
@ -151,20 +151,20 @@ const { ThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'ThumbnailInfo fail test 2', function ( assert ) {
|
||||
var api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg'
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} },
|
||||
file = new mw.Title( 'File:Stuff.jpg' ),
|
||||
done = assert.async(),
|
||||
thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
const api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg'
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} };
|
||||
const file = new mw.Title( 'File:Stuff.jpg' );
|
||||
const done = assert.async();
|
||||
const thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
|
||||
thumbnailInfoProvider.get( file, 100 ).fail( function () {
|
||||
assert.true( true, 'promise rejected when imageinfo is missing' );
|
||||
|
@ -173,22 +173,22 @@ const { ThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'ThumbnailInfo missing page test', function ( assert ) {
|
||||
var api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg',
|
||||
missing: true,
|
||||
imagerepository: ''
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} },
|
||||
file = new mw.Title( 'File:Stuff.jpg' ),
|
||||
done = assert.async(),
|
||||
thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
const api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg',
|
||||
missing: true,
|
||||
imagerepository: ''
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} };
|
||||
const file = new mw.Title( 'File:Stuff.jpg' );
|
||||
const done = assert.async();
|
||||
const thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
|
||||
thumbnailInfoProvider.get( file ).fail( function ( errorMessage ) {
|
||||
assert.strictEqual( errorMessage, 'file does not exist: File:Stuff.jpg',
|
||||
|
@ -198,23 +198,23 @@ const { ThumbnailInfo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'ThumbnailInfo fail test 3', function ( assert ) {
|
||||
var api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg',
|
||||
imageinfo: [
|
||||
{}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} },
|
||||
file = new mw.Title( 'File:Stuff.jpg' ),
|
||||
done = assert.async(),
|
||||
thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
const api = { get: function () {
|
||||
return $.Deferred().resolve( {
|
||||
query: {
|
||||
pages: [
|
||||
{
|
||||
title: 'File:Stuff.jpg',
|
||||
imageinfo: [
|
||||
{}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
} );
|
||||
} };
|
||||
const file = new mw.Title( 'File:Stuff.jpg' );
|
||||
const done = assert.async();
|
||||
const thumbnailInfoProvider = new ThumbnailInfo( api );
|
||||
|
||||
thumbnailInfoProvider.get( file, 100 ).fail( function () {
|
||||
assert.true( true, 'promise rejected when thumbnail info is missing' );
|
||||
|
|
|
@ -21,8 +21,8 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.ui.Canvas', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Constructor sense check', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
canvas = new Canvas( $qf, $qf, $qf );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const canvas = new Canvas( $qf, $qf, $qf );
|
||||
|
||||
assert.strictEqual( canvas.$imageDiv.length, 1, 'Image container is created.' );
|
||||
assert.strictEqual( canvas.$imageWrapper, $qf, '$imageWrapper is set correctly.' );
|
||||
|
@ -30,11 +30,11 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'empty() and set()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
canvas = new Canvas( $qf ),
|
||||
image = new Image(),
|
||||
$imageElem = $( image ),
|
||||
imageRawMetadata = new LightboxImage( 'foo.png' );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const canvas = new Canvas( $qf );
|
||||
const image = new Image();
|
||||
const $imageElem = $( image );
|
||||
const imageRawMetadata = new LightboxImage( 'foo.png' );
|
||||
|
||||
canvas.empty();
|
||||
|
||||
|
@ -55,23 +55,21 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'setImageAndMaxDimensions()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
$mainWrapper = $( '<div>' ).appendTo( $qf ),
|
||||
$innerWrapper = $( '<div>' ).appendTo( $mainWrapper ),
|
||||
$imageWrapper = $( '<div>' ).appendTo( $innerWrapper ),
|
||||
canvas = new Canvas( $innerWrapper, $imageWrapper, $mainWrapper ),
|
||||
imageRawMetadata = new LightboxImage( 'foo.png' ),
|
||||
image = new Image(),
|
||||
$imageElem = $( image ),
|
||||
image2 = new Image(),
|
||||
thumbnailWidth = 10,
|
||||
screenWidth = 100,
|
||||
$currentImage,
|
||||
originalWidth;
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const $mainWrapper = $( '<div>' ).appendTo( $qf );
|
||||
const $innerWrapper = $( '<div>' ).appendTo( $mainWrapper );
|
||||
const $imageWrapper = $( '<div>' ).appendTo( $innerWrapper );
|
||||
const canvas = new Canvas( $innerWrapper, $imageWrapper, $mainWrapper );
|
||||
const imageRawMetadata = new LightboxImage( 'foo.png' );
|
||||
const image = new Image();
|
||||
const $imageElem = $( image );
|
||||
const image2 = new Image();
|
||||
let thumbnailWidth = 10;
|
||||
const screenWidth = 100;
|
||||
|
||||
// Need to call set() before using setImageAndMaxDimensions()
|
||||
canvas.set( imageRawMetadata, $imageElem );
|
||||
originalWidth = image.width;
|
||||
const originalWidth = image.width;
|
||||
|
||||
// Call with the same image
|
||||
canvas.setImageAndMaxDimensions(
|
||||
|
@ -83,7 +81,7 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
assert.strictEqual( image.width, originalWidth, 'Image width was not modified.' );
|
||||
assert.strictEqual( canvas.$image, $imageElem, 'Image element still set correctly.' );
|
||||
|
||||
$currentImage = canvas.$image;
|
||||
const $currentImage = canvas.$image;
|
||||
|
||||
// Call with a new image bigger than screen size
|
||||
thumbnailWidth = 150;
|
||||
|
@ -98,11 +96,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'maybeDisplayPlaceholder: Constrained area for SVG files', function ( assert ) {
|
||||
var $image,
|
||||
blurredThumbnailShown,
|
||||
$qf = $( '#qunit-fixture' ),
|
||||
imageRawMetadata = new LightboxImage( 'foo.svg' ),
|
||||
canvas = new Canvas( $qf );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const imageRawMetadata = new LightboxImage( 'foo.svg' );
|
||||
const canvas = new Canvas( $qf );
|
||||
|
||||
imageRawMetadata.filePageTitle = {
|
||||
getExtension: function () { return 'svg'; }
|
||||
|
@ -113,9 +109,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
assert.true( false, 'Placeholder is not shown' );
|
||||
};
|
||||
|
||||
$image = $( '<img>' ).width( 10 ).height( 5 );
|
||||
const $image = $( '<img>' ).width( 10 ).height( 5 );
|
||||
|
||||
blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
const blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
{ width: 200, height: 100 },
|
||||
$image,
|
||||
{ cssWidth: 300, cssHeight: 150 }
|
||||
|
@ -128,11 +124,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'maybeDisplayPlaceholder: placeholder big enough that it doesn\'t need blurring, actual image bigger than the lightbox', function ( assert ) {
|
||||
var $image,
|
||||
blurredThumbnailShown,
|
||||
$qf = $( '#qunit-fixture' ),
|
||||
imageRawMetadata = new LightboxImage( 'foo.png' ),
|
||||
canvas = new Canvas( $qf );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const imageRawMetadata = new LightboxImage( 'foo.png' );
|
||||
const canvas = new Canvas( $qf );
|
||||
|
||||
imageRawMetadata.filePageTitle = {
|
||||
getExtension: function () { return 'png'; }
|
||||
|
@ -143,9 +137,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
assert.true( true, 'Placeholder shown' );
|
||||
};
|
||||
|
||||
$image = $( '<img>' ).width( 200 ).height( 100 );
|
||||
const $image = $( '<img>' ).width( 200 ).height( 100 );
|
||||
|
||||
blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
const blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
{ width: 1000, height: 500 },
|
||||
$image,
|
||||
{ cssWidth: 300, cssHeight: 150 }
|
||||
|
@ -158,11 +152,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'maybeDisplayPlaceholder: big-enough placeholder that needs blurring, actual image bigger than the lightbox', function ( assert ) {
|
||||
var $image,
|
||||
blurredThumbnailShown,
|
||||
$qf = $( '#qunit-fixture' ),
|
||||
imageRawMetadata = new LightboxImage( 'foo.png' ),
|
||||
canvas = new Canvas( $qf );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const imageRawMetadata = new LightboxImage( 'foo.png' );
|
||||
const canvas = new Canvas( $qf );
|
||||
|
||||
imageRawMetadata.filePageTitle = {
|
||||
getExtension: function () { return 'png'; }
|
||||
|
@ -173,9 +165,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
assert.true( true, 'Placeholder shown' );
|
||||
};
|
||||
|
||||
$image = $( '<img>' ).width( 100 ).height( 50 );
|
||||
const $image = $( '<img>' ).width( 100 ).height( 50 );
|
||||
|
||||
blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
const blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
{ width: 1000, height: 500 },
|
||||
$image,
|
||||
{ cssWidth: 300, cssHeight: 150 }
|
||||
|
@ -188,11 +180,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'maybeDisplayPlaceholder: big-enough placeholder that needs blurring, actual image smaller than the lightbox', function ( assert ) {
|
||||
var $image,
|
||||
blurredThumbnailShown,
|
||||
$qf = $( '#qunit-fixture' ),
|
||||
imageRawMetadata = new LightboxImage( 'foo.png' ),
|
||||
canvas = new Canvas( $qf );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const imageRawMetadata = new LightboxImage( 'foo.png' );
|
||||
const canvas = new Canvas( $qf );
|
||||
|
||||
imageRawMetadata.filePageTitle = {
|
||||
getExtension: function () { return 'png'; }
|
||||
|
@ -203,9 +193,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
assert.true( true, 'Placeholder shown' );
|
||||
};
|
||||
|
||||
$image = $( '<img>' ).width( 100 ).height( 50 );
|
||||
const $image = $( '<img>' ).width( 100 ).height( 50 );
|
||||
|
||||
blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
const blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
{ width: 1000, height: 500 },
|
||||
$image,
|
||||
{ cssWidth: 1200, cssHeight: 600 }
|
||||
|
@ -218,11 +208,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'maybeDisplayPlaceholder: placeholder too small to be displayed, actual image bigger than the lightbox', function ( assert ) {
|
||||
var $image,
|
||||
blurredThumbnailShown,
|
||||
$qf = $( '#qunit-fixture' ),
|
||||
imageRawMetadata = new LightboxImage( 'foo.png' ),
|
||||
canvas = new Canvas( $qf );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const imageRawMetadata = new LightboxImage( 'foo.png' );
|
||||
const canvas = new Canvas( $qf );
|
||||
|
||||
imageRawMetadata.filePageTitle = {
|
||||
getExtension: function () { return 'png'; }
|
||||
|
@ -233,9 +221,9 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
assert.true( false, 'Placeholder shown when it should not' );
|
||||
};
|
||||
|
||||
$image = $( '<img>' ).width( 10 ).height( 5 );
|
||||
const $image = $( '<img>' ).width( 10 ).height( 5 );
|
||||
|
||||
blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
const blurredThumbnailShown = canvas.maybeDisplayPlaceholder(
|
||||
{ width: 1000, height: 500 },
|
||||
$image,
|
||||
{ cssWidth: 300, cssHeight: 150 }
|
||||
|
@ -248,16 +236,14 @@ const { Canvas, LightboxImage } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'unblurWithAnimation', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
canvas = new Canvas( $qf ),
|
||||
oldAnimate = $.fn.animate;
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const canvas = new Canvas( $qf );
|
||||
const oldAnimate = $.fn.animate;
|
||||
|
||||
$.fn.animate = function ( target, options ) {
|
||||
var key;
|
||||
|
||||
if ( options ) {
|
||||
if ( options.step ) {
|
||||
for ( key in target ) {
|
||||
for ( const key in target ) {
|
||||
options.step.call( this, target[ key ] /* , tween object */ );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ const { CanvasButtons } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.ui.CanvasButtons', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Prev/Next', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
buttons = new CanvasButtons( $qf, $( '<div>' ), $( '<div>' ) );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const buttons = new CanvasButtons( $qf, $( '<div>' ), $( '<div>' ) );
|
||||
|
||||
buttons.on( 'next', function () {
|
||||
assert.true( true, 'Switched to next image' );
|
||||
|
|
|
@ -4,7 +4,7 @@ const { Description } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.ui.description', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Sense test, object creation and UI construction', function ( assert ) {
|
||||
var description = new Description( $( '#qunit-fixture' ) );
|
||||
const description = new Description( $( '#qunit-fixture' ) );
|
||||
|
||||
assert.true( description instanceof Description, 'Image description UI element is created' );
|
||||
assert.strictEqual( description.$imageDescDiv.length, 1, 'Image description div is created' );
|
||||
|
@ -12,7 +12,7 @@ const { Description } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Setting data in different combinations works well', function ( assert ) {
|
||||
var description = new Description( $( '#qunit-fixture' ) );
|
||||
const description = new Description( $( '#qunit-fixture' ) );
|
||||
|
||||
description.set( null, null );
|
||||
assert.strictEqual( description.$imageDescDiv.hasClass( 'empty' ), true,
|
||||
|
@ -34,7 +34,7 @@ const { Description } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Emptying data works as expected', function ( assert ) {
|
||||
var description = new Description( $( '#qunit-fixture' ) );
|
||||
const description = new Description( $( '#qunit-fixture' ) );
|
||||
|
||||
description.set( 'foo', 'bar' );
|
||||
description.empty();
|
||||
|
|
|
@ -21,7 +21,7 @@ const DownloadPane = require( 'mmv.ui.download.pane' );
|
|||
QUnit.module( 'mmv.ui.download.pane', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Sense test, object creation and UI construction', function ( assert ) {
|
||||
var download = new DownloadPane( $( '#qunit-fixture' ) );
|
||||
const download = new DownloadPane( $( '#qunit-fixture' ) );
|
||||
|
||||
assert.true( download instanceof DownloadPane, 'download UI element is created.' );
|
||||
assert.strictEqual( download.$pane.length, 1, 'Pane div created.' );
|
||||
|
@ -37,12 +37,12 @@ const DownloadPane = require( 'mmv.ui.download.pane' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'set()/empty():', function ( assert ) {
|
||||
var download = new DownloadPane( $( '#qunit-fixture' ) ),
|
||||
src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
image = { // fake ImageModel
|
||||
title: new mw.Title( 'File:Foobar.jpg' ),
|
||||
url: src
|
||||
};
|
||||
const download = new DownloadPane( $( '#qunit-fixture' ) );
|
||||
const src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const image = { // fake ImageModel
|
||||
title: new mw.Title( 'File:Foobar.jpg' ),
|
||||
url: src
|
||||
};
|
||||
|
||||
assert.strictEqual( download.imageExtension, undefined, 'Image extension is not set.' );
|
||||
|
||||
|
@ -63,17 +63,16 @@ const DownloadPane = require( 'mmv.ui.download.pane' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'attach()/unattach():', function ( assert ) {
|
||||
var hsstub, tstub,
|
||||
download = new DownloadPane( $( '#qunit-fixture' ) ),
|
||||
image = {
|
||||
title: new mw.Title( 'File:Foobar.jpg' ),
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg'
|
||||
};
|
||||
const download = new DownloadPane( $( '#qunit-fixture' ) );
|
||||
const image = {
|
||||
title: new mw.Title( 'File:Foobar.jpg' ),
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg'
|
||||
};
|
||||
|
||||
download.set( image );
|
||||
|
||||
hsstub = this.sandbox.stub( download, 'handleSizeSwitch' );
|
||||
tstub = this.sandbox.stub( download.downloadSizeMenu.getMenu(), 'toggle' );
|
||||
const hsstub = this.sandbox.stub( download, 'handleSizeSwitch' );
|
||||
const tstub = this.sandbox.stub( download.downloadSizeMenu.getMenu(), 'toggle' );
|
||||
|
||||
// Triggering action events before attaching should do nothing
|
||||
download.downloadSizeMenu.getMenu().emit(
|
||||
|
@ -111,8 +110,8 @@ const DownloadPane = require( 'mmv.ui.download.pane' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'handleSizeSwitch():', function ( assert ) {
|
||||
var download = new DownloadPane( $( '#qunit-fixture' ) ),
|
||||
newImageUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/NewFoobar.jpg';
|
||||
const download = new DownloadPane( $( '#qunit-fixture' ) );
|
||||
const newImageUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/NewFoobar.jpg';
|
||||
|
||||
download.utils.getThumbnailUrlPromise = function () {
|
||||
return $.Deferred().resolve( { url: newImageUrl } ).promise();
|
||||
|
@ -136,27 +135,26 @@ const DownloadPane = require( 'mmv.ui.download.pane' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'setButtonText() sense check:', function ( assert ) {
|
||||
var download = new DownloadPane( $( '#qunit-fixture' ) ),
|
||||
message;
|
||||
const download = new DownloadPane( $( '#qunit-fixture' ) );
|
||||
|
||||
download.setButtonText( 'large', 'jpg', 100, 200 );
|
||||
assert.true( true, 'Setting the text did not cause any errors' );
|
||||
|
||||
message = download.$downloadButton.html();
|
||||
const message = download.$downloadButton.html();
|
||||
download.setButtonText( 'small', 'png', 1000, 2000 );
|
||||
assert.notStrictEqual( download.$downloadButton.html(), message, 'Button text was updated' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'getExtensionFromUrl():', function ( assert ) {
|
||||
var download = new DownloadPane( $( '#qunit-fixture' ) );
|
||||
const download = new DownloadPane( $( '#qunit-fixture' ) );
|
||||
|
||||
assert.strictEqual( download.getExtensionFromUrl( 'http://example.com/bing/foo.bar.png' ),
|
||||
'png', 'Extension is parsed correctly' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'setDownloadUrl', function ( assert ) {
|
||||
var download = new DownloadPane( $( '#qunit-fixture' ) ),
|
||||
imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/NewFoobar.jpg';
|
||||
const download = new DownloadPane( $( '#qunit-fixture' ) );
|
||||
const imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/NewFoobar.jpg';
|
||||
|
||||
download.setDownloadUrl( imageUrl );
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ const { MetadataPanel, License } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.ui.metadataPanel', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( '.empty()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' );
|
||||
var panel = new MetadataPanel(
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const panel = new MetadataPanel(
|
||||
$qf,
|
||||
$( '<div>' ).appendTo( $qf ),
|
||||
mw.storage,
|
||||
|
@ -33,17 +33,17 @@ QUnit.test( '.empty()', function ( assert ) {
|
|||
} );
|
||||
|
||||
QUnit.test( '.setLocationData()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' );
|
||||
var panel = new MetadataPanel(
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const panel = new MetadataPanel(
|
||||
$qf,
|
||||
$( '<div>' ).appendTo( $qf ),
|
||||
mw.storage,
|
||||
new Config( {}, mw.config, mw.user, new mw.Api(), mw.storage )
|
||||
);
|
||||
var fileName = 'Foobar.jpg';
|
||||
var latitude = 12.3456789;
|
||||
var longitude = 98.7654321;
|
||||
var imageData = {
|
||||
const fileName = 'Foobar.jpg';
|
||||
let latitude = 12.3456789;
|
||||
let longitude = 98.7654321;
|
||||
const imageData = {
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
hasCoords: function () { return true; },
|
||||
|
@ -99,28 +99,28 @@ QUnit.test( '.setLocationData()', function ( assert ) {
|
|||
} );
|
||||
|
||||
QUnit.test( '.setImageInfo()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' );
|
||||
var panel = new MetadataPanel(
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const panel = new MetadataPanel(
|
||||
$qf,
|
||||
$( '<div>' ).appendTo( $qf ),
|
||||
mw.storage,
|
||||
new Config( {}, mw.config, mw.user, new mw.Api(), mw.storage )
|
||||
);
|
||||
var title = 'Foo bar';
|
||||
var image = {
|
||||
const title = 'Foo bar';
|
||||
const image = {
|
||||
filePageTitle: mw.Title.newFromText( 'File:' + title + '.jpg' )
|
||||
};
|
||||
var imageData = {
|
||||
const imageData = {
|
||||
title: image.filePageTitle,
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
descriptionUrl: 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||
hasCoords: function () { return false; }
|
||||
};
|
||||
var repoData = {
|
||||
const repoData = {
|
||||
getArticlePath: function () { return 'Foo'; },
|
||||
isCommons: function () { return false; }
|
||||
};
|
||||
var clock = this.sandbox.useFakeTimers();
|
||||
const clock = this.sandbox.useFakeTimers();
|
||||
|
||||
panel.setImageInfo( image, imageData, repoData );
|
||||
|
||||
|
@ -143,7 +143,7 @@ QUnit.test( '.setImageInfo()', function ( assert ) {
|
|||
imageData.restrictions = [ 'trademarked', 'default', 'insignia' ];
|
||||
|
||||
panel.setImageInfo( image, imageData, repoData );
|
||||
var creditPopupText = panel.creditField.$element.attr( 'original-title' );
|
||||
const creditPopupText = panel.creditField.$element.attr( 'original-title' );
|
||||
clock.tick( 10 );
|
||||
|
||||
assert.strictEqual( panel.$title.text(), title, 'Title is correctly set' );
|
||||
|
@ -169,8 +169,8 @@ QUnit.test( '.setImageInfo()', function ( assert ) {
|
|||
|
||||
// FIXME: test broken since migrating to require/packageFiles
|
||||
QUnit.skip( 'Setting permission information works as expected', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' );
|
||||
var panel = new MetadataPanel(
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const panel = new MetadataPanel(
|
||||
$qf,
|
||||
$( '<div>' ).appendTo( $qf ),
|
||||
mw.storage,
|
||||
|
@ -184,21 +184,21 @@ QUnit.skip( 'Setting permission information works as expected', function ( asser
|
|||
} );
|
||||
|
||||
QUnit.test( 'Date formatting', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' );
|
||||
var panel = new MetadataPanel(
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const panel = new MetadataPanel(
|
||||
$qf,
|
||||
$( '<div>' ).appendTo( $qf ),
|
||||
mw.storage,
|
||||
new Config( {}, mw.config, mw.user, new mw.Api(), mw.storage )
|
||||
);
|
||||
var date1 = 'Garbage';
|
||||
var result = panel.formatDate( date1 );
|
||||
const date1 = 'Garbage';
|
||||
const result = panel.formatDate( date1 );
|
||||
|
||||
assert.strictEqual( result, date1, 'Invalid date is correctly ignored' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'About links', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
|
||||
this.sandbox.stub( mw.user, 'isAnon' );
|
||||
// eslint-disable-next-line no-new
|
||||
|
|
|
@ -26,24 +26,24 @@ const { MetadataPanelScroller } = require( 'mmv' );
|
|||
} ) );
|
||||
|
||||
QUnit.test( 'empty()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
localStorage = getFakeLocalStorage(),
|
||||
scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const localStorage = getFakeLocalStorage();
|
||||
const scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
|
||||
|
||||
scroller.empty();
|
||||
assert.strictEqual( scroller.$container.hasClass( 'invite' ), false, 'We successfully reset the invite' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Metadata div is only animated once', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
displayCount = null, // pretend it doesn't exist at first
|
||||
localStorage = createLocalStorage( {
|
||||
// We simulate localStorage to avoid test side-effects
|
||||
getItem: function () { return displayCount; },
|
||||
setItem: function ( _, val ) { displayCount = val; },
|
||||
removeItem: function () { displayCount = null; }
|
||||
} ),
|
||||
scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
let displayCount = null; // pretend it doesn't exist at first
|
||||
const localStorage = createLocalStorage( {
|
||||
// We simulate localStorage to avoid test side-effects
|
||||
getItem: function () { return displayCount; },
|
||||
setItem: function ( _, val ) { displayCount = val; },
|
||||
removeItem: function () { displayCount = null; }
|
||||
} );
|
||||
const scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
|
||||
|
||||
scroller.attach();
|
||||
|
||||
|
@ -74,9 +74,9 @@ const { MetadataPanelScroller } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'No localStorage', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
localStorage = getUnsupportedLocalStorage(),
|
||||
scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const localStorage = getUnsupportedLocalStorage();
|
||||
const scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
|
||||
|
||||
this.sandbox.stub( $.fn, 'scrollTop', () => 10 );
|
||||
|
||||
|
@ -86,13 +86,13 @@ const { MetadataPanelScroller } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'localStorage is full', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
localStorage = createLocalStorage( {
|
||||
getItem: this.sandbox.stub().returns( null ),
|
||||
setItem: this.sandbox.stub().throwsException( 'I am full' ),
|
||||
removeItem: this.sandbox.stub()
|
||||
} ),
|
||||
scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const localStorage = createLocalStorage( {
|
||||
getItem: this.sandbox.stub().returns( null ),
|
||||
setItem: this.sandbox.stub().throwsException( 'I am full' ),
|
||||
removeItem: this.sandbox.stub()
|
||||
} );
|
||||
const scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
|
||||
|
||||
this.sandbox.stub( $.fn, 'scrollTop', () => 10 );
|
||||
|
||||
|
@ -118,7 +118,7 @@ const { MetadataPanelScroller } = require( 'mmv' );
|
|||
* @param {MetadataPanelScroller} scroller
|
||||
*/
|
||||
function stubScrollFunctions( sandbox, scroller ) {
|
||||
var memorizedScrollTop = 0;
|
||||
let memorizedScrollTop = 0;
|
||||
|
||||
sandbox.stub( $.fn, 'scrollTop', function ( scrollTop ) {
|
||||
if ( scrollTop !== undefined ) {
|
||||
|
@ -139,17 +139,17 @@ const { MetadataPanelScroller } = require( 'mmv' );
|
|||
}
|
||||
|
||||
QUnit.test( 'Metadata scrolling', function ( assert ) {
|
||||
var $window = $( window ),
|
||||
$qf = $( '#qunit-fixture' ),
|
||||
$container = $( '<div>' ).css( 'height', 100 ).appendTo( $qf ),
|
||||
$aboveFold = $( '<div>' ).css( 'height', 50 ).appendTo( $container ),
|
||||
fakeLocalStorage = createLocalStorage( {
|
||||
getItem: this.sandbox.stub().returns( null ),
|
||||
setItem: function () {},
|
||||
removeItem: function () {}
|
||||
} ),
|
||||
scroller = new MetadataPanelScroller( $container, $aboveFold, fakeLocalStorage ),
|
||||
keydown = $.Event( 'keydown' );
|
||||
const $window = $( window );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const $container = $( '<div>' ).css( 'height', 100 ).appendTo( $qf );
|
||||
const $aboveFold = $( '<div>' ).css( 'height', 50 ).appendTo( $container );
|
||||
const fakeLocalStorage = createLocalStorage( {
|
||||
getItem: this.sandbox.stub().returns( null ),
|
||||
setItem: function () {},
|
||||
removeItem: function () {}
|
||||
} );
|
||||
const scroller = new MetadataPanelScroller( $container, $aboveFold, fakeLocalStorage );
|
||||
const keydown = $.Event( 'keydown' );
|
||||
|
||||
stubScrollFunctions( this.sandbox, scroller );
|
||||
|
||||
|
|
|
@ -26,16 +26,16 @@ const { Permission } = require( 'mmv' );
|
|||
} ) );
|
||||
|
||||
QUnit.test( 'Constructor sense check', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
permission = new Permission( $qf );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const permission = new Permission( $qf );
|
||||
|
||||
assert.true( permission instanceof Permission, 'constructor does not throw error' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'set()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
permission = new Permission( $qf ),
|
||||
text = 'Nothing to see here.';
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const permission = new Permission( $qf );
|
||||
const text = 'Nothing to see here.';
|
||||
|
||||
permission.set( text );
|
||||
|
||||
|
@ -49,9 +49,9 @@ const { Permission } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'set() with html', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
permission = new Permission( $qf ),
|
||||
text = '<b>Nothing</b> to see here.';
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const permission = new Permission( $qf );
|
||||
const text = '<b>Nothing</b> to see here.';
|
||||
|
||||
permission.set( text );
|
||||
|
||||
|
@ -60,9 +60,9 @@ const { Permission } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'empty()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
permission = new Permission( $qf ),
|
||||
text = 'Nothing to see here.';
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const permission = new Permission( $qf );
|
||||
const text = 'Nothing to see here.';
|
||||
|
||||
permission.set( text );
|
||||
permission.empty();
|
||||
|
@ -73,9 +73,9 @@ const { Permission } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'grow()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
permission = new Permission( $qf ),
|
||||
text = 'Nothing to see here.';
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const permission = new Permission( $qf );
|
||||
const text = 'Nothing to see here.';
|
||||
|
||||
permission.set( text );
|
||||
permission.grow();
|
||||
|
@ -86,9 +86,9 @@ const { Permission } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'shrink()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
permission = new Permission( $qf ),
|
||||
text = 'Nothing to see here.';
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const permission = new Permission( $qf );
|
||||
const text = 'Nothing to see here.';
|
||||
|
||||
permission.set( text );
|
||||
permission.grow();
|
||||
|
@ -100,9 +100,9 @@ const { Permission } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'isFullSize()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
permission = new Permission( $qf ),
|
||||
text = 'Nothing to see here.';
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const permission = new Permission( $qf );
|
||||
const text = 'Nothing to see here.';
|
||||
|
||||
permission.set( text );
|
||||
assert.strictEqual( permission.isFullSize(), false, 'permission is not full-size' );
|
||||
|
|
|
@ -21,15 +21,15 @@ const { ProgressBar } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.ui.ProgressBar', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Constructor sense check', function ( assert ) {
|
||||
var progressBar = new ProgressBar( $( '<div>' ) );
|
||||
const progressBar = new ProgressBar( $( '<div>' ) );
|
||||
assert.true( progressBar instanceof ProgressBar, 'ProgressBar created sccessfully' );
|
||||
assert.strictEqual( progressBar.$progress.hasClass( 'empty' ), true, 'ProgressBar starts empty' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'animateTo()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
$div = $( '<div>' ).css( { width: 250, position: 'relative' } ).appendTo( $qf ),
|
||||
progress = new ProgressBar( $div );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const $div = $( '<div>' ).css( { width: 250, position: 'relative' } ).appendTo( $qf );
|
||||
const progress = new ProgressBar( $div );
|
||||
|
||||
assert.strictEqual( progress.$progress.hasClass( 'empty' ), true, 'Progress bar is hidden' );
|
||||
assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is at 0' );
|
||||
|
@ -59,9 +59,9 @@ const { ProgressBar } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'jumpTo()/hide()', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
$div = $( '<div>' ).css( { width: 250, position: 'relative' } ).appendTo( $qf ),
|
||||
progress = new ProgressBar( $div );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const $div = $( '<div>' ).css( { width: 250, position: 'relative' } ).appendTo( $qf );
|
||||
const progress = new ProgressBar( $div );
|
||||
|
||||
assert.strictEqual( progress.$progress.hasClass( 'empty' ), true, 'Progress bar is hidden' );
|
||||
assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is at 0' );
|
||||
|
|
|
@ -19,22 +19,22 @@ const { ReuseDialog, Repo } = require( 'mmv' );
|
|||
|
||||
( function () {
|
||||
function makeReuseDialog( sandbox ) {
|
||||
var $fixture = $( '#qunit-fixture' ),
|
||||
config = { getFromLocalStorage: sandbox.stub(), setInLocalStorage: sandbox.stub() };
|
||||
const $fixture = $( '#qunit-fixture' );
|
||||
const config = { getFromLocalStorage: sandbox.stub(), setInLocalStorage: sandbox.stub() };
|
||||
return new ReuseDialog( $fixture, $( '<div>' ).appendTo( $fixture ), config );
|
||||
}
|
||||
|
||||
QUnit.module( 'mmv.ui.reuse.Dialog', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Sense test, object creation and UI construction', function ( assert ) {
|
||||
var reuseDialog = makeReuseDialog( this.sandbox );
|
||||
const reuseDialog = makeReuseDialog( this.sandbox );
|
||||
|
||||
assert.true( reuseDialog instanceof ReuseDialog, 'Reuse UI element is created.' );
|
||||
assert.strictEqual( reuseDialog.$dialog.length, 1, 'Reuse dialog div created.' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'handleOpenCloseClick():', function ( assert ) {
|
||||
var reuseDialog = makeReuseDialog( this.sandbox );
|
||||
const reuseDialog = makeReuseDialog( this.sandbox );
|
||||
|
||||
reuseDialog.openDialog = function () {
|
||||
assert.true( true, 'openDialog called.' );
|
||||
|
@ -59,7 +59,7 @@ const { ReuseDialog, Repo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'handleTabSelection():', function ( assert ) {
|
||||
var reuseDialog = makeReuseDialog( this.sandbox );
|
||||
const reuseDialog = makeReuseDialog( this.sandbox );
|
||||
|
||||
reuseDialog.initTabs();
|
||||
|
||||
|
@ -77,9 +77,7 @@ const { ReuseDialog, Repo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'default tab:', function ( assert ) {
|
||||
var reuseDialog;
|
||||
|
||||
reuseDialog = makeReuseDialog( this.sandbox );
|
||||
let reuseDialog = makeReuseDialog( this.sandbox );
|
||||
reuseDialog.initTabs();
|
||||
assert.strictEqual( reuseDialog.selectedTab, 'share', 'Share tab is default' );
|
||||
|
||||
|
@ -90,7 +88,7 @@ const { ReuseDialog, Repo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'attach()/unattach():', function ( assert ) {
|
||||
var reuseDialog = makeReuseDialog( this.sandbox );
|
||||
const reuseDialog = makeReuseDialog( this.sandbox );
|
||||
|
||||
reuseDialog.initTabs();
|
||||
|
||||
|
@ -134,33 +132,31 @@ const { ReuseDialog, Repo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'start/stopListeningToOutsideClick():', function ( assert ) {
|
||||
var reuseDialog = makeReuseDialog( this.sandbox ),
|
||||
realCloseDialog = reuseDialog.closeDialog;
|
||||
const reuseDialog = makeReuseDialog( this.sandbox );
|
||||
const realCloseDialog = reuseDialog.closeDialog;
|
||||
|
||||
reuseDialog.initTabs();
|
||||
|
||||
function clickOutsideDialog() {
|
||||
var event = new $.Event( 'click', { target: reuseDialog.$container[ 0 ] } );
|
||||
const event = new $.Event( 'click', { target: reuseDialog.$container[ 0 ] } );
|
||||
reuseDialog.$container.trigger( event );
|
||||
return event;
|
||||
}
|
||||
function clickInsideDialog() {
|
||||
var event = new $.Event( 'click', { target: reuseDialog.$dialog[ 0 ] } );
|
||||
const event = new $.Event( 'click', { target: reuseDialog.$dialog[ 0 ] } );
|
||||
reuseDialog.$dialog.trigger( event );
|
||||
return event;
|
||||
}
|
||||
|
||||
function assertDialogDoesNotCatchClicks() {
|
||||
var event;
|
||||
reuseDialog.closeDialog = () => assert.true( false, 'Dialog is not affected by click' );
|
||||
event = clickOutsideDialog();
|
||||
const event = clickOutsideDialog();
|
||||
assert.strictEqual( event.isDefaultPrevented(), false, 'Dialog does not affect click' );
|
||||
assert.strictEqual( event.isPropagationStopped(), false, 'Dialog does not affect click propagation' );
|
||||
}
|
||||
function assertDialogCatchesOutsideClicksOnly() {
|
||||
var event;
|
||||
reuseDialog.closeDialog = () => assert.true( false, 'Dialog is not affected by inside click' );
|
||||
event = clickInsideDialog();
|
||||
let event = clickInsideDialog();
|
||||
assert.strictEqual( event.isDefaultPrevented(), false, 'Dialog does not affect inside click' );
|
||||
assert.strictEqual( event.isPropagationStopped(), false, 'Dialog does not affect inside click propagation' );
|
||||
reuseDialog.closeDialog = () => assert.true( true, 'Dialog is closed by outside click' );
|
||||
|
@ -180,22 +176,22 @@ const { ReuseDialog, Repo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'set()/empty() sense check:', function ( assert ) {
|
||||
var reuseDialog = makeReuseDialog( this.sandbox ),
|
||||
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
||||
src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||
image = { // fake ImageModel
|
||||
title: title,
|
||||
url: src,
|
||||
descriptionUrl: url,
|
||||
width: 100,
|
||||
height: 80
|
||||
},
|
||||
embedFileInfo = {
|
||||
imageInfo: title,
|
||||
repoInfo: src,
|
||||
caption: url
|
||||
};
|
||||
const reuseDialog = makeReuseDialog( this.sandbox );
|
||||
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
||||
const src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
||||
const image = { // fake ImageModel
|
||||
title: title,
|
||||
url: src,
|
||||
descriptionUrl: url,
|
||||
width: 100,
|
||||
height: 80
|
||||
};
|
||||
const embedFileInfo = {
|
||||
imageInfo: title,
|
||||
repoInfo: src,
|
||||
caption: url
|
||||
};
|
||||
|
||||
reuseDialog.set( image, embedFileInfo );
|
||||
reuseDialog.empty();
|
||||
|
@ -204,18 +200,18 @@ const { ReuseDialog, Repo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'openDialog()/closeDialog():', function ( assert ) {
|
||||
var reuseDialog = makeReuseDialog( this.sandbox ),
|
||||
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
||||
src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||
image = { // fake ImageModel
|
||||
title: title,
|
||||
url: src,
|
||||
descriptionUrl: url,
|
||||
width: 100,
|
||||
height: 80
|
||||
},
|
||||
repoInfo = new Repo( 'Wikipedia', '//wikipedia.org/favicon.ico', true );
|
||||
const reuseDialog = makeReuseDialog( this.sandbox );
|
||||
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
||||
const src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
||||
const image = { // fake ImageModel
|
||||
title: title,
|
||||
url: src,
|
||||
descriptionUrl: url,
|
||||
width: 100,
|
||||
height: 80
|
||||
};
|
||||
const repoInfo = new Repo( 'Wikipedia', '//wikipedia.org/favicon.ico', true );
|
||||
|
||||
reuseDialog.initTabs();
|
||||
|
||||
|
@ -233,18 +229,18 @@ const { ReuseDialog, Repo } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getImageWarnings():', function ( assert ) {
|
||||
var reuseDialog = makeReuseDialog( this.sandbox ),
|
||||
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
||||
src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||
image = { // fake ImageModel
|
||||
title: title,
|
||||
url: src,
|
||||
descriptionUrl: url,
|
||||
width: 100,
|
||||
height: 80
|
||||
},
|
||||
imageDeleted = Object.assign( { deletionReason: 'deleted file test' }, image );
|
||||
const reuseDialog = makeReuseDialog( this.sandbox );
|
||||
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
||||
const src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
||||
const image = { // fake ImageModel
|
||||
title: title,
|
||||
url: src,
|
||||
descriptionUrl: url,
|
||||
width: 100,
|
||||
height: 80
|
||||
};
|
||||
const imageDeleted = Object.assign( { deletionReason: 'deleted file test' }, image );
|
||||
|
||||
// Test that the lack of license is picked up
|
||||
assert.strictEqual( reuseDialog.getImageWarnings( image ).length, 1, 'Lack of license detected' );
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
||||
|
||||
( function () {
|
||||
var $qf = $( '#qunit-fixture' );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
|
||||
QUnit.module( 'mmv.ui.reuse.Embed', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Sense test, object creation and UI construction', function ( assert ) {
|
||||
var embed = new Embed( $qf );
|
||||
const embed = new Embed( $qf );
|
||||
|
||||
assert.true( embed instanceof Embed, 'Embed UI element is created.' );
|
||||
assert.strictEqual( embed.$pane.length, 1, 'Pane div is created.' );
|
||||
|
@ -41,9 +41,9 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'changeSize(): Skip if no item selected.', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
width = 10,
|
||||
height = 20;
|
||||
const embed = new Embed( $qf );
|
||||
const width = 10;
|
||||
const height = 20;
|
||||
|
||||
assert.expect( 0 );
|
||||
|
||||
|
@ -61,9 +61,9 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'changeSize(): HTML size menu item selected.', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
width = 10,
|
||||
height = 20;
|
||||
const embed = new Embed( $qf );
|
||||
const width = 10;
|
||||
const height = 20;
|
||||
|
||||
embed.embedSwitch.findSelectedItem = function () {
|
||||
return { getData: () => 'html' };
|
||||
|
@ -84,9 +84,9 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'changeSize(): Wikitext size menu item selected.', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
width = 10,
|
||||
height = 20;
|
||||
const embed = new Embed( $qf );
|
||||
const width = 10;
|
||||
const height = 20;
|
||||
|
||||
embed.embedSwitch.findSelectedItem = function () {
|
||||
return { getData: () => 'wikitext' };
|
||||
|
@ -105,9 +105,9 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'updateEmbedHtml(): Do nothing if set() not called before.', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
width = 10,
|
||||
height = 20;
|
||||
const embed = new Embed( $qf );
|
||||
const width = 10;
|
||||
const height = 20;
|
||||
|
||||
assert.expect( 0 );
|
||||
|
||||
|
@ -118,19 +118,19 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'updateEmbedHtml():', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
thumbUrl = 'https://upload.wikimedia.org/wikipedia/thumb/Foobar.jpg',
|
||||
imageInfo = { url: url },
|
||||
repoInfo = {},
|
||||
caption = '-',
|
||||
info = {
|
||||
imageInfo: imageInfo,
|
||||
repoInfo: repoInfo,
|
||||
caption: caption
|
||||
},
|
||||
width = 10,
|
||||
height = 20;
|
||||
const embed = new Embed( $qf );
|
||||
const url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const thumbUrl = 'https://upload.wikimedia.org/wikipedia/thumb/Foobar.jpg';
|
||||
const imageInfo = { url: url };
|
||||
const repoInfo = {};
|
||||
const caption = '-';
|
||||
const info = {
|
||||
imageInfo: imageInfo,
|
||||
repoInfo: repoInfo,
|
||||
caption: caption
|
||||
};
|
||||
let width = 10;
|
||||
const height = 20;
|
||||
|
||||
embed.set( imageInfo, repoInfo, caption );
|
||||
|
||||
|
@ -158,8 +158,8 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'updateEmbedWikitext(): Do nothing if set() not called before.', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
width = 10;
|
||||
const embed = new Embed( $qf );
|
||||
const width = 10;
|
||||
|
||||
assert.expect( 0 );
|
||||
|
||||
|
@ -170,16 +170,16 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'updateEmbedWikitext():', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
imageInfo = {},
|
||||
repoInfo = {},
|
||||
caption = '-',
|
||||
info = {
|
||||
imageInfo: imageInfo,
|
||||
repoInfo: repoInfo,
|
||||
caption: caption
|
||||
},
|
||||
width = 10;
|
||||
const embed = new Embed( $qf );
|
||||
const imageInfo = {};
|
||||
const repoInfo = {};
|
||||
const caption = '-';
|
||||
const info = {
|
||||
imageInfo: imageInfo,
|
||||
repoInfo: repoInfo,
|
||||
caption: caption
|
||||
};
|
||||
const width = 10;
|
||||
|
||||
embed.set( imageInfo, repoInfo, caption );
|
||||
|
||||
|
@ -191,56 +191,55 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getPossibleImageSizesForWikitext()', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
exampleSizes = [
|
||||
// Big wide image
|
||||
{
|
||||
width: 2048, height: 1536,
|
||||
expected: {
|
||||
small: { width: 300, height: 225 },
|
||||
medium: { width: 400, height: 300 },
|
||||
large: { width: 500, height: 375 },
|
||||
default: { width: null, height: null }
|
||||
}
|
||||
},
|
||||
|
||||
// Big tall image
|
||||
{
|
||||
width: 201, height: 1536,
|
||||
expected: {
|
||||
default: { width: null, height: null }
|
||||
}
|
||||
},
|
||||
|
||||
// Very small image
|
||||
{
|
||||
width: 15, height: 20,
|
||||
expected: {
|
||||
default: { width: null, height: null }
|
||||
}
|
||||
const embed = new Embed( $qf );
|
||||
const exampleSizes = [
|
||||
// Big wide image
|
||||
{
|
||||
width: 2048, height: 1536,
|
||||
expected: {
|
||||
small: { width: 300, height: 225 },
|
||||
medium: { width: 400, height: 300 },
|
||||
large: { width: 500, height: 375 },
|
||||
default: { width: null, height: null }
|
||||
}
|
||||
],
|
||||
i, cursize, opts;
|
||||
for ( i = 0; i < exampleSizes.length; i++ ) {
|
||||
cursize = exampleSizes[ i ];
|
||||
opts = embed.getPossibleImageSizesForWikitext( cursize.width, cursize.height );
|
||||
},
|
||||
|
||||
// Big tall image
|
||||
{
|
||||
width: 201, height: 1536,
|
||||
expected: {
|
||||
default: { width: null, height: null }
|
||||
}
|
||||
},
|
||||
|
||||
// Very small image
|
||||
{
|
||||
width: 15, height: 20,
|
||||
expected: {
|
||||
default: { width: null, height: null }
|
||||
}
|
||||
}
|
||||
];
|
||||
for ( let i = 0; i < exampleSizes.length; i++ ) {
|
||||
const cursize = exampleSizes[ i ];
|
||||
const opts = embed.getPossibleImageSizesForWikitext( cursize.width, cursize.height );
|
||||
assert.deepEqual( opts, cursize.expected, 'We got the expected results out of the size calculation function.' );
|
||||
}
|
||||
} );
|
||||
|
||||
QUnit.test( 'set():', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
||||
src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||
embedFileInfo = {
|
||||
imageInfo: title,
|
||||
repoInfo: src,
|
||||
caption: url
|
||||
},
|
||||
calledSelect = false,
|
||||
width = 15,
|
||||
height = 20;
|
||||
const embed = new Embed( $qf );
|
||||
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
||||
const src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
||||
const embedFileInfo = {
|
||||
imageInfo: title,
|
||||
repoInfo: src,
|
||||
caption: url
|
||||
};
|
||||
let calledSelect = false;
|
||||
const width = 15;
|
||||
const height = 20;
|
||||
|
||||
embed.utils.updateMenuOptions = function ( sizes, options ) {
|
||||
assert.strictEqual( options.length, 4, 'Options passed correctly.' );
|
||||
|
@ -268,9 +267,9 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'empty():', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
width = 15,
|
||||
height = 20;
|
||||
const embed = new Embed( $qf );
|
||||
const width = 15;
|
||||
const height = 20;
|
||||
|
||||
embed.formatter = {
|
||||
getThumbnailWikitextFromEmbedFileInfo: function () { return 'wikitext'; },
|
||||
|
@ -293,17 +292,17 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'attach()/unattach():', function ( assert ) {
|
||||
var embed = new Embed( $qf ),
|
||||
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
||||
src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||
embedFileInfo = {
|
||||
imageInfo: title,
|
||||
repoInfo: src,
|
||||
caption: url
|
||||
},
|
||||
width = 15,
|
||||
height = 20;
|
||||
const embed = new Embed( $qf );
|
||||
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
||||
const src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
||||
const url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
||||
const embedFileInfo = {
|
||||
imageInfo: title,
|
||||
repoInfo: src,
|
||||
caption: url
|
||||
};
|
||||
const width = 15;
|
||||
const height = 20;
|
||||
|
||||
embed.set( { width: width, height: height }, embedFileInfo );
|
||||
|
||||
|
@ -356,7 +355,7 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'handleTypeSwitch():', function ( assert ) {
|
||||
var embed = new Embed( $qf );
|
||||
const embed = new Embed( $qf );
|
||||
|
||||
assert.strictEqual( embed.isSizeMenuDefaultReset, false, 'Reset flag intialized correctly.' );
|
||||
|
||||
|
@ -382,12 +381,11 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Logged out', function ( assert ) {
|
||||
var embed,
|
||||
oldUserIsAnon = mw.user.isAnon;
|
||||
const oldUserIsAnon = mw.user.isAnon;
|
||||
|
||||
mw.user.isAnon = () => true;
|
||||
|
||||
embed = new Embed( $qf );
|
||||
const embed = new Embed( $qf );
|
||||
|
||||
embed.attach();
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ const { Share } = require( 'mmv.ui.reuse.shareembed' );
|
|||
QUnit.module( 'mmv.ui.reuse.share', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Sense test, object creation and UI construction', function ( assert ) {
|
||||
var share = makeShare();
|
||||
const share = makeShare();
|
||||
|
||||
assert.true( share instanceof Share, 'Share UI element is created.' );
|
||||
assert.strictEqual( share.$pane.length, 1, 'Pane div created.' );
|
||||
|
@ -34,12 +34,12 @@ const { Share } = require( 'mmv.ui.reuse.shareembed' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'set()/empty():', function ( assert ) {
|
||||
var share = makeShare(),
|
||||
image = { // fake ImageModel
|
||||
title: new mw.Title( 'File:Foobar.jpg' ),
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
descriptionUrl: '//commons.wikimedia.org/wiki/File:Foobar.jpg'
|
||||
};
|
||||
const share = makeShare();
|
||||
const image = { // fake ImageModel
|
||||
title: new mw.Title( 'File:Foobar.jpg' ),
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||
descriptionUrl: '//commons.wikimedia.org/wiki/File:Foobar.jpg'
|
||||
};
|
||||
|
||||
assert.notStrictEqual( !share.pageInput.textInput.getValue(), '', 'pageInput is empty.' );
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
const { Tab } = require( 'mmv.ui.reuse.shareembed' );
|
||||
|
||||
( function () {
|
||||
var $fixture = $( '#qunit-fixture' );
|
||||
const $fixture = $( '#qunit-fixture' );
|
||||
|
||||
function makeReuseTab() {
|
||||
return new Tab( $( '<div>' ).appendTo( $fixture ), $fixture );
|
||||
|
@ -27,7 +27,7 @@ const { Tab } = require( 'mmv.ui.reuse.shareembed' );
|
|||
QUnit.module( 'mmv.ui.reuse.Tab', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Object creation, UI construction and basic funtionality', function ( assert ) {
|
||||
var reuseTab = makeReuseTab();
|
||||
const reuseTab = makeReuseTab();
|
||||
|
||||
assert.true( reuseTab instanceof Tab, 'Reuse UI element is created.' );
|
||||
assert.strictEqual( reuseTab.$pane.length, 1, 'Pane created.' );
|
||||
|
|
|
@ -21,27 +21,26 @@ const { Utils } = require( 'mmv.ui.ondemandshareddependencies' );
|
|||
QUnit.module( 'mmv.ui.reuse.utils', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Sense test, object creation and UI construction', function ( assert ) {
|
||||
var utils = new Utils();
|
||||
const utils = new Utils();
|
||||
|
||||
assert.true( utils instanceof Utils, 'ReuseUtils object is created.' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'createPulldownMenu():', function ( assert ) {
|
||||
var utils = new Utils(),
|
||||
menuItems = [ 'original', 'small', 'medium', 'large' ],
|
||||
def = 'large',
|
||||
menu = utils.createPulldownMenu(
|
||||
menuItems,
|
||||
[ 'mw-mmv-download-size' ],
|
||||
def
|
||||
),
|
||||
options = menu.getMenu().getItems(),
|
||||
i, data;
|
||||
const utils = new Utils();
|
||||
const menuItems = [ 'original', 'small', 'medium', 'large' ];
|
||||
const def = 'large';
|
||||
const menu = utils.createPulldownMenu(
|
||||
menuItems,
|
||||
[ 'mw-mmv-download-size' ],
|
||||
def
|
||||
);
|
||||
const options = menu.getMenu().getItems();
|
||||
|
||||
assert.strictEqual( options.length, 4, 'Menu has correct number of items.' );
|
||||
|
||||
for ( i = 0; i < menuItems.length; i++ ) {
|
||||
data = options[ i ].getData();
|
||||
for ( let i = 0; i < menuItems.length; i++ ) {
|
||||
const 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.' );
|
||||
|
@ -52,17 +51,17 @@ const { Utils } = require( 'mmv.ui.ondemandshareddependencies' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'updateMenuOptions():', function ( assert ) {
|
||||
var utils = new Utils(),
|
||||
menu = utils.createPulldownMenu(
|
||||
[ 'original', 'small', 'medium', 'large' ],
|
||||
[ 'mw-mmv-download-size' ],
|
||||
'original'
|
||||
),
|
||||
options = menu.getMenu().getItems(),
|
||||
width = 700,
|
||||
height = 500,
|
||||
sizes = utils.getPossibleImageSizesForHtml( width, height ),
|
||||
oldMessage = mw.message;
|
||||
const utils = new Utils();
|
||||
const menu = utils.createPulldownMenu(
|
||||
[ 'original', 'small', 'medium', 'large' ],
|
||||
[ 'mw-mmv-download-size' ],
|
||||
'original'
|
||||
);
|
||||
const options = menu.getMenu().getItems();
|
||||
const width = 700;
|
||||
const height = 500;
|
||||
const sizes = utils.getPossibleImageSizesForHtml( width, height );
|
||||
const oldMessage = mw.message;
|
||||
|
||||
mw.message = function ( messageKey ) {
|
||||
assert.true( /^multimediaviewer-(small|medium|original|embed-dimensions)/.test( messageKey ), 'messageKey passed correctly.' );
|
||||
|
@ -76,54 +75,53 @@ const { Utils } = require( 'mmv.ui.ondemandshareddependencies' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'getPossibleImageSizesForHtml()', function ( assert ) {
|
||||
var utils = new Utils(),
|
||||
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 }
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
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 }
|
||||
}
|
||||
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 }
|
||||
}
|
||||
],
|
||||
i, cursize, opts;
|
||||
for ( i = 0; i < exampleSizes.length; i++ ) {
|
||||
cursize = exampleSizes[ i ];
|
||||
opts = utils.getPossibleImageSizesForHtml( cursize.width, cursize.height );
|
||||
},
|
||||
|
||||
{
|
||||
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 );
|
||||
assert.deepEqual( opts, cursize.expected, 'Size calculation for "' + cursize.test + '" gives expected results' );
|
||||
}
|
||||
} );
|
||||
|
|
|
@ -21,17 +21,16 @@ const { StripeButtons } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.ui.StripeButtons', QUnit.newMwEnvironment() );
|
||||
|
||||
function createStripeButtons() {
|
||||
var $fixture = $( '#qunit-fixture' );
|
||||
const $fixture = $( '#qunit-fixture' );
|
||||
return new StripeButtons( $fixture );
|
||||
}
|
||||
|
||||
QUnit.test( 'Sense test, object creation and UI construction', function ( assert ) {
|
||||
var buttons,
|
||||
oldMwUserIsAnon = mw.user.isAnon;
|
||||
const oldMwUserIsAnon = mw.user.isAnon;
|
||||
|
||||
// first pretend we are anonymous
|
||||
mw.user.isAnon = () => true;
|
||||
buttons = createStripeButtons();
|
||||
let buttons = createStripeButtons();
|
||||
|
||||
assert.true( buttons instanceof StripeButtons, 'UI element is created.' );
|
||||
assert.strictEqual( buttons.buttons.$descriptionPage.length, 1, 'File page button created for anon.' );
|
||||
|
@ -46,9 +45,12 @@ const { StripeButtons } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'set()/empty() sense test:', function ( assert ) {
|
||||
var buttons = createStripeButtons(),
|
||||
fakeImageInfo = { descriptionUrl: '//commons.wikimedia.org/wiki/File:Foo.jpg' },
|
||||
fakeRepoInfo = { displayName: 'Wikimedia Commons', isCommons: function () { return true; } };
|
||||
const buttons = createStripeButtons();
|
||||
const fakeImageInfo = { descriptionUrl: '//commons.wikimedia.org/wiki/File:Foo.jpg' };
|
||||
const fakeRepoInfo = {
|
||||
displayName: 'Wikimedia Commons',
|
||||
isCommons: function () { return true; }
|
||||
};
|
||||
|
||||
buttons.set( fakeImageInfo, fakeRepoInfo );
|
||||
buttons.empty();
|
||||
|
@ -57,13 +59,15 @@ const { StripeButtons } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Description page button', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
buttons = new StripeButtons( $qf ),
|
||||
$button = buttons.buttons.$descriptionPage,
|
||||
descriptionUrl = 'http://example.com/desc',
|
||||
descriptionUrl2 = 'http://example.com/different-desc',
|
||||
imageInfo = { descriptionUrl: descriptionUrl },
|
||||
repoInfo = { isCommons: function () { return false; } };
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const buttons = new StripeButtons( $qf );
|
||||
const $button = buttons.buttons.$descriptionPage;
|
||||
const descriptionUrl = 'http://example.com/desc';
|
||||
const descriptionUrl2 = 'http://example.com/different-desc';
|
||||
const imageInfo = { descriptionUrl: descriptionUrl };
|
||||
const repoInfo = {
|
||||
isCommons: function () { return false; }
|
||||
};
|
||||
|
||||
buttons.setDescriptionPageButton( imageInfo, repoInfo );
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ const { UiElement } = require( 'mmv' );
|
|||
} ) );
|
||||
|
||||
QUnit.test( 'handleEvent()', function ( assert ) {
|
||||
var element = new UiElement( $( '<div>' ) );
|
||||
const element = new UiElement( $( '<div>' ) );
|
||||
|
||||
element.handleEvent( 'mmv-foo', function () {
|
||||
assert.true( true, 'Event is handled' );
|
||||
|
@ -22,8 +22,8 @@ const { UiElement } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'setInlineStyle()', function ( assert ) {
|
||||
var element = new UiElement( $( '<div>' ) ),
|
||||
$testDiv = $( '<div>' ).attr( 'id', 'mmv-testdiv' ).text( '!!!' ).appendTo( '#qunit-fixture' );
|
||||
const element = new UiElement( $( '<div>' ) );
|
||||
const $testDiv = $( '<div>' ).attr( 'id', 'mmv-testdiv' ).text( '!!!' ).appendTo( '#qunit-fixture' );
|
||||
|
||||
assert.true( $testDiv.is( ':visible' ), 'Test div is visible' );
|
||||
|
||||
|
@ -37,10 +37,10 @@ const { UiElement } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'setTimer()/clearTimer()/resetTimer()', function ( assert ) {
|
||||
var element = new UiElement( $( '<div>' ) ),
|
||||
element2 = new UiElement( $( '<div>' ) ),
|
||||
spy = this.sandbox.spy(),
|
||||
spy2 = this.sandbox.spy();
|
||||
const element = new UiElement( $( '<div>' ) );
|
||||
const element2 = new UiElement( $( '<div>' ) );
|
||||
let spy = this.sandbox.spy();
|
||||
let spy2 = this.sandbox.spy();
|
||||
|
||||
element.setTimer( 'foo', spy, 10 );
|
||||
this.clock.tick( 100 );
|
||||
|
@ -95,7 +95,7 @@ const { UiElement } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'correctEW()', function ( assert ) {
|
||||
var element = new UiElement( $( '<div>' ) );
|
||||
const element = new UiElement( $( '<div>' ) );
|
||||
|
||||
element.isRTL = this.sandbox.stub().returns( true );
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ const { TruncatableTextField } = require( 'mmv' );
|
|||
* @return {TruncatableTextField}
|
||||
*/
|
||||
function getField( width, height, $qf, sandbox ) {
|
||||
var $container = $( '<div>' ).appendTo( $qf ),
|
||||
$element = $( '<span>' ),
|
||||
ttf = new TruncatableTextField( $container, $element, {} );
|
||||
const $container = $( '<div>' ).appendTo( $qf );
|
||||
const $element = $( '<span>' );
|
||||
const ttf = new TruncatableTextField( $container, $element, {} );
|
||||
|
||||
ttf.htmlUtils.htmlToTextWithLinks = sandbox.stub().returnsArg( 0 );
|
||||
|
||||
|
@ -47,17 +47,17 @@ const { TruncatableTextField } = require( 'mmv' );
|
|||
}
|
||||
|
||||
QUnit.test( 'Normal constructor', function ( assert ) {
|
||||
var $container = $( '#qunit-fixture' ),
|
||||
$element = $( '<div>' ).appendTo( $container ).text( 'This is a unique string.' ),
|
||||
ttf = new TruncatableTextField( $container, $element );
|
||||
const $container = $( '#qunit-fixture' );
|
||||
const $element = $( '<div>' ).appendTo( $container ).text( 'This is a unique string.' );
|
||||
const ttf = new TruncatableTextField( $container, $element );
|
||||
|
||||
assert.strictEqual( ttf.$element.text(), 'This is a unique string.', 'The constructor set the element to the right thing.' );
|
||||
assert.strictEqual( ttf.$element.closest( '#qunit-fixture' ).length, 1, 'The constructor put the element into the container.' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Set method', function ( assert ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
ttf = getField( 3, 2, $qf, this.sandbox );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const ttf = getField( 3, 2, $qf, this.sandbox );
|
||||
|
||||
ttf.shrink = this.sandbox.stub();
|
||||
ttf.set( 'abc' );
|
||||
|
|
|
@ -2,9 +2,9 @@ const { OptionsDialog } = require( 'mmv' );
|
|||
|
||||
( function () {
|
||||
function makeDialog( initialise ) {
|
||||
var $qf = $( '#qunit-fixture' ),
|
||||
$button = $( '<div>' ).appendTo( $qf ),
|
||||
dialog = new OptionsDialog( $qf, $button, { setMediaViewerEnabledOnClick: function () {} } );
|
||||
const $qf = $( '#qunit-fixture' );
|
||||
const $button = $( '<div>' ).appendTo( $qf );
|
||||
const dialog = new OptionsDialog( $qf, $button, { setMediaViewerEnabledOnClick: function () {} } );
|
||||
|
||||
if ( initialise ) {
|
||||
dialog.initPanel();
|
||||
|
@ -16,12 +16,12 @@ const { OptionsDialog } = require( 'mmv' );
|
|||
QUnit.module( 'mmv.ui.viewingOptions', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Constructor sense test', function ( assert ) {
|
||||
var dialog = makeDialog();
|
||||
const dialog = makeDialog();
|
||||
assert.true( dialog instanceof OptionsDialog, 'Dialog is created successfully' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Initialisation functions', function ( assert ) {
|
||||
var dialog = makeDialog( true );
|
||||
const dialog = makeDialog( true );
|
||||
|
||||
assert.strictEqual( dialog.$disableDiv.length, 1, 'Disable div is created.' );
|
||||
assert.strictEqual( dialog.$enableDiv.length, 1, 'Enable div is created.' );
|
||||
|
@ -30,10 +30,8 @@ const { OptionsDialog } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Disable', function ( assert ) {
|
||||
var $header, $icon, $text, $textHeader, $textBody,
|
||||
$submitButton, $cancelButton, $aboutLink,
|
||||
dialog = makeDialog(),
|
||||
deferred = $.Deferred();
|
||||
const dialog = makeDialog();
|
||||
const deferred = $.Deferred();
|
||||
|
||||
this.sandbox.stub( dialog.config, 'setMediaViewerEnabledOnClick', function () {
|
||||
return deferred;
|
||||
|
@ -41,15 +39,15 @@ const { OptionsDialog } = require( 'mmv' );
|
|||
|
||||
dialog.initDisableDiv();
|
||||
|
||||
$header = dialog.$disableDiv.find( 'h3.mw-mmv-options-dialog-header' );
|
||||
$icon = dialog.$disableDiv.find( 'div.mw-mmv-options-icon' );
|
||||
const $header = dialog.$disableDiv.find( 'h3.mw-mmv-options-dialog-header' );
|
||||
const $icon = dialog.$disableDiv.find( 'div.mw-mmv-options-icon' );
|
||||
|
||||
$text = dialog.$disableDiv.find( 'div.mw-mmv-options-text' );
|
||||
$textHeader = $text.find( 'p.mw-mmv-options-text-header' );
|
||||
$textBody = $text.find( 'p.mw-mmv-options-text-body' );
|
||||
$aboutLink = $text.find( 'a.mw-mmv-project-info-link' );
|
||||
$submitButton = dialog.$disableDiv.find( 'button.mw-mmv-options-submit-button' );
|
||||
$cancelButton = dialog.$disableDiv.find( 'button.mw-mmv-options-cancel-button' );
|
||||
const $text = dialog.$disableDiv.find( 'div.mw-mmv-options-text' );
|
||||
const $textHeader = $text.find( 'p.mw-mmv-options-text-header' );
|
||||
const $textBody = $text.find( 'p.mw-mmv-options-text-body' );
|
||||
const $aboutLink = $text.find( 'a.mw-mmv-project-info-link' );
|
||||
const $submitButton = dialog.$disableDiv.find( 'button.mw-mmv-options-submit-button' );
|
||||
const $cancelButton = dialog.$disableDiv.find( 'button.mw-mmv-options-cancel-button' );
|
||||
|
||||
assert.strictEqual( $header.length, 1, 'Disable header created successfully.' );
|
||||
assert.strictEqual( $header.text(), '(multimediaviewer-options-dialog-header)', 'Disable header has correct text (if this fails, it may be due to i18n differences)' );
|
||||
|
@ -87,10 +85,8 @@ const { OptionsDialog } = require( 'mmv' );
|
|||
} );
|
||||
|
||||
QUnit.test( 'Enable', function ( assert ) {
|
||||
var $header, $icon, $text, $textHeader, $aboutLink,
|
||||
$submitButton, $cancelButton,
|
||||
dialog = makeDialog(),
|
||||
deferred = $.Deferred();
|
||||
const dialog = makeDialog();
|
||||
const deferred = $.Deferred();
|
||||
|
||||
this.sandbox.stub( dialog.config, 'setMediaViewerEnabledOnClick', function () {
|
||||
return deferred;
|
||||
|
@ -98,14 +94,14 @@ const { OptionsDialog } = require( 'mmv' );
|
|||
|
||||
dialog.initEnableDiv();
|
||||
|
||||
$header = dialog.$enableDiv.find( 'h3.mw-mmv-options-dialog-header' );
|
||||
$icon = dialog.$enableDiv.find( 'div.mw-mmv-options-icon' );
|
||||
const $header = dialog.$enableDiv.find( 'h3.mw-mmv-options-dialog-header' );
|
||||
const $icon = dialog.$enableDiv.find( 'div.mw-mmv-options-icon' );
|
||||
|
||||
$text = dialog.$enableDiv.find( 'div.mw-mmv-options-text' );
|
||||
$textHeader = $text.find( 'p.mw-mmv-options-text-header' );
|
||||
$aboutLink = $text.find( 'a.mw-mmv-project-info-link' );
|
||||
$submitButton = dialog.$enableDiv.find( 'button.mw-mmv-options-submit-button' );
|
||||
$cancelButton = dialog.$enableDiv.find( 'button.mw-mmv-options-cancel-button' );
|
||||
const $text = dialog.$enableDiv.find( 'div.mw-mmv-options-text' );
|
||||
const $textHeader = $text.find( 'p.mw-mmv-options-text-header' );
|
||||
const $aboutLink = $text.find( 'a.mw-mmv-project-info-link' );
|
||||
const $submitButton = dialog.$enableDiv.find( 'button.mw-mmv-options-submit-button' );
|
||||
const $cancelButton = dialog.$enableDiv.find( 'button.mw-mmv-options-cancel-button' );
|
||||
|
||||
assert.strictEqual( $header.length, 1, 'Enable header created successfully.' );
|
||||
assert.strictEqual( $header.text(), '(multimediaviewer-enable-dialog-header)', 'Enable header has correct text (if this fails, it may be due to i18n differences)' );
|
||||
|
|
正在加载...
在新工单中引用