mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-15 03:34:03 +00:00
Handle user explicitly enabling/disabling feature
Follow on I4959749. Bug: T132604 Change-Id: I4e6780f17b0423823295be9410a4343150e1e562
This commit is contained in:
parent
8f12b9d35f
commit
e9ddc8328d
|
@ -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 )
|
||||
|
|
|
@ -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();
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue