mediawiki-skins-MinervaNeue/tests/qunit/skins.minerva.scripts/test_AB.js
Jan Drewniak e27cbf2a49 Reading depth hook should send additional sampling bucket parameter
The hook that enables the Reading depth test should send an
additional paramter that specifies which test bucket the hook
being is calling from.

Bug: T191532
Change-Id: Ifd9f43220c476ece8a0c0cee46b62b58a717c616
2018-07-31 11:40:29 +00:00

47 lines
1.2 KiB
JavaScript

( function ( M ) {
var AB = M.require( 'skins.minerva.scripts/AB' ),
util = M.require( 'mobile.startup/util' ),
defaultConfig = {
testName: 'WME.MinervaABTest',
samplingRate: 0.5,
sessionId: mw.user.generateRandomSessionId()
};
QUnit.module( 'Minerva AB-test' );
QUnit.test( 'Bucketing test', function ( assert ) {
var userBuckets = {
control: 0,
A: 0,
B: 0
},
maxUsers = 1000,
bucketingTest,
config,
i;
for ( i = 0; i < maxUsers; i++ ) {
config = util.extend( {}, defaultConfig, { sessionId: mw.user.generateRandomSessionId() } );
bucketingTest = new AB( config );
userBuckets[ bucketingTest.getBucket() ] += 1;
}
assert.strictEqual(
( userBuckets.control / maxUsers > 0.4 ) &&
( userBuckets.control / maxUsers < 0.6 ),
true, 'test control group is about 50% (' + userBuckets.control / 10 + '%)' );
assert.strictEqual(
( userBuckets.A / maxUsers > 0.2 ) &&
( userBuckets.A / maxUsers < 0.3 ),
true, 'test group A is about 25% (' + userBuckets.A / 10 + '%)' );
assert.strictEqual(
( userBuckets.B / maxUsers > 0.2 ) &&
( userBuckets.B / maxUsers < 0.3 ),
true, 'test group B is about 25% (' + userBuckets.B / 10 + '%)' );
} );
}( mw.mobileFrontend ) );