mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-19 02:30:45 +00:00
9a94300858
For logging to work: 1. $wgWMEStatsdBaseUri needs to point to a valid statsv endpoint, e.g. 'https://en.wikipedia.org/beacon/statsv'. 2. $wgPopupsStatsvSamplingRate needs to be set. Note that the codebase already contains the EventLogging functionality, which is configured separately. Separately configuring different logging mechanisms allows us to avoid sampling mistakes that may arise while choosing one or the other. For example, let's say we want to use EventLogging for 10% of users and statsv for 5%. We'd sample all users into two buckets: 50/50. And then we'd have to set the sampling rates as 20% and 10% respectively, only because of the bucketing above. To avoid this kind of complications, separate sampling rates are used for each logging mechanism. This, of course, may result in situations where a session is logged via both EventLogging and statsv. 3. The WikimediaEvents extension needs to be installed. The extension adds the `ext.wikimediaEvents` module to the output page. The logging functionality is delegated to this module. Notable changes: * The FETCH_START and FETCH_END actions are converted to a timed action. * The experiments stub used in tests has been extracted to the stubs file. Logged data is visualized at https://grafana.wikimedia.org/dashboard/db/reading-web-page-previews Bug: T157111 Change-Id: If3f1a06f1f623e8e625b6c30a48b7f5aa9de24db
99 lines
2.9 KiB
JavaScript
99 lines
2.9 KiB
JavaScript
/* global Map: false */
|
|
|
|
var stubs = require( './stubs' ),
|
|
isEnabled = require( '../../src/isEnabled' );
|
|
|
|
function createStubUserSettings( isEnabled ) {
|
|
return {
|
|
hasIsEnabled: function () {
|
|
return isEnabled !== undefined;
|
|
},
|
|
getIsEnabled: function () {
|
|
return Boolean( isEnabled );
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
QUnit.module( 'ext.popups#isEnabled (logged out)', {
|
|
setup: function () {
|
|
this.user = stubs.createStubUser( /* isAnon = */ true );
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'is should handle logged out users', function ( assert ) {
|
|
var user = stubs.createStubUser( /* isAnon = */ true ),
|
|
cases,
|
|
i, testCase,
|
|
userSettings,
|
|
experiments,
|
|
config = new Map();
|
|
|
|
cases = [
|
|
[ undefined, true, true, 'When the user hasn\'t enabled or disabled' +
|
|
' the feature and the user is in the sample.' ],
|
|
[ undefined, false, false, 'When the user hasn\'t enabled or disabled' +
|
|
' the feature and the user is not in the sample.' ],
|
|
[ false, true, false, 'When the user has disabled the feature' +
|
|
' and the user is in the sample.'],
|
|
[ false, false, false, 'When the user has disabled the feature' +
|
|
' and the user is not in the sample.'],
|
|
[ true, true, true, 'When the user has enabled the feature' +
|
|
' and the user is in the sample.' ],
|
|
[ true, false, true, 'When the user has enabled the feature' +
|
|
' and the user is not in the sample.' ]
|
|
];
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
testCase = cases[ i ];
|
|
userSettings = createStubUserSettings( testCase[ 0 ] );
|
|
experiments = stubs.createStubExperiments( testCase[ 1 ] );
|
|
|
|
assert.equal(
|
|
isEnabled( user, userSettings, config, experiments ),
|
|
testCase[ 2 ],
|
|
testCase[ 3 ]
|
|
);
|
|
}
|
|
|
|
// ---
|
|
|
|
config.set( 'wgPopupsBetaFeature', true );
|
|
experiments = stubs.createStubExperiments( true );
|
|
|
|
assert.notOk(
|
|
isEnabled( user, userSettings, config, experiments ),
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
' enabled for logged out users when they are in the sample.'
|
|
);
|
|
|
|
experiments = stubs.createStubExperiments( false );
|
|
|
|
assert.notOk(
|
|
isEnabled( user, userSettings, config, experiments ),
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
' enabled for logged out users when they are not in the sample.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'it should handle logged in users', function ( assert ) {
|
|
var user = stubs.createStubUser( /* isAnon = */ false ),
|
|
userSettings = createStubUserSettings( false ),
|
|
experiments = stubs.createStubExperiments( true ),
|
|
config = new Map();
|
|
|
|
config.set( 'wgPopupsShouldSendModuleToUser', true );
|
|
|
|
assert.ok(
|
|
isEnabled( user, userSettings, config, experiments ),
|
|
'If the user is logged in and Page Previews has booted, then it\'s enabled.'
|
|
);
|
|
|
|
experiments = stubs.createStubExperiments( false );
|
|
assert.ok(
|
|
isEnabled( user, userSettings, config, experiments ),
|
|
'Anon sampling does not have an affect on logged in users.' +
|
|
'If the user is logged in and Page Previews has booted, then it\'s enabled.'
|
|
);
|
|
} );
|