mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-24 07:34:11 +00:00
if preview count stored in localStorage is not a number override it
There are some cases when the preview count stored in local storage evaluates to NaN. When this happens we should override the value to zero, store it in localStorage, and return it. Bug: T168371 Change-Id: Ic44b7c7b5b716f6a0859f33278d56d2d95bbfb3e
This commit is contained in:
parent
08331ba199
commit
910dd0408f
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.
|
@ -66,21 +66,28 @@ export default function createUserSettings( storage ) {
|
|||
* Gets the number of previews that the user has seen.
|
||||
*
|
||||
* If the storage isn't available, then -1 is returned.
|
||||
* If the value in storage is not a number it will override stored value to 0
|
||||
*
|
||||
* @function
|
||||
* @name UserSettings#getPreviewCount
|
||||
* @return {Number}
|
||||
*/
|
||||
getPreviewCount: function () {
|
||||
var result = storage.get( PREVIEW_COUNT_KEY );
|
||||
var result = storage.get( PREVIEW_COUNT_KEY ), count;
|
||||
|
||||
if ( result === false ) {
|
||||
return -1;
|
||||
} else if ( result === null ) {
|
||||
return 0;
|
||||
}
|
||||
count = parseInt( result, 10 );
|
||||
|
||||
return parseInt( result, 10 );
|
||||
// stored number is not a zero, override it to zero and store new value
|
||||
if ( Number.isNaN( count ) ) {
|
||||
count = 0;
|
||||
this.setPreviewCount( count );
|
||||
}
|
||||
return count;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,3 +92,10 @@ QUnit.test( '#setPreviewCount should store the count as a string', function ( as
|
|||
|
||||
assert.strictEqual( this.storage.get( 'ext.popups.core.previewCount' ), '222' );
|
||||
} );
|
||||
|
||||
QUnit.test( '#getPreviewCount should override value in storage when is not a number', function ( assert ) {
|
||||
this.storage.set( 'ext.popups.core.previewCount', 'NaN' );
|
||||
|
||||
assert.strictEqual( this.userSettings.getPreviewCount(), 0 );
|
||||
assert.strictEqual( this.storage.get( 'ext.popups.core.previewCount' ), '0' );
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue