mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-25 13:32:53 +00:00
efb7b3d872
The save action has been implemented, and it is listened to by the canonical enabled state in the previews reducer, and by the settings reducer to perform UI changes. The enabled state of the application has been kept in the preview reducer as the canonical source of truth. See supporting changes for documentation about the decision. Actions: * Introduce new action SETTINGS_CHANGE with the enabled status * Trigger that action when clicking Save in the settings dialog Reducers: * Listen to SETTINGS_CHANGE in the preview reducer to update enabled status * On the settings reducer * Handle the SETTINGS_CHANGE action * Add showHelp flag to determine if the help should be showing Change listeners: * Switch to compare past vs present changes in the implementation * Handle showing and hiding the help Supporting changes: * On the rendered settings dialog: * Change #hide to actually just hide and remove legacy if statement * Add #toggleHelp method to show or hide the help dialog * Add doc/adr/0003-keep-enabled-state-only-in-preview-reducer.md to support the decision of making the saveSettings action creator return a Redux.Thunk and keeping the enabled state just in the preview reducer. * Add NB to actions#saveSettings explaining and linking to the document Follow commits soon: * Persist the settings change to local storage when it changes, and unify with the preview change listener Change-Id: I80dc5f29fbe6286f2e3e3b50d909894bc5041ccd
84 lines
1.9 KiB
JavaScript
84 lines
1.9 KiB
JavaScript
( function ( mw ) {
|
|
|
|
QUnit.module( 'ext.popups/reducers#settings' );
|
|
|
|
QUnit.test( '@@INIT', function ( assert ) {
|
|
var state = mw.popups.reducers.settings( undefined, { type: '@@INIT' } );
|
|
|
|
assert.deepEqual(
|
|
state,
|
|
{
|
|
shouldShow: false,
|
|
showHelp: false
|
|
}
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'SETTINGS_SHOW', function ( assert ) {
|
|
assert.expect( 1 );
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.settings( {}, { type: 'SETTINGS_SHOW' } ),
|
|
{
|
|
shouldShow: true,
|
|
showHelp: false
|
|
},
|
|
'It should mark the settings dialog as ready to be shown, with no help.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'SETTINGS_HIDE', function ( assert ) {
|
|
assert.expect( 1 );
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.settings( {}, { type: 'SETTINGS_HIDE' } ),
|
|
{
|
|
shouldShow: false,
|
|
showHelp: false
|
|
},
|
|
'It should mark the settings dialog as ready to be closed, and hide help.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'SETTINGS_CHANGE', function ( assert ) {
|
|
var action = function ( wasEnabled, enabled ) {
|
|
return {
|
|
type: 'SETTINGS_CHANGE',
|
|
wasEnabled: wasEnabled,
|
|
enabled: enabled
|
|
};
|
|
};
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.settings( {}, action( false, false ) ),
|
|
{ shouldShow: false },
|
|
'It should just hide the settings dialog when enabled state stays the same.'
|
|
);
|
|
assert.deepEqual(
|
|
mw.popups.reducers.settings( {}, action( true, true ) ),
|
|
{ shouldShow: false },
|
|
'It should just hide the settings dialog when enabled state stays the same.'
|
|
);
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.settings( {}, action( false, true ) ),
|
|
{
|
|
shouldShow: false,
|
|
showHelp: false
|
|
},
|
|
'It should hide the settings dialog and help when we enable.'
|
|
);
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.settings( {}, action( true, false ) ),
|
|
{
|
|
shouldShow: true,
|
|
showHelp: true
|
|
},
|
|
'It should keep the settings showing and show the help when we disable.'
|
|
);
|
|
|
|
} );
|
|
|
|
}( mediaWiki ) );
|