2017-07-28 17:32:46 +00:00
|
|
|
import * as stubs from './stubs';
|
2021-03-31 08:51:54 +00:00
|
|
|
import isPagePreviewsEnabled from '../../src/isPagePreviewsEnabled';
|
2017-02-15 15:18:59 +00:00
|
|
|
|
2020-09-18 18:15:57 +00:00
|
|
|
function createStubUserSettings( expectEnabled ) {
|
2017-02-15 15:18:59 +00:00
|
|
|
return {
|
2021-03-31 08:51:54 +00:00
|
|
|
isPagePreviewsEnabled() {
|
2021-04-07 10:34:48 +00:00
|
|
|
return expectEnabled !== false;
|
2017-02-15 15:18:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-16 11:06:13 +00:00
|
|
|
QUnit.module( 'ext.popups#isPagePreviewsEnabled', {
|
|
|
|
beforeEach() {
|
|
|
|
mw.user = { options: { get: () => '1' } };
|
|
|
|
},
|
|
|
|
afterEach() {
|
|
|
|
mw.user = null;
|
|
|
|
}
|
|
|
|
} );
|
2017-02-15 15:18:59 +00:00
|
|
|
|
2021-04-07 10:34:48 +00:00
|
|
|
QUnit.test( 'it 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
|
|
|
/*
|
|
|
|
[
|
2021-03-31 08:51:54 +00:00
|
|
|
<isAnon>, <expected value of isPagePreviewsEnabled>, <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 ] );
|
|
|
|
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual(
|
2021-03-31 08:51:54 +00:00
|
|
|
isPagePreviewsEnabled( user, userSettings, config ),
|
2018-05-03 21:22:11 +00:00
|
|
|
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
|
|
|
config = new Map();
|
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.true(
|
2021-04-16 11:06:13 +00:00
|
|
|
isPagePreviewsEnabled( user, {}, 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
|
|
|
config = new Map();
|
|
|
|
|
|
|
|
config.set( 'wgPopupsConflictsWithNavPopupGadget', true );
|
|
|
|
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.strictEqual(
|
2021-04-16 11:06:13 +00:00
|
|
|
isPagePreviewsEnabled( user, {}, config ),
|
2022-02-09 15:09:19 +00:00
|
|
|
null,
|
2017-04-06 17:07:42 +00:00
|
|
|
'Page Previews is disabled when it conflicts with the Navigation Popups Gadget.'
|
|
|
|
);
|
|
|
|
|
|
|
|
} );
|