mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-13 16:18:30 +00:00
622fb6c5e8
Bug: T277639 Change-Id: I0742b8ab1c5ed0b374d4f9447bebc46a35207339
118 lines
2.5 KiB
JavaScript
118 lines
2.5 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,
|
|
showHelp: false,
|
|
shouldShowFooterLink: false
|
|
},
|
|
'The initial state doesn\'t show, doesn\'t show help, and doesn\'t show a footer link.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'BOOT', ( 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.'
|
|
);
|
|
|
|
// ---
|
|
|
|
// And when the user is logged out...
|
|
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( 'SETTINGS_SHOW', ( assert ) => {
|
|
assert.expect( 1, 'All assertions are executed.' );
|
|
|
|
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.expect( 1, 'All assertions are executed.' );
|
|
|
|
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', ( assert ) => {
|
|
const action = ( oldValue, newValue ) => {
|
|
return {
|
|
type: actionTypes.SETTINGS_CHANGE,
|
|
oldValue,
|
|
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.'
|
|
);
|
|
|
|
} );
|