mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-27 08:50:33 +00:00
2c09fd1d1c
This reverts commit a6a65204c6
.
to restore custom preview types.
-- Changes since revert
The previous patch accidentally removed the syncUserSettings
changeListener. This has now been restored with several modifications:
* We have a migrate script which rewrites existing localStorage settings
to the new system
* The existing save functions are generalized.
The changes since this patch are captured in
Ia73467799a9b535f7a3cf7268727c9fab7af0d7e
-- More information
A new REGISTER_SETTING action replaces the BOOT action for
registering settings. This allows custom preview types to be
associated with a setting. They do this by adding the enabled
property to the module they provide to mw.popups.register
Every time the new action is called, we refresh the settings
dialog UI with the new settings.
Previously the settings dialog was hardcoded, but now it is generated
from the registered preview types by deriving associated messages
and checking they exist, so by default custom types will not show
up in the settings.
Benefits:
* This change empowers us to add a setting for Math previews to allow
them to be enabled or disabled.
* Allows us to separate references as its own module
Additional notes:
* The syncUserSettings.js changeListener is no longer needed as the logic
for this is handled inside the "userSettings" change listener in response to
the "settings" reducer which is responding to
SETTINGS_CHANGE and REGISTER_SETTING actions.
Upon merging:
* https://www.mediawiki.org/wiki/Extension:Popups#Extensibility will be
updated to detail how a setting can be registered.
Bug: T334261
Bug: T326692
Change-Id: Ie17d622870511ac9730fc9fa525698fc3aa0d5b6
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
import * as stubs from './stubs';
|
|
import isPagePreviewsEnabled from '../../src/isPagePreviewsEnabled';
|
|
|
|
function createStubUserSettings( expectEnabled ) {
|
|
return {
|
|
isPreviewTypeEnabled() {
|
|
return expectEnabled !== false;
|
|
}
|
|
};
|
|
}
|
|
|
|
QUnit.module( 'ext.popups#isPagePreviewsEnabled', {
|
|
beforeEach() {
|
|
mw.user = { options: { get: () => '1' } };
|
|
},
|
|
afterEach() {
|
|
mw.user = null;
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'it should handle logged out users', ( assert ) => {
|
|
const user = stubs.createStubUser( /* isAnon = */ true ),
|
|
config = new Map();
|
|
|
|
const cases = [
|
|
/*
|
|
[
|
|
<isAnon>, <expected value of isPagePreviewsEnabled>, <test description>
|
|
]
|
|
*/
|
|
[ 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' ]
|
|
];
|
|
|
|
let userSettings;
|
|
for ( let i = 0; i < cases.length; i++ ) {
|
|
const testCase = cases[ i ];
|
|
userSettings = createStubUserSettings( testCase[ 0 ] );
|
|
|
|
assert.strictEqual(
|
|
isPagePreviewsEnabled( user, userSettings, config ),
|
|
testCase[ 1 ],
|
|
testCase[ 2 ]
|
|
);
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'it should handle logged in users', ( assert ) => {
|
|
const user = stubs.createStubUser( /* isAnon = */ false ),
|
|
config = new Map();
|
|
|
|
assert.true(
|
|
isPagePreviewsEnabled( user, {}, 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 Navigation Popups Gadget', ( assert ) => {
|
|
const user = stubs.createStubUser( /* isAnon = */ false ),
|
|
config = new Map();
|
|
|
|
config.set( 'wgPopupsConflictsWithNavPopupGadget', true );
|
|
|
|
assert.strictEqual(
|
|
isPagePreviewsEnabled( user, {}, config ),
|
|
null,
|
|
'Page Previews is disabled when it conflicts with the Navigation Popups Gadget.'
|
|
);
|
|
|
|
} );
|