2017-02-15 15:18:59 +00:00
|
|
|
/* global Map: false */
|
|
|
|
|
2017-07-28 17:32:46 +00:00
|
|
|
import * as stubs from './stubs';
|
|
|
|
import isEnabled from '../../src/isEnabled';
|
2017-02-15 15:18:59 +00:00
|
|
|
|
|
|
|
function createStubUserSettings( isEnabled ) {
|
|
|
|
return {
|
2018-03-14 22:04:59 +00:00
|
|
|
hasIsEnabled() {
|
2017-02-15 15:18:59 +00:00
|
|
|
return isEnabled !== undefined;
|
|
|
|
},
|
2018-03-14 22:04:59 +00:00
|
|
|
getIsEnabled() {
|
2017-02-15 15:18:59 +00:00
|
|
|
return Boolean( isEnabled );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
QUnit.module( 'ext.popups#isEnabled (logged out)', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2017-02-15 15:18:59 +00:00
|
|
|
this.user = stubs.createStubUser( /* isAnon = */ true );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'is should handle logged out users', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const user = stubs.createStubUser( /* isAnon = */ true ),
|
2017-02-15 15:18:59 +00:00
|
|
|
config = new Map();
|
|
|
|
|
2018-03-19 19:39:41 +00:00
|
|
|
const cases = [
|
2017-08-10 17:55:26 +00:00
|
|
|
/*
|
|
|
|
[
|
2018-05-03 21:22:11 +00:00
|
|
|
<isAnon>, <expected value of isEnabled>, <test description>
|
2017-08-10 17:55:26 +00:00
|
|
|
]
|
|
|
|
*/
|
2018-05-03 21:22:11 +00:00
|
|
|
[ 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' ]
|
2017-02-15 15:18:59 +00:00
|
|
|
];
|
|
|
|
|
2018-03-19 19:39:41 +00:00
|
|
|
let userSettings;
|
|
|
|
for ( let i = 0; i < cases.length; i++ ) {
|
|
|
|
const testCase = cases[ i ];
|
2017-02-15 15:18:59 +00:00
|
|
|
userSettings = createStubUserSettings( testCase[ 0 ] );
|
|
|
|
|
|
|
|
assert.equal(
|
2018-05-03 21:22:11 +00:00
|
|
|
isEnabled( user, userSettings, config ),
|
|
|
|
testCase[ 1 ],
|
|
|
|
testCase[ 2 ]
|
2017-02-15 15:18:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'it should handle logged in users', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const user = stubs.createStubUser( /* isAnon = */ false ),
|
2017-02-15 15:18:59 +00:00
|
|
|
userSettings = createStubUserSettings( false ),
|
|
|
|
config = new Map();
|
|
|
|
|
|
|
|
config.set( 'wgPopupsShouldSendModuleToUser', true );
|
|
|
|
|
|
|
|
assert.ok(
|
2018-05-03 21:22:11 +00:00
|
|
|
isEnabled( user, userSettings, config ),
|
2017-08-10 17:55:26 +00:00
|
|
|
'If the user is logged in and the user is in the on group, then it\'s enabled.'
|
|
|
|
);
|
2017-02-15 15:18:59 +00:00
|
|
|
} );
|
2017-04-06 17:07:42 +00:00
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'it should handle the conflict with the Navigation Popups Gadget', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const user = stubs.createStubUser( /* isAnon = */ false ),
|
2017-04-06 17:07:42 +00:00
|
|
|
userSettings = createStubUserSettings( false ),
|
|
|
|
config = new Map();
|
|
|
|
|
|
|
|
config.set( 'wgPopupsConflictsWithNavPopupGadget', true );
|
|
|
|
|
|
|
|
assert.notOk(
|
2018-05-03 21:22:11 +00:00
|
|
|
isEnabled( user, userSettings, config ),
|
2017-04-06 17:07:42 +00:00
|
|
|
'Page Previews is disabled when it conflicts with the Navigation Popups Gadget.'
|
|
|
|
);
|
|
|
|
|
|
|
|
} );
|