mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-28 09:20:31 +00:00
35bf613964
Action changes: * Include the namespace ID in LINK_DWELL. Reducer changes: * Add the createEvent helper, which adds the pageTitleHover and namespaceIdHover properties in the event. * Create "dismissed", "dwelledButAbandoned", and "opened" events using the createEvent helper. Additional changes: * Store the target page's associated mw.Title using jQuery. * Update the eventLogging reducer's test cases so that all LINK_DWELL representations include title and namespaceID attributes. * Create the createStubTitle factory function, which returns a minimal usable mw.Title stub, and use it in the actions and integration test cases. Bug: T164256 Change-Id: I8a63d82a65324680dff9176020a8ea97695428c4
68 lines
1.5 KiB
JavaScript
68 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}
|
|
*/
|
|
exports.createStubUser = function createStubUser( isAnon ) {
|
|
return {
|
|
isAnon: function () {
|
|
return isAnon;
|
|
},
|
|
sessionId: function () {
|
|
return '0123456789';
|
|
}
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Creates a **minimal** stub that can be used in place of an `mw.Map`
|
|
* instance.
|
|
*
|
|
* @return {mw.Map}
|
|
*/
|
|
exports.createStubMap = function createStubMap() {
|
|
var 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 {bool} isSampled If `true` then the `getBucket` method will
|
|
* return 'A' otherwise 'control'.
|
|
* @return {object}
|
|
*/
|
|
exports.createStubExperiments = function createStubExperiments( isSampled ) {
|
|
return {
|
|
getBucket: function () {
|
|
return isSampled ? 'A' : 'control';
|
|
}
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Creates a **minimal** stub that can be used in place of an instance of
|
|
* `mw.Title`.
|
|
*
|
|
* @param {Number} namespace
|
|
* @param {String} prefixedText e.g. Foo, or File:Bar.jpg
|
|
* @return {Object}
|
|
*/
|
|
exports.createStubTitle = function createStubTitle( namespace, prefixedText ) {
|
|
return {
|
|
namespace: namespace,
|
|
getPrefixedText: function () {
|
|
return prefixedText;
|
|
}
|
|
};
|
|
};
|