mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-18 21:05:57 +00:00
765aa40cc1
Use the standardised MediaWiki storage system for the simple use case of disabling/enabling Popups. The jStorage library is 12kb uncompressed and cannot be justified for this usage (and if it becomes the standardised library mw.storage will begin using it) This means that browsers with full localStorage or no localStorage support will not be able to disable Popups. Given the current ecosystem of the web - localStorage is widely supported - and the fact that grade A browsers enjoy localStorage support - this is not a problem. See https://github.com/wikimedia/mediawiki/blob/REL1_27/resources/src/startup.js#L59 Changes: * Stop using jStorage * Cleanup and migrate previous values in jStorage with plan for removing this in a month. Bug: T136241 Change-Id: I6dac2911e84d6cb20731be34add01576cf407c46
106 lines
2.9 KiB
JavaScript
106 lines
2.9 KiB
JavaScript
( function ( mw ) {
|
|
|
|
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
|
|
}
|
|
},
|
|
wgPopupsExperimentIsBetaFeatureEnabled: null
|
|
},
|
|
setup: function () {
|
|
mw.storage.remove( 'mwe-popups-enabled' );
|
|
},
|
|
teardown: function () {
|
|
mw.storage.remove( 'PopupsExperimentID' );
|
|
}
|
|
} ) );
|
|
|
|
QUnit.test( '#isUserInCondition: user has beta feature enabled', 1, function ( assert ) {
|
|
mw.config.set( 'wgPopupsExperimentConfig', null );
|
|
mw.config.set( 'wgPopupsExperimentIsBetaFeatureEnabled', true );
|
|
|
|
assert.strictEqual(
|
|
mw.popups.experiment.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.experiment.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.experiment.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.experiment.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.experiment.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.experiment.isUserInCondition(),
|
|
false,
|
|
'If the experiment has enabled the feature, then the user is in the condition.'
|
|
);
|
|
} );
|
|
|
|
}( mediaWiki ) );
|