mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 23:24:39 +00:00
0b2961c318
ext.popups.experiment depends on .core as it initialized the mw.popups namespace and .core depends on .experiments for mw.popups#getEnabledState. By merging the experiment module into core, we can eliminate any circular dependencies. Changes: * Move ext.popups.experiment.js code into ext.popups.core.js * Remove mw.popups.experiment module and any references to it Note: ext.popups.experiment.test.js was left in its own file for cleaner QUnit module setups and easier removal later. I'm not entirely happy with doing it this way, but I'm not sure changing the mw.config within the mw.popups.core QUnit module is worth merging the files. Bug: T146035 Change-Id: I1f024567010acaa61c1d613c6e59c998198a5976
112 lines
3.1 KiB
JavaScript
112 lines
3.1 KiB
JavaScript
( function ( mw ) {
|
|
|
|
QUnit.module( 'ext.popups.core:experiment', QUnit.newMwEnvironment( {
|
|
config: {
|
|
wgPopupsExperimentConfig: {
|
|
name: 'Popups A/B Test - May, 2016',
|
|
enabled: true,
|
|
buckets: {
|
|
control: 0.5,
|
|
A: 0.5
|
|
}
|
|
},
|
|
wgPopupsExperimentIsBetaFeatureEnabled: null
|
|
},
|
|
setup: function () {
|
|
// As anon user by default
|
|
this.sandbox.stub( mw.user, 'isAnon', function () { return true; } );
|
|
mw.storage.remove( 'mwe-popups-enabled' );
|
|
},
|
|
teardown: function () {
|
|
mw.storage.remove( 'PopupsExperimentID' );
|
|
}
|
|
} ) );
|
|
|
|
QUnit.test( '#isUserInCondition: user has beta feature enabled', 1, function ( assert ) {
|
|
// Be logged in for the beta feature test
|
|
mw.user.isAnon.restore();
|
|
this.sandbox.stub( mw.user, 'isAnon', function () { return false; } );
|
|
|
|
mw.config.set( 'wgPopupsExperimentConfig', null );
|
|
mw.config.set( 'wgPopupsExperimentIsBetaFeatureEnabled', true );
|
|
|
|
assert.strictEqual(
|
|
mw.popups.isUserInCondition(),
|
|
true,
|
|
'If the user has the beta feature enabled, then they aren\'t in the condition.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( '#isUserInCondition', 2, function ( assert ) {
|
|
var getBucketSpy = this.sandbox.stub( mw.experiments, 'getBucket' ).returns( 'A' ),
|
|
config = mw.config.get( 'wgPopupsExperimentConfig' ),
|
|
result,
|
|
firstCallArgs;
|
|
|
|
result = mw.popups.isUserInCondition();
|
|
|
|
firstCallArgs = getBucketSpy.firstCall.args;
|
|
|
|
assert.deepEqual(
|
|
firstCallArgs[ 0 ],
|
|
config,
|
|
'The Popups experiment config is used when bucketing the user.'
|
|
);
|
|
|
|
assert.strictEqual(
|
|
result,
|
|
true,
|
|
'If the user isn\'t in the control bucket, then they are in the condition.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( '#isUserInCondition: token is persisted', 1, function ( assert ) {
|
|
var token = '1234567890',
|
|
setSpy = this.sandbox.spy( mw.storage, 'set' );
|
|
|
|
this.sandbox.stub( mw.user, 'generateRandomSessionId' ).returns( token );
|
|
|
|
mw.popups.isUserInCondition();
|
|
|
|
assert.deepEqual(
|
|
setSpy.firstCall.args[ 1 ],
|
|
token,
|
|
'The token is persisted transparently.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( '#isUserInCondition: experiment isn\'t configured', 1, function ( assert ) {
|
|
mw.config.set( 'wgPopupsExperimentConfig', null );
|
|
|
|
assert.strictEqual(
|
|
mw.popups.isUserInCondition(),
|
|
false,
|
|
'If the experiment isn\'t configured, then the user isn\'t in the condition.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( '#isUserInCondition: user has enabled the feature', 1, function ( assert ) {
|
|
mw.storage.set( 'mwe-popups-enabled', '1' );
|
|
|
|
assert.strictEqual(
|
|
mw.popups.isUserInCondition(),
|
|
true,
|
|
'If the experiment has enabled the feature, then the user is in the condition.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( '#isUserInCondition: user has disabled the feature', 1, function ( assert ) {
|
|
// 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 );
|
|
mw.storage.set( 'mwe-popups-enabled', '0' );
|
|
|
|
assert.strictEqual(
|
|
mw.popups.isUserInCondition(),
|
|
false,
|
|
'If the experiment has enabled the feature, then the user is in the condition.'
|
|
);
|
|
} );
|
|
|
|
}( mediaWiki ) );
|