mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-03 03:36:41 +00:00
19349c0108
Changes: * Make grunt:qunit run all QUnit tests in those modules whose names being with "ext.popups". * Add ext.popups/index.js, which initialises the mw.popups namespace. * Add ext.popups/userSettings.js, which contains the code that deals with interacting with the User Agent's storage. * Add ext.popups/experiment.js, which contains the code that that decides whether or not the user is in the experiment condition. * Add tests for both units, converting existing tests where appropriate. * Remove the associated code from ext.popups.core/ext.popups.core.js. * Finally, dispatch the BOOT action against the store in ext.popups/boot.js. Change-Id: I697207677304bd49c7cfe1d37bb0a4af7810f387
100 lines
2.7 KiB
JavaScript
100 lines
2.7 KiB
JavaScript
( function ( mw ) {
|
|
|
|
function createStubUser( isAnon ) {
|
|
return {
|
|
isAnon: function () {
|
|
return isAnon;
|
|
}
|
|
};
|
|
}
|
|
|
|
function createStubUserSettings( hasIsEnabled ) {
|
|
return {
|
|
getToken: function () {
|
|
return '1234567890';
|
|
},
|
|
hasIsEnabled: function () {
|
|
return hasIsEnabled;
|
|
},
|
|
getIsEnabled: function () {
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
|
|
QUnit.module( 'ext.popups/experiment', {
|
|
setup: function () {
|
|
this.config = new mw.Map();
|
|
this.user = createStubUser( /* isAnon = */ true );
|
|
this.userSettings = createStubUserSettings( /* hasIsEnabled = */ false );
|
|
this.isUserInCondition = mw.popups.createExperiment( this.config, this.user, this.userSettings );
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'is should return false if the experiment is disabled', 1, function ( assert ) {
|
|
this.config.set( 'wgPopupsExperiment', false );
|
|
|
|
assert.notOk( this.isUserInCondition() );
|
|
} );
|
|
|
|
QUnit.test( '#isUserInCondition', 2, function ( assert ) {
|
|
var user = createStubUser( /* isAnon = */ false ),
|
|
isUserInCondition = mw.popups.createExperiment( this.config, user, this.userSettings );
|
|
|
|
this.config.set( {
|
|
wgPopupsExperiment: true,
|
|
wgPopupsExperimentIsBetaFeatureEnabled: true
|
|
} );
|
|
|
|
assert.ok(
|
|
isUserInCondition(),
|
|
'If the user has the beta feature enabled, then they are in the condition.'
|
|
);
|
|
|
|
// ---
|
|
|
|
this.config.set( 'wgPopupsExperimentIsBetaFeatureEnabled', false );
|
|
|
|
assert.notOk(
|
|
isUserInCondition(),
|
|
'If the user has the beta feature disabled, then they aren\'t in the condition.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'it should bucket the user', 2, function ( assert ) {
|
|
var experimentConfig = {
|
|
name: 'Popups A/B Test - May, 2016',
|
|
enabled: true,
|
|
buckets: {
|
|
control: 0.5,
|
|
A: 0.5
|
|
}
|
|
},
|
|
getBucketSpy = this.sandbox.stub( mw.experiments, 'getBucket' ).returns( 'A' );
|
|
|
|
this.config.set( {
|
|
wgPopupsExperiment: true,
|
|
wgPopupsExperimentConfig: experimentConfig
|
|
} );
|
|
|
|
assert.ok( this.isUserInCondition() );
|
|
assert.deepEqual( getBucketSpy.firstCall.args[0], experimentConfig );
|
|
} );
|
|
|
|
QUnit.test( 'it should return false if the experiment isn\'t configured', 1, function ( assert ) {
|
|
this.config.set( 'wgPopupsExperiment', true );
|
|
|
|
assert.notOk( this.isUserInCondition() );
|
|
} );
|
|
|
|
QUnit.test( 'it shouldn\'t bucket the user if they have enabled or disabled Link Previews', 2, function ( assert ) {
|
|
var userSettings = createStubUserSettings( /* hasIsEnabled = */ true ),
|
|
getIsEnabledSpy = this.sandbox.spy( userSettings, 'getIsEnabled' ),
|
|
isUserInCondition = mw.popups.createExperiment( this.config, this.user, userSettings );
|
|
|
|
assert.ok( isUserInCondition() );
|
|
assert.strictEqual( 1, getIsEnabledSpy.callCount );
|
|
} );
|
|
|
|
}( mediaWiki ) );
|