Handle user explicitly enabling/disabling feature

Follow on I4959749.

Bug: T132604
Change-Id: I4e6780f17b0423823295be9410a4343150e1e562
This commit is contained in:
Sam Smith 2016-05-19 19:04:53 +01:00
parent 8f12b9d35f
commit e9ddc8328d
2 changed files with 39 additions and 3 deletions

View file

@ -29,6 +29,17 @@
return Boolean( value ) && value !== 'false';
}
/**
* Has the user previously disabled Popups by clicking "Disable previews" in the settings
* overlay?
*
* @return {boolean}
* @ignore
*/
function hasUserDisabledFeature() {
return $.jStorage.get( 'mwe-popups-enabled' ) === 'false';
}
/**
* @class mw.popups.experiment
* @singleton
@ -54,8 +65,13 @@
config = mw.config.get( 'wgPopupsExperimentConfig' ),
result;
if (
hasUserEnabledFeature() ||
// The first two tests deal with whether the user has /explicitly/ enable or disabled via its
// settings.
if ( hasUserEnabledFeature() ) {
deferred.resolve( true );
} else if ( hasUserDisabledFeature() ) {
deferred.resolve( false );
} else if (
// Users with the beta feature enabled are already in the experimental condition.
mw.config.get( 'wgPopupsExperimentIsBetaFeatureEnabled', false )

View file

@ -11,6 +11,9 @@
}
}
},
setup: function () {
$.jStorage.deleteKey( 'mwe-popups-enabled' );
},
teardown: function () {
mw.storage.remove( 'PopupsExperimentID' );
}
@ -103,7 +106,24 @@
'If the experiment has enabled the feature, then the user is in the condition.'
);
$.jStorage.deleteKey( 'mwe-popups-enabled' );
done();
} );
} );
QUnit.test( '#isUserInCondition: user has disabled the feature', function ( assert ) {
var done = assert.async();
// 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 );
$.jStorage.set( 'mwe-popups-enabled', 'false' );
mw.popups.experiment.isUserInCondition().then( function ( result ) {
assert.strictEqual(
result,
false,
'If the experiment has enabled the feature, then the user is in the condition.'
);
done();
} );