mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-17 20:41:32 +00:00
a67466acc0
Replace easily identifiable object functions with method syntax: 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%:\s*function\s*(\([^)]*\))%\1%g' Bug: T165036 Change-Id: I90693ee99a6a36dff820dd5ae6f6000429763058
123 lines
3.7 KiB
JavaScript
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', function ( 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', function ( 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', function ( 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.'
|
|
);
|
|
|
|
} );
|