mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-17 19:21:39 +00:00
2163d5f965
Updates QUnit test files from starting with "test_" to ending with "test.js" in accordance with the Readers Wed coding conventions. https://www.mediawiki.org/wiki/Reading/Web/Coding_conventions Bug: T197884 Change-Id: I98877e3fc432b6edd0c53d834ef23b3ef8fb7d6a
57 lines
1.4 KiB
JavaScript
57 lines
1.4 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 );
|
|
if ( bucketingTest.isA() ) {
|
|
++userBuckets.A;
|
|
} else if ( bucketingTest.isB() ) {
|
|
++userBuckets.B;
|
|
} else if ( !bucketingTest.isEnabled() ) {
|
|
++userBuckets.control;
|
|
} else {
|
|
throw new Error( 'Unknown bucket!' );
|
|
}
|
|
}
|
|
|
|
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 ) );
|