mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-09-23 10:21:11 +00:00
Merge "Hygiene: Make mw.popups#isEnabled return boolean" into mpga
This commit is contained in:
commit
397d3e8bc2
|
@ -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
|
||||
|
|
|
@ -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 ) );
|
||||
|
|
|
@ -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 ),
|
||||
|
|
|
@ -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, {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ) );
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -26,9 +26,7 @@
|
|||
QUnit.test( 'BOOT', function ( assert ) {
|
||||
var action = {
|
||||
type: 'BOOT',
|
||||
user: {
|
||||
isInCondition: true
|
||||
}
|
||||
isEnabled: true
|
||||
};
|
||||
|
||||
assert.expect( 1 );
|
||||
|
|
Loading…
Reference in a new issue