mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-09-24 02:39:11 +00:00
storage: Fix UserSettings#hasIsEnabled
mw.storage#get doesn't take a default value to return if the underlying storage is disabled or the key is missing. In the former case it'll return false and in the latter it'll return null, i.e. in neither case will it return undefined. Bug: T157700 Change-Id: I3f653c11468e17b64765e85ebb3b8f03e311352a
This commit is contained in:
parent
e4ea8df42e
commit
f54f92402c
BIN
resources/dist/index.js
vendored
BIN
resources/dist/index.js
vendored
Binary file not shown.
BIN
resources/dist/index.js.map
vendored
BIN
resources/dist/index.js.map
vendored
Binary file not shown.
|
@ -45,7 +45,9 @@ module.exports = function ( storage ) {
|
|||
* @return {Boolean}
|
||||
*/
|
||||
hasIsEnabled: function () {
|
||||
return storage.get( IS_ENABLED_KEY, undefined ) !== undefined;
|
||||
var value = storage.get( IS_ENABLED_KEY );
|
||||
|
||||
return Boolean( value ) !== false;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,11 +9,7 @@
|
|||
}
|
||||
} );
|
||||
|
||||
QUnit.test( '#getIsEnabled should return true if the storage is empty', 1, function ( assert ) {
|
||||
assert.ok( this.userSettings.getIsEnabled() );
|
||||
} );
|
||||
|
||||
QUnit.test( '#getIsEnabled should return false if Link Previews have been disabled', 2, function ( assert ) {
|
||||
QUnit.test( '#getIsEnabled should return false if Page Previews have been disabled', 2, function ( assert ) {
|
||||
this.userSettings.setIsEnabled( false );
|
||||
|
||||
assert.notOk( this.userSettings.getIsEnabled() );
|
||||
|
@ -28,8 +24,13 @@
|
|||
);
|
||||
} );
|
||||
|
||||
QUnit.test( '#hasIsEnabled', 2, function ( assert ) {
|
||||
assert.notOk( this.userSettings.hasIsEnabled() );
|
||||
QUnit.test( '#hasIsEnabled', 3, function ( assert ) {
|
||||
var getStub;
|
||||
|
||||
assert.notOk(
|
||||
this.userSettings.hasIsEnabled(),
|
||||
'#hasIsEnabled should return false if the storage is empty.'
|
||||
);
|
||||
|
||||
// ---
|
||||
|
||||
|
@ -39,6 +40,17 @@
|
|||
this.userSettings.hasIsEnabled(),
|
||||
'#hasIsEnabled should return true even if "isEnabled" has been set to falsy.'
|
||||
);
|
||||
|
||||
// ---
|
||||
|
||||
getStub = this.sandbox.stub( this.storage, 'get' ).returns( false );
|
||||
|
||||
assert.notOk(
|
||||
this.userSettings.hasIsEnabled(),
|
||||
'#hasIsEnabled should return false if the storage is disabled.'
|
||||
);
|
||||
|
||||
getStub.restore();
|
||||
} );
|
||||
|
||||
QUnit.test( '#getPreviewCount should return the count as a number', function ( assert ) {
|
||||
|
|
Loading…
Reference in a new issue