2016-12-14 13:48:20 +00:00
|
|
|
( function ( mw ) {
|
|
|
|
|
2016-12-21 12:35:35 +00:00
|
|
|
function createStubUserSettings( isEnabled ) {
|
2016-12-14 13:48:20 +00:00
|
|
|
return {
|
|
|
|
hasIsEnabled: function () {
|
2016-12-21 12:35:35 +00:00
|
|
|
return isEnabled !== undefined;
|
2016-12-14 13:48:20 +00:00
|
|
|
},
|
|
|
|
getIsEnabled: function () {
|
2016-12-21 12:35:35 +00:00
|
|
|
return Boolean(isEnabled);
|
2016-12-14 13:48:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:35:35 +00:00
|
|
|
QUnit.module( 'ext.popups#isEnabled (logged out)', {
|
|
|
|
setup: function () {
|
|
|
|
this.user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ true );
|
|
|
|
}
|
2016-12-14 13:48:20 +00:00
|
|
|
} );
|
|
|
|
|
2016-12-21 12:35:35 +00:00
|
|
|
QUnit.test( 'is should handle logged out users', function ( assert ) {
|
2016-12-14 13:48:20 +00:00
|
|
|
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ true ),
|
2016-12-21 12:35:35 +00:00
|
|
|
cases,
|
|
|
|
userSettings,
|
|
|
|
config = new mw.Map();
|
|
|
|
|
|
|
|
cases = [
|
|
|
|
[ undefined, true, 'When the user hasn\'t enabled or disabled the feature' ],
|
|
|
|
[ false, false, 'When the user has disabled the feature' ],
|
|
|
|
[ true, true, 'When the user has enabled the feature' ]
|
|
|
|
];
|
|
|
|
|
|
|
|
$.each( cases, function ( _, testCase ) {
|
|
|
|
userSettings = createStubUserSettings( testCase[ 0 ] );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
mw.popups.isEnabled( user, userSettings, config ),
|
|
|
|
testCase[ 1 ],
|
|
|
|
testCase[ 2 ]
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
config.set( 'wgPopupsBetaFeature', true );
|
2016-12-14 13:48:20 +00:00
|
|
|
|
|
|
|
assert.notOk(
|
2016-12-21 12:35:35 +00:00
|
|
|
mw.popups.isEnabled( user, userSettings, config ),
|
|
|
|
'When Page Previews is enabled as a beta feature, then it\'s not enabled for logged out users.'
|
2016-12-14 13:48:20 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-12-21 12:35:35 +00:00
|
|
|
QUnit.test( 'it should handle logged in users', function ( assert ) {
|
2016-12-14 13:48:20 +00:00
|
|
|
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ false ),
|
2016-12-21 12:35:35 +00:00
|
|
|
userSettings = createStubUserSettings( false ),
|
|
|
|
config = new mw.Map();
|
2016-12-14 13:48:20 +00:00
|
|
|
|
2016-12-21 12:35:35 +00:00
|
|
|
config.set( 'wgPopupsIsEnabledByUser', true );
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
mw.popups.isEnabled( user, userSettings, config ),
|
|
|
|
'If the user is logged in and Page Previews has booted, then it\'s enabled.'
|
|
|
|
);
|
2016-12-14 13:48:20 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
}( mediaWiki ) );
|