mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-14 19:25:33 +00:00
e6081106f1
Why: Because they are the approved standard by TC39 and Ecma for JavaScript modules. Changes: * Wrap mw-node-qunit in run.js to register babel to transpile modules for node v6 * Change all sources in src/ to use ES modules * Change constants.js to be able to run without jQuery.bracketedDevicePixelRatio given ES modules are hoisted to the top by spec so we can't patch globals before importing it * Change all tests in tests/node-qunit/ to use ES modules * Drop usage of mock-require given ES modules are easy to stub with sinon Additional changes: * Rename tests/node-qunit/renderer.js to renderer.test.js to follow the convention of all the other files * Make npm run test:node run only .test.js test files so that it doesn't run the stubs.js or run.js file. Bug: T171951 Change-Id: I17a0b76041d5e2fd18e2d54950d9d7c0db99a941
115 lines
2.3 KiB
JavaScript
115 lines
2.3 KiB
JavaScript
import settings from '../../../src/reducers/settings';
|
|
|
|
QUnit.module( 'reducers/settings' );
|
|
|
|
QUnit.test( '@@INIT', function ( assert ) {
|
|
var state = settings( undefined, { type: '@@INIT' } );
|
|
|
|
assert.deepEqual(
|
|
state,
|
|
{
|
|
shouldShow: false,
|
|
showHelp: false,
|
|
shouldShowFooterLink: false
|
|
}
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'BOOT', function ( 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', function ( 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', function ( 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', function ( assert ) {
|
|
var action = function ( wasEnabled, enabled ) {
|
|
return {
|
|
type: 'SETTINGS_CHANGE',
|
|
wasEnabled: wasEnabled,
|
|
enabled: 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.'
|
|
);
|
|
|
|
} );
|