mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-25 05:22:57 +00:00
007cc5ab7c
Update the ESLint config to favor ES6 strings where variables or string concatenation is used and fix *all* offenders automatically via: eslint \ --cache \ --max-warnings 0 \ --report-unused-disable-directives \ --fix \ src tests Change-Id: I1a9345162348e5ded21d541e7a2ce251ea72ab5a
70 lines
1.4 KiB
JavaScript
70 lines
1.4 KiB
JavaScript
/**
|
|
* Creates a **minimal** stub that can be used in place of an `mw.User`
|
|
* instance.
|
|
*
|
|
* @param {boolean} isAnon The return value of the `#isAnon`.
|
|
* @return {Object}
|
|
*/
|
|
export function createStubUser( isAnon ) {
|
|
return {
|
|
isAnon() {
|
|
return isAnon;
|
|
},
|
|
sessionId() {
|
|
return '0123456789';
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a **minimal** stub that can be used in place of an `mw.Map`
|
|
* instance.
|
|
*
|
|
* @return {mw.Map}
|
|
*/
|
|
export function createStubMap() {
|
|
const m = new Map(); /* global Map */
|
|
m.get = function ( key, fallback ) {
|
|
fallback = arguments.length > 1 ? fallback : null;
|
|
if ( typeof key === 'string' ) {
|
|
return m.has( key ) ? Map.prototype.get.call( m, key ) : fallback;
|
|
}
|
|
// Invalid selection key
|
|
return null;
|
|
};
|
|
return m;
|
|
}
|
|
|
|
/**
|
|
* Creates a stub that can be used as a replacement to mw.experiements
|
|
* @param {string} bucket getBucket will respond with this bucket.
|
|
* @return {object}
|
|
*/
|
|
export function createStubExperiments( bucket ) {
|
|
return {
|
|
getBucket() {
|
|
return bucket;
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a **minimal** stub that can be used in place of an instance of
|
|
* `mw.Title`.
|
|
*
|
|
* @param {!Number} namespace
|
|
* @param {!String} prefixedDb, e.g. Foo, or File:Bar.jpg
|
|
* @return {!Object}
|
|
*/
|
|
export function createStubTitle( namespace, prefixedDb ) {
|
|
return {
|
|
namespace,
|
|
getPrefixedDb() {
|
|
return prefixedDb;
|
|
},
|
|
getUrl() {
|
|
return `/wiki/${ prefixedDb }`;
|
|
}
|
|
};
|
|
}
|