mediawiki-extensions-Popups/tests/node-qunit/reducers/settings.test.js
Stephen Niedzielski ece4670710 Hygiene: use arrow for anonymous functions
In some places, the arrow function seems more natural. This patch
approximates the following with manual amendments:

  find \
    -not \( \( -name node_modules -o -name .git -o -name vendor -o -name doc -o -name resources \) -prune \) \
    -iname \*.js|
  xargs -rd\\n sed -ri 's%function\s*(\([^)]*\))%\1 =>%g'

Files to focus on were identified with:

  rg -slg\!/resources/dist/ -g\!/i18n/ -g\!/doc/ 'this|self|arguments|bind|call|apply|new'|
  xargs -rd\\n git difftool -y

Bug: T165036
Change-Id: Ic66b6000b8fc000f9bfde39749f9cfa69924a13c
2018-03-20 09:27:08 -05:00

115 lines
2.2 KiB
JavaScript

import settings from '../../../src/reducers/settings';
QUnit.module( 'reducers/settings' );
QUnit.test( '@@INIT', ( assert ) => {
var state = settings( undefined, { type: '@@INIT' } );
assert.deepEqual(
state,
{
shouldShow: false,
showHelp: false,
shouldShowFooterLink: false
}
);
} );
QUnit.test( 'BOOT', ( assert ) => {
var action = {
type: 'BOOT',
isEnabled: false,
user: {
isAnon: true
}
};
assert.deepEqual(
settings( {}, action ),
{
shouldShowFooterLink: true
}
);
// ---
// 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 );
assert.deepEqual(
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', ( assert ) => {
assert.expect( 1 );
assert.deepEqual(
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', ( assert ) => {
var action = ( wasEnabled, enabled ) => {
return {
type: 'SETTINGS_CHANGE',
wasEnabled,
enabled
};
};
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.'
);
} );