mediawiki-extensions-Popups/tests/node-qunit/isEnabled.test.js
Stephen Niedzielski ece4670710 Hygiene: use arrow for anonymous functions
In some places, the arrow function seems more natural. This patch
approximates the following with manual amendments:

  find \
    -not \( \( -name node_modules -o -name .git -o -name vendor -o -name doc -o -name resources \) -prune \) \
    -iname \*.js|
  xargs -rd\\n sed -ri 's%function\s*(\([^)]*\))%\1 =>%g'

Files to focus on were identified with:

  rg -slg\!/resources/dist/ -g\!/i18n/ -g\!/doc/ 'this|self|arguments|bind|call|apply|new'|
  xargs -rd\\n git difftool -y

Bug: T165036
Change-Id: Ic66b6000b8fc000f9bfde39749f9cfa69924a13c
2018-03-20 09:27:08 -05:00

123 lines
3.7 KiB
JavaScript

/* global Map: false */
import * as stubs from './stubs';
import isEnabled from '../../src/isEnabled';
import { BUCKETS } from '../../src/constants';
function createStubUserSettings( isEnabled ) {
return {
hasIsEnabled() {
return isEnabled !== undefined;
},
getIsEnabled() {
return Boolean( isEnabled );
}
};
}
QUnit.module( 'ext.popups#isEnabled (logged out)', {
beforeEach() {
this.user = stubs.createStubUser( /* isAnon = */ true );
}
} );
QUnit.test( 'is should handle logged out users', ( assert ) => {
var user = stubs.createStubUser( /* isAnon = */ true ),
cases,
i, testCase,
userSettings,
config = new Map();
cases = [
/*
[
<isAnon>, <bucket>, <expected value of isEnabled>, <test description>
]
*/
[ undefined, BUCKETS.on, true, 'When the user hasn\'t enabled or disabled' +
' the feature and the user is in the sample.' ],
[ undefined, BUCKETS.control, false, 'When the user hasn\'t enabled or disabled' +
' the feature and the user is not in the sample.' ],
[ false, BUCKETS.on, false, 'When the user has disabled the feature' +
' and the user is in the sample.' ],
[ false, BUCKETS.control, false, 'When the user has disabled the feature' +
' and the user is not in the sample.' ],
[ true, BUCKETS.on, true, 'When the user has enabled the feature' +
' and the user is in the sample.' ],
[ true, BUCKETS.control, true, 'When the user has enabled the feature' +
' and the user is not in the sample.' ]
];
for ( i = 0; i < cases.length; i++ ) {
testCase = cases[ i ];
userSettings = createStubUserSettings( testCase[ 0 ] );
assert.equal(
isEnabled( user, userSettings, config, testCase[ 1 ] ),
testCase[ 2 ],
testCase[ 3 ]
);
}
// ---
config.set( 'wgPopupsBetaFeature', true );
assert.notOk(
isEnabled( user, userSettings, config, BUCKETS.on ),
'When Page Previews is enabled as a beta feature, then it\'s not' +
' enabled for logged out users when they are in the on group.'
);
assert.notOk(
isEnabled( user, userSettings, config, BUCKETS.control ),
'When Page Previews is enabled as a beta feature, then it\'s not' +
' enabled for logged out users when they are not in the control group.'
);
assert.notOk(
isEnabled( user, userSettings, config, BUCKETS.off ),
'When Page Previews is enabled as a beta feature, then it\'s not' +
' enabled for logged out users when they are in the off group.'
);
} );
QUnit.test( 'it should handle logged in users', ( assert ) => {
var user = stubs.createStubUser( /* isAnon = */ false ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsShouldSendModuleToUser', true );
assert.ok(
isEnabled( user, userSettings, config, BUCKETS.on ),
'If the user is logged in and the user is in the on group, then it\'s enabled.'
);
assert.ok(
isEnabled( user, userSettings, config, BUCKETS.control ),
'Bucket does not have an affect on logged in users.' +
'If the user is logged in and they are in the control group it\'s still enabled.'
);
assert.ok(
isEnabled( user, userSettings, config, BUCKETS.off ),
'Bucket does not have an affect on logged in users.' +
'If the user is logged in and the user is bucketed as off then it\'s still enabled.'
);
} );
QUnit.test( 'it should handle the conflict with the Navigation Popups Gadget', ( assert ) => {
var user = stubs.createStubUser( /* isAnon = */ false ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsConflictsWithNavPopupGadget', true );
assert.notOk(
isEnabled( user, userSettings, config, BUCKETS.on ),
'Page Previews is disabled when it conflicts with the Navigation Popups Gadget.'
);
} );