mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-22 11:32:38 +00:00
e3fdee52aa
The two are different: * CiteReferencePreviews as specified in extension.json is a feature flag that allows us to disable the feature entirely. It could be named "CiteReferencePreviewsFeature" or "CiteEnableReferencePreviews", but renaming a feature flag that's already in use is hard. * The client-side flag tells the JavaScript code "you know what, it was kind of a mistake you got loaded, please stop". This is because we can not make all decisions before we register the ResourceLoader module, e.g. if the user has certain gadgets enabled. Adding the word "Active" is not a huge improvement, but at least makes the two different now. Suggestions welcome. Bug: T362771 Change-Id: I0f6a911df8772616ac50c1301f402f77dbe32089
107 lines
2.7 KiB
JavaScript
107 lines
2.7 KiB
JavaScript
function createStubUserSettings( expectEnabled ) {
|
|
return {
|
|
isPreviewTypeEnabled() {
|
|
return expectEnabled !== false;
|
|
}
|
|
};
|
|
}
|
|
|
|
function createStubUser( isAnon, options ) {
|
|
return {
|
|
isNamed() {
|
|
return !isAnon;
|
|
},
|
|
isAnon() {
|
|
return isAnon;
|
|
},
|
|
options
|
|
};
|
|
}
|
|
|
|
const options = { get: () => '1' };
|
|
|
|
( mw.loader.getModuleNames().indexOf( 'ext.popups.main' ) !== -1 ?
|
|
QUnit.module :
|
|
QUnit.module.skip )( 'ext.cite.referencePreviews#isReferencePreviewsEnabled' );
|
|
|
|
QUnit.test( 'relevant combinations of anonymous flags', ( assert ) => {
|
|
[
|
|
{
|
|
testCase: 'enabled for an anonymous user',
|
|
wgCiteReferencePreviewsActive: true,
|
|
isAnon: true,
|
|
enabledByAnon: true,
|
|
expected: true
|
|
},
|
|
{
|
|
testCase: 'turned off via the feature flag (anonymous user)',
|
|
wgCiteReferencePreviewsActive: false,
|
|
isAnon: true,
|
|
enabledByAnon: true,
|
|
expected: null
|
|
},
|
|
{
|
|
testCase: 'manually disabled by the anonymous user',
|
|
wgCiteReferencePreviewsActive: true,
|
|
isAnon: true,
|
|
enabledByAnon: false,
|
|
expected: false
|
|
}
|
|
].forEach( ( data ) => {
|
|
const user = {
|
|
isNamed: () => !data.isAnon && !data.isIPMasked,
|
|
isAnon: () => data.isAnon,
|
|
options: {
|
|
get: () => {}
|
|
}
|
|
},
|
|
isPreviewTypeEnabled = () => {
|
|
if ( !data.isAnon ) {
|
|
assert.true( false, 'not expected to be called' );
|
|
}
|
|
return data.enabledByAnon;
|
|
},
|
|
config = new Map();
|
|
config.set( 'wgCiteReferencePreviewsActive', data.wgCiteReferencePreviewsActive );
|
|
|
|
if ( data.isAnon ) {
|
|
user.options.get = () => assert.true( false, 'not expected to be called 2' );
|
|
} else {
|
|
user.options.get = () => data.enabledByRegistered ? '1' : '0';
|
|
}
|
|
|
|
assert.strictEqual(
|
|
require( 'ext.cite.referencePreviews' ).private.isReferencePreviewsEnabled( user, isPreviewTypeEnabled, config ),
|
|
data.expected,
|
|
data.testCase
|
|
);
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'it should display reference previews when conditions are fulfilled', ( assert ) => {
|
|
const user = createStubUser( false, options ),
|
|
userSettings = createStubUserSettings( false ),
|
|
config = new Map();
|
|
|
|
config.set( 'wgCiteReferencePreviewsActive', true );
|
|
|
|
assert.true(
|
|
require( 'ext.cite.referencePreviews' ).private.isReferencePreviewsEnabled( user, userSettings, config ),
|
|
'If the user is logged in and the user is in the on group, then it\'s enabled.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'it should not be enabled when the global is disabling it', ( assert ) => {
|
|
const user = createStubUser( false ),
|
|
userSettings = createStubUserSettings( false ),
|
|
config = new Map();
|
|
|
|
config.set( 'wgCiteReferencePreviewsActive', false );
|
|
|
|
assert.strictEqual(
|
|
require( 'ext.cite.referencePreviews' ).private.isReferencePreviewsEnabled( user, userSettings, config ),
|
|
null,
|
|
'Reference Previews is disabled.'
|
|
);
|
|
} );
|