mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-17 20:41:32 +00:00
e4e9bb3bd6
Introduce PopupsAnonsExperimentalGroupSize config variable. This defines a population size who will be subject to experimentation. If the group size is undefined or 0 (default) and PopupsBetaFeature is false (default value) Popups will be enabled for everyone. If it is any other value, half that group will see page previews. Drop the config variable PopupsSchemaSamplingRate - we will now only EventLog when an experiment is occuring. This means we can simplify the MWEventLogger class as shouldLog will always be truthy. Given server side eventlogging is only used for preference changes traffic should be low and not need sampling. Introduce getUserBucket which determines whether a user is in a bucket on, off or control based on the value of PopupsAnonsExperimentalGroupSize. Add tests showing how these buckets are calculated. Caution: A kill switch wgPopupsEventLogging is provided for safety. It defaults to false. Before merging, please check if any config changes are necessary. Bug: T171853 Change-Id: If2a0c5fceae78262c44cb522af38a925cc5919d3
123 lines
3.7 KiB
JavaScript
123 lines
3.7 KiB
JavaScript
/* global Map: false */
|
|
|
|
import * as stubs from './stubs';
|
|
import isEnabled from '../../src/isEnabled';
|
|
import { BUCKETS } from '../../src/constants';
|
|
|
|
function createStubUserSettings( isEnabled ) {
|
|
return {
|
|
hasIsEnabled: function () {
|
|
return isEnabled !== undefined;
|
|
},
|
|
getIsEnabled: function () {
|
|
return Boolean( isEnabled );
|
|
}
|
|
};
|
|
}
|
|
|
|
QUnit.module( 'ext.popups#isEnabled (logged out)', {
|
|
beforeEach: 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,
|
|
config = new Map();
|
|
|
|
cases = [
|
|
/*
|
|
[
|
|
<isAnon>, <bucket>, <expected value of isEnabled>, <test description>
|
|
]
|
|
*/
|
|
[ undefined, BUCKETS.on, true, 'When the user hasn\'t enabled or disabled' +
|
|
' the feature and the user is in the sample.' ],
|
|
[ undefined, BUCKETS.control, false, 'When the user hasn\'t enabled or disabled' +
|
|
' the feature and the user is not in the sample.' ],
|
|
[ false, BUCKETS.on, false, 'When the user has disabled the feature' +
|
|
' and the user is in the sample.' ],
|
|
[ false, BUCKETS.control, false, 'When the user has disabled the feature' +
|
|
' and the user is not in the sample.' ],
|
|
[ true, BUCKETS.on, true, 'When the user has enabled the feature' +
|
|
' and the user is in the sample.' ],
|
|
[ true, BUCKETS.control, 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 ] );
|
|
|
|
assert.equal(
|
|
isEnabled( user, userSettings, config, testCase[ 1 ] ),
|
|
testCase[ 2 ],
|
|
testCase[ 3 ]
|
|
);
|
|
}
|
|
|
|
// ---
|
|
|
|
config.set( 'wgPopupsBetaFeature', true );
|
|
|
|
assert.notOk(
|
|
isEnabled( user, userSettings, config, BUCKETS.on ),
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
' enabled for logged out users when they are in the on group.'
|
|
);
|
|
|
|
assert.notOk(
|
|
isEnabled( user, userSettings, config, BUCKETS.control ),
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
' enabled for logged out users when they are not in the control group.'
|
|
);
|
|
|
|
assert.notOk(
|
|
isEnabled( user, userSettings, config, BUCKETS.off ),
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
' enabled for logged out users when they are in the off group.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'it should handle logged in users', function ( assert ) {
|
|
var user = stubs.createStubUser( /* isAnon = */ false ),
|
|
userSettings = createStubUserSettings( false ),
|
|
config = new Map();
|
|
|
|
config.set( 'wgPopupsShouldSendModuleToUser', true );
|
|
|
|
assert.ok(
|
|
isEnabled( user, userSettings, config, BUCKETS.on ),
|
|
'If the user is logged in and the user is in the on group, then it\'s enabled.'
|
|
);
|
|
|
|
assert.ok(
|
|
isEnabled( user, userSettings, config, BUCKETS.control ),
|
|
'Bucket does not have an affect on logged in users.' +
|
|
'If the user is logged in and they are in the control group it\'s still enabled.'
|
|
);
|
|
|
|
assert.ok(
|
|
isEnabled( user, userSettings, config, BUCKETS.off ),
|
|
'Bucket does not have an affect on logged in users.' +
|
|
'If the user is logged in and the user is bucketed as off then it\'s still enabled.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'it should handle the conflict with the Navigation Popups Gadget', function ( assert ) {
|
|
var user = stubs.createStubUser( /* isAnon = */ false ),
|
|
userSettings = createStubUserSettings( false ),
|
|
config = new Map();
|
|
|
|
config.set( 'wgPopupsConflictsWithNavPopupGadget', true );
|
|
|
|
assert.notOk(
|
|
isEnabled( user, userSettings, config, BUCKETS.on ),
|
|
'Page Previews is disabled when it conflicts with the Navigation Popups Gadget.'
|
|
);
|
|
|
|
} );
|