Merge "Hygiene: Make mw.popups#isEnabled return boolean" into mpga

This commit is contained in:
jenkins-bot 2016-12-16 19:48:10 +00:00 committed by Gerrit Code Review
commit 397d3e8bc2
8 changed files with 23 additions and 33 deletions

View file

@ -52,7 +52,7 @@
* [`mw.requestIdleCallback`](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback))
* so as not to impact latency-critical events.
*
* @param {Function} isUserInCondition See `mw.popups.createExperiment`
* @param {Boolean} isEnabled See `mw.popups.isEnabled`
* @param {mw.user} user
* @param {ext.popups.UserSettings} userSettings
* @param {Function} generateToken
@ -61,7 +61,7 @@
* @returns {Object}
*/
actions.boot = function (
isUserInCondition,
isEnabled,
user,
userSettings,
generateToken,
@ -72,6 +72,7 @@
return {
type: types.BOOT,
isEnabled: isEnabled,
sessionToken: user.sessionId(),
pageToken: generateToken(),
page: {
@ -80,7 +81,6 @@
id: config.get( 'wgArticleId' )
},
user: {
isInCondition: isUserInCondition(),
isAnon: user.isAnon(),
editCount: editCount,
previewCount: previewCount

View file

@ -17,17 +17,15 @@
* @param {Object} userSettings An object returned by
* `mw.popups.createUserSettings`
*
* @return {Function}
* @return {Boolean}
*/
mw.popups.isEnabled = function ( user, userSettings ) {
return function () {
if ( user.isAnon() ) {
return false;
}
if ( user.isAnon() ) {
return false;
}
return !userSettings.hasIsEnabled() ||
( userSettings.hasIsEnabled() && userSettings.getIsEnabled() );
};
return !userSettings.hasIsEnabled() ||
( userSettings.hasIsEnabled() && userSettings.getIsEnabled() );
};
}( mediaWiki ) );

View file

@ -41,7 +41,7 @@
namespaceIdSource: action.page.namespaceID,
pageIdSource: action.page.id,
isAnon: action.user.isAnon,
popupEnabled: action.user.isInCondition,
popupEnabled: action.isEnabled,
pageToken: action.pageToken,
sessionToken: action.sessionToken,
editCountBucket: popups.counts.getEditCountBucket( action.user.editCount ),

View file

@ -22,7 +22,7 @@
switch ( action.type ) {
case popups.actionTypes.BOOT:
return nextState( state, {
enabled: action.user.isInCondition
enabled: action.isEnabled
} );
case popups.actionTypes.SETTINGS_CHANGE:
return nextState( state, {

View file

@ -7,10 +7,7 @@
QUnit.module( 'ext.popups/actions' );
QUnit.test( '#boot', function ( assert ) {
var isUserInCondition = function () {
return false;
},
config = new mw.Map(),
var config = new mw.Map(),
stubUser = mw.popups.tests.stubs.createStubUser( /* isAnon = */ true ),
stubUserSettings,
action;
@ -31,7 +28,7 @@
assert.expect( 1 );
action = mw.popups.actions.boot(
isUserInCondition,
false,
stubUser,
stubUserSettings,
generateToken,
@ -42,6 +39,7 @@
action,
{
type: 'BOOT',
isEnabled: false,
sessionToken: '0123456789',
pageToken: '9876543210',
page: {
@ -50,7 +48,6 @@
id: 2
},
user: {
isInCondition: false,
isAnon: true,
editCount: 3,
previewCount: 22

View file

@ -15,29 +15,26 @@
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 );
userSettings = createStubUserSettings( /* hasIsEnabled = */ true );
assert.ok( isEnabled() );
assert.ok( mw.popups.isEnabled( user, userSettings ) );
} );
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 );
userSettings = createStubUserSettings( /* hasIsEnabled = */ true );
assert.notOk(
isEnabled(),
mw.popups.isEnabled( user, userSettings ),
'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 );
userSettings = createStubUserSettings( /* hasIsEnabled = */ false );
assert.ok( isEnabled() );
assert.ok( mw.popups.isEnabled( user, userSettings ) );
} );
}( mediaWiki ) );

View file

@ -25,6 +25,7 @@
QUnit.test( 'BOOT', function ( assert ) {
var action = {
type: 'BOOT',
isEnabled: true,
sessionToken: '0123456789',
pageToken: '9876543210',
page: {
@ -33,7 +34,6 @@
id: 2
},
user: {
isInCondition: true,
isAnon: false,
editCount: 11,
previewCount: 22
@ -54,7 +54,7 @@
namespaceIdSource: action.page.namespaceID,
pageIdSource: action.page.id,
isAnon: action.user.isAnon,
popupEnabled: action.user.isInCondition,
popupEnabled: action.isEnabled,
pageToken: action.pageToken,
sessionToken: action.sessionToken,
editCountBucket: expectedEditCountBucket,

View file

@ -26,9 +26,7 @@
QUnit.test( 'BOOT', function ( assert ) {
var action = {
type: 'BOOT',
user: {
isInCondition: true
}
isEnabled: true
};
assert.expect( 1 );