2016-05-13 20:15:36 +00:00
|
|
|
( function ( mw ) {
|
2016-05-13 12:25:39 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups.experiment', QUnit.newMwEnvironment( {
|
|
|
|
config: {
|
|
|
|
wgPopupsExperimentConfig: {
|
|
|
|
name: 'Popups A/B Test - May, 2016',
|
|
|
|
enabled: true,
|
|
|
|
buckets: {
|
|
|
|
control: 0.5,
|
|
|
|
A: 0.5
|
|
|
|
}
|
2016-05-19 20:04:14 +00:00
|
|
|
},
|
|
|
|
wgPopupsExperimentIsBetaFeatureEnabled: null
|
2016-05-13 12:25:39 +00:00
|
|
|
},
|
2016-05-19 18:04:53 +00:00
|
|
|
setup: function () {
|
2016-09-20 15:22:08 +00:00
|
|
|
// As anon user by default
|
|
|
|
this.sandbox.stub( mw.user, 'isAnon', function () { return true; } );
|
2016-05-13 20:15:36 +00:00
|
|
|
mw.storage.remove( 'mwe-popups-enabled' );
|
2016-05-19 18:04:53 +00:00
|
|
|
},
|
2016-05-13 12:25:39 +00:00
|
|
|
teardown: function () {
|
|
|
|
mw.storage.remove( 'PopupsExperimentID' );
|
|
|
|
}
|
|
|
|
} ) );
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
QUnit.test( '#isUserInCondition: user has beta feature enabled', 1, function ( assert ) {
|
2016-09-20 15:22:08 +00:00
|
|
|
// Be logged in for the beta feature test
|
|
|
|
mw.user.isAnon.restore();
|
|
|
|
this.sandbox.stub( mw.user, 'isAnon', function () { return false; } );
|
|
|
|
|
2016-05-13 12:25:39 +00:00
|
|
|
mw.config.set( 'wgPopupsExperimentConfig', null );
|
|
|
|
mw.config.set( 'wgPopupsExperimentIsBetaFeatureEnabled', true );
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
mw.popups.experiment.isUserInCondition(),
|
|
|
|
true,
|
|
|
|
'If the user has the beta feature enabled, then they aren\'t in the condition.'
|
|
|
|
);
|
2016-05-13 12:25:39 +00:00
|
|
|
} );
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
QUnit.test( '#isUserInCondition', 2, function ( assert ) {
|
2016-05-13 12:25:39 +00:00
|
|
|
var getBucketSpy = this.sandbox.stub( mw.experiments, 'getBucket' ).returns( 'A' ),
|
|
|
|
config = mw.config.get( 'wgPopupsExperimentConfig' ),
|
2016-05-19 20:04:14 +00:00
|
|
|
result,
|
|
|
|
firstCallArgs;
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
result = mw.popups.experiment.isUserInCondition();
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
firstCallArgs = getBucketSpy.firstCall.args;
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
firstCallArgs[ 0 ],
|
|
|
|
config,
|
|
|
|
'The Popups experiment config is used when bucketing the user.'
|
|
|
|
);
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
result,
|
|
|
|
true,
|
|
|
|
'If the user isn\'t in the control bucket, then they are in the condition.'
|
|
|
|
);
|
2016-05-13 12:25:39 +00:00
|
|
|
} );
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
QUnit.test( '#isUserInCondition: token is persisted', 1, function ( assert ) {
|
2016-05-13 12:25:39 +00:00
|
|
|
var token = '1234567890',
|
2016-05-19 20:04:14 +00:00
|
|
|
setSpy = this.sandbox.spy( mw.storage, 'set' );
|
2016-05-13 12:25:39 +00:00
|
|
|
|
|
|
|
this.sandbox.stub( mw.user, 'generateRandomSessionId' ).returns( token );
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
mw.popups.experiment.isUserInCondition();
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
setSpy.firstCall.args[ 1 ],
|
|
|
|
token,
|
|
|
|
'The token is persisted transparently.'
|
|
|
|
);
|
2016-05-13 12:25:39 +00:00
|
|
|
} );
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
QUnit.test( '#isUserInCondition: experiment isn\'t configured', 1, function ( assert ) {
|
2016-05-13 12:25:39 +00:00
|
|
|
mw.config.set( 'wgPopupsExperimentConfig', null );
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
mw.popups.experiment.isUserInCondition(),
|
|
|
|
false,
|
|
|
|
'If the experiment isn\'t configured, then the user isn\'t in the condition.'
|
|
|
|
);
|
2016-05-13 12:25:39 +00:00
|
|
|
} );
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
QUnit.test( '#isUserInCondition: user has enabled the feature', 1, function ( assert ) {
|
2016-05-13 20:15:36 +00:00
|
|
|
mw.storage.set( 'mwe-popups-enabled', '1' );
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
mw.popups.experiment.isUserInCondition(),
|
|
|
|
true,
|
|
|
|
'If the experiment has enabled the feature, then the user is in the condition.'
|
|
|
|
);
|
2016-05-19 18:04:53 +00:00
|
|
|
} );
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
QUnit.test( '#isUserInCondition: user has disabled the feature', 1, function ( assert ) {
|
2016-05-19 18:04:53 +00:00
|
|
|
// This should be read as follows: the user has enabled the beta feature but has since
|
|
|
|
// disabled the feature via its settings.
|
|
|
|
mw.config.set( 'wgPopupsExperimentIsBetaFeatureEnabled', true );
|
2016-05-13 20:15:36 +00:00
|
|
|
mw.storage.set( 'mwe-popups-enabled', '0' );
|
2016-05-19 18:04:53 +00:00
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
mw.popups.experiment.isUserInCondition(),
|
|
|
|
false,
|
|
|
|
'If the experiment has enabled the feature, then the user is in the condition.'
|
|
|
|
);
|
2016-05-13 12:25:39 +00:00
|
|
|
} );
|
|
|
|
|
2016-05-13 20:15:36 +00:00
|
|
|
}( mediaWiki ) );
|