mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-30 18:34:40 +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
228 lines
5.4 KiB
JavaScript
228 lines
5.4 KiB
JavaScript
import settings from '../../../src/reducers/settings';
|
|
import actionTypes from '../../../src/actionTypes';
|
|
|
|
QUnit.module( 'reducers/settings' );
|
|
|
|
QUnit.test( '@@INIT', ( assert ) => {
|
|
const state = settings( undefined, { type: '@@INIT' } );
|
|
|
|
assert.deepEqual(
|
|
state,
|
|
{
|
|
shouldShow: false,
|
|
previewTypesEnabled: {},
|
|
showHelp: false,
|
|
shouldShowFooterLink: false
|
|
},
|
|
'The initial state doesn\'t show, doesn\'t show help, and doesn\'t show a footer link.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'BOOT with a single disabled popup type', ( assert ) => {
|
|
const action = {
|
|
type: actionTypes.BOOT,
|
|
initiallyEnabled: { page: false },
|
|
user: { isAnon: true }
|
|
};
|
|
assert.deepEqual(
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
true,
|
|
'The boot state shows a footer link.'
|
|
);
|
|
|
|
action.user.isAnon = false;
|
|
assert.deepEqual(
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
false,
|
|
'If the user is logged in, then it doesn\'t signal that the footer link should be shown.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'BOOT with multiple popup types', ( assert ) => {
|
|
const action = {
|
|
type: actionTypes.BOOT,
|
|
initiallyEnabled: { page: true, reference: null },
|
|
user: { isAnon: true }
|
|
};
|
|
assert.deepEqual(
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
false,
|
|
'Footer link ignores unavailable popup types.'
|
|
);
|
|
|
|
action.initiallyEnabled.reference = true;
|
|
assert.deepEqual(
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
false,
|
|
'Footer link is pointless when there is nothing to enable.'
|
|
);
|
|
|
|
action.initiallyEnabled.reference = false;
|
|
assert.deepEqual(
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
true,
|
|
'Footer link appears when at least one popup type is disabled.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'REGISTER_SETTING that is disabled by default reveals footer link', ( assert ) => {
|
|
const REGISTER_SETTING_FOO_DISABLED = {
|
|
type: actionTypes.REGISTER_SETTING,
|
|
name: 'foo',
|
|
enabled: false
|
|
};
|
|
const newState = settings( {
|
|
previewTypesEnabled: {},
|
|
shouldShowFooterLink: false
|
|
}, REGISTER_SETTING_FOO_DISABLED );
|
|
|
|
assert.deepEqual(
|
|
newState.shouldShowFooterLink,
|
|
true,
|
|
'if one setting is registered as disabled, then the footer link is revealed.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'REGISTER_SETTING that is enabled by default should not show footer link', ( assert ) => {
|
|
const REGISTER_SETTING_FOO_ENABLED = {
|
|
type: actionTypes.REGISTER_SETTING,
|
|
name: 'foo',
|
|
enabled: true
|
|
};
|
|
const newState = settings( {
|
|
previewTypesEnabled: {},
|
|
shouldShowFooterLink: false
|
|
}, REGISTER_SETTING_FOO_ENABLED );
|
|
|
|
assert.deepEqual(
|
|
newState.previewTypesEnabled.foo,
|
|
true,
|
|
'previewTypesEnabled is updated'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'SETTINGS_SHOW', ( assert ) => {
|
|
assert.deepEqual(
|
|
settings( {}, { type: actionTypes.SETTINGS_SHOW } ),
|
|
{
|
|
shouldShow: true,
|
|
showHelp: false
|
|
},
|
|
'It should mark the settings dialog as ready to be shown, with no help.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'SETTINGS_HIDE', ( assert ) => {
|
|
assert.deepEqual(
|
|
settings( {}, { type: actionTypes.SETTINGS_HIDE } ),
|
|
{
|
|
shouldShow: false,
|
|
showHelp: false
|
|
},
|
|
'It should mark the settings dialog as ready to be closed, and hide help.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'SETTINGS_CHANGE with page previews only', ( assert ) => {
|
|
const action = ( oldValue, newValue ) => {
|
|
return {
|
|
type: actionTypes.SETTINGS_CHANGE,
|
|
oldValue: { page: oldValue },
|
|
newValue: { page: newValue }
|
|
};
|
|
};
|
|
|
|
assert.deepEqual(
|
|
settings( {}, action( false, false ) ),
|
|
{ shouldShow: false },
|
|
'It should just hide the settings dialog when enabled state stays the same.'
|
|
);
|
|
assert.deepEqual(
|
|
settings( {}, action( true, true ) ),
|
|
{ shouldShow: false },
|
|
'It should just hide the settings dialog when enabled state stays the same.'
|
|
);
|
|
|
|
assert.deepEqual(
|
|
settings( {}, action( false, true ) ),
|
|
{
|
|
shouldShow: false,
|
|
showHelp: false,
|
|
shouldShowFooterLink: false
|
|
},
|
|
'It should hide the settings dialog and help when we enable.'
|
|
);
|
|
|
|
assert.deepEqual(
|
|
settings( {}, action( true, false ) ),
|
|
{
|
|
shouldShow: true,
|
|
showHelp: true,
|
|
shouldShowFooterLink: true
|
|
},
|
|
'It should keep the settings showing and show the help when we disable.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'SETTINGS_CHANGE with two preview types', ( assert ) => {
|
|
[
|
|
[
|
|
'All are disabled but nothing changed',
|
|
false, false, false, false,
|
|
{ shouldShow: false }
|
|
],
|
|
[
|
|
'All are enabled but nothing changed',
|
|
true, true, true, true,
|
|
{ shouldShow: false }
|
|
],
|
|
[
|
|
'One is enabled but nothing changed',
|
|
false, false, true, true,
|
|
{ shouldShow: false }
|
|
],
|
|
[
|
|
'Only one got disabled',
|
|
true, true, true, false,
|
|
{ shouldShow: true, showHelp: true, shouldShowFooterLink: true }
|
|
],
|
|
[
|
|
'One got disabled, the other enabled',
|
|
false, true, true, false,
|
|
{ shouldShow: true, showHelp: true, shouldShowFooterLink: true }
|
|
],
|
|
[
|
|
'Both got disabled',
|
|
true, false, true, false,
|
|
{ shouldShow: true, showHelp: true, shouldShowFooterLink: true }
|
|
],
|
|
[
|
|
'Only one got enabled',
|
|
false, false, false, true,
|
|
{ shouldShow: false, showHelp: false, shouldShowFooterLink: true }
|
|
],
|
|
[
|
|
'Both got enabled',
|
|
false, true, false, true,
|
|
{ shouldShow: false, showHelp: false, shouldShowFooterLink: false }
|
|
]
|
|
].forEach( ( [
|
|
message,
|
|
pageBefore,
|
|
pageAfter,
|
|
referenceBefore,
|
|
referenceAfter,
|
|
expected
|
|
] ) => {
|
|
assert.deepEqual(
|
|
settings( {}, {
|
|
type: actionTypes.SETTINGS_CHANGE,
|
|
oldValue: { page: pageBefore, reference: referenceBefore },
|
|
newValue: { page: pageAfter, reference: referenceAfter }
|
|
} ),
|
|
expected,
|
|
message
|
|
);
|
|
} );
|
|
} );
|