mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-15 19:50:04 +00:00
53d1a2c329
Currently the Popups schema is disabled but if we were to re-enable it, the page tokens would now be consistent with the ReadingDepth schema The getToken function is kept to allow generation of the pageInteractionToken's relating to a link interaction, for which there is no centralised API. Additional changes: * I've updated various tests to use the central mw.user stub to make clearer where tokens come from. Bug: T203013 Change-Id: If746bea5aeed2b4c192a9b8a02feb1fe06480633
73 lines
1.5 KiB
JavaScript
73 lines
1.5 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 {
|
|
getPageviewToken() {
|
|
return '9876543210';
|
|
},
|
|
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 }`;
|
|
}
|
|
};
|
|
}
|