mediawiki-extensions-Popups/tests/qunit/ext.popups/isEnabled.test.js
Sam Smith b2bd1ebdf7 Hygiene: Make mw.popups#isEnabled return boolean
Action changes:
* Update the BOOT action to include isEnabled and update the associated
  tests.

Reducer changes:
* Make the preview and eventLogging reducers handle the BOOT action's
  new shape.

Bug: T152687
Change-Id: I3fa2098269a32912eda99ceb8f13887688a14c15
2016-12-16 10:59:47 +00:00

41 lines
1.3 KiB
JavaScript

( function ( mw ) {
function createStubUserSettings( hasIsEnabled ) {
return {
hasIsEnabled: function () {
return hasIsEnabled;
},
getIsEnabled: function () {
return true;
}
};
}
QUnit.module( 'ext.popups#isEnabled' );
QUnit.test( 'it should return true when the user has enabled it via UI interactions', function ( assert ) {
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ false ),
userSettings = createStubUserSettings( /* hasIsEnabled = */ true );
assert.ok( mw.popups.isEnabled( user, userSettings ) );
} );
QUnit.test( 'it should return false if the user is an anon', function ( assert ) {
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ true ),
userSettings = createStubUserSettings( /* hasIsEnabled = */ true );
assert.notOk(
mw.popups.isEnabled( user, userSettings ),
'It should return false even if the user has enabled it via UI interactions.'
);
} );
QUnit.test( 'it should return true if the user hasn\'t disabled it via UI interactions', function ( assert ) {
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ false ),
userSettings = createStubUserSettings( /* hasIsEnabled = */ false );
assert.ok( mw.popups.isEnabled( user, userSettings ) );
} );
}( mediaWiki ) );