mediawiki-extensions-Popups/tests/qunit/ext.popups/isEnabled.test.js
Sam Smith a6423fbc75 Redefine when Page Previews are enabled
The Page Previews A/B test was disabled in T144490. After the changes
for that task had been deployed we discovered that the old definition
for when previews are enabled was invalid.

Previews are enabled:
* If the beta feature is enabled and the user has enabled the beta
  feature.
* The user hasn't disabled previews via the settings modal.
* And soon, if the beta feature is disabled and the user hasn't disabled
  previews via their user preferences (see T146889).

Changes:
* mw.popups#createExperiment -> mw.popups#isEnabled
* Make mw.popups#isEnabled act like a factory to maintain backwards
  compatibility.
* Update the associated tests.

Bug: T152687
Change-Id: I713a90dfb29866b27738e7d19e8a22518a12d417
2016-12-16 10:35:55 +00:00

44 lines
1.3 KiB
JavaScript

( function ( mw ) {
function createStubUserSettings( hasIsEnabled ) {
return {
hasIsEnabled: function () {
return hasIsEnabled;
},
getIsEnabled: function () {
return true;
}
};
}
QUnit.module( 'ext.popups#isEnabled' );
QUnit.test( 'it should return true when the user has enabled it via UI interactions', function ( assert ) {
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ false ),
userSettings = createStubUserSettings( /* hasIsEnabled = */ true ),
isEnabled = mw.popups.isEnabled( user, userSettings );
assert.ok( isEnabled() );
} );
QUnit.test( 'it should return false if the user is an anon', function ( assert ) {
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ true ),
userSettings = createStubUserSettings( /* hasIsEnabled = */ true ),
isEnabled = mw.popups.isEnabled( user, userSettings );
assert.notOk(
isEnabled(),
'It should return false even if the user has enabled it via UI interactions.'
);
} );
QUnit.test( 'it should return true if the user hasn\'t disabled it via UI interactions', function ( assert ) {
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ false ),
userSettings = createStubUserSettings( /* hasIsEnabled = */ false ),
isEnabled = mw.popups.isEnabled( user, userSettings );
assert.ok( isEnabled() );
} );
}( mediaWiki ) );