mediawiki-extensions-Popups/tests/node-qunit/isReferencePreviewsEnabled.test.js
Svantje Lilienthal 09c2c52945 Added popup types handling
We added reference preview as a checkbox the the
anonymous user settings. To handle both popup types
(pages and references), we changed the usage of
preview.enabled. We pass on all types as a map
inside preview.enabled. The footer link to edit the
settings will appear for anonymous users if at least
one type is disabled.

Bug: T277639
Change-Id: I860a1b35ac7749d8d0884575f6acb7186ad8e4d0
2021-04-23 12:14:23 +02:00

77 lines
2.2 KiB
JavaScript

import * as stubs from './stubs';
import isReferencePreviewsEnabled from '../../src/isReferencePreviewsEnabled';
function createStubUserSettings( expectEnabled ) {
return {
isReferencePreviewsEnabled() {
return expectEnabled !== false;
}
};
}
QUnit.module( 'ext.popups#isReferencePreviewsEnabled', {
beforeEach() {
mw.user = { options: { get: () => '1' } };
},
afterEach() {
mw.user = null;
}
} );
QUnit.test( 'it should display reference previews when conditions are fulfilled', ( assert ) => {
const user = stubs.createStubUser( false ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsReferencePreviews', true );
config.set( 'wgPopupsConflictsWithRefTooltipsGadget', false );
assert.ok(
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 handle the conflict with the Reference Tooltips Gadget', ( assert ) => {
const user = stubs.createStubUser( false ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsReferencePreviews', true );
config.set( 'wgPopupsConflictsWithRefTooltipsGadget', true );
assert.notOk(
isReferencePreviewsEnabled( user, userSettings, config ),
'Reference Previews is disabled.'
);
} );
QUnit.test( 'it should not be enabled when the global is disabling it', ( assert ) => {
const user = stubs.createStubUser( false ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsReferencePreviews', false );
config.set( 'wgPopupsConflictsWithRefTooltipsGadget', false );
assert.notOk(
isReferencePreviewsEnabled( user, userSettings, config ),
'Reference Previews is disabled.'
);
} );
QUnit.test( 'it should not be enabled when minerva skin used', ( assert ) => {
const user = stubs.createStubUser( false ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsReferencePreviews', true );
config.set( 'wgPopupsConflictsWithRefTooltipsGadget', false );
config.set( 'skin', 'minerva' );
assert.notOk(
isReferencePreviewsEnabled( user, userSettings, config ),
'Reference Previews is disabled.'
);
} );