-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from 200ok-ch/fix/settings-persistance-3
fix: Remove previously stored bogus values from localStorage
- Loading branch information
Showing
5 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import migrateAccessTokenToDropboxAccessToken from './migrate_access_token_to_dropbox_access_token'; | ||
import migrateStoreInDropboxToStoreInSyncBackend from './migrate_store_in_dropbox_to_store_in_sync_backend'; | ||
import migrateNonsenseValuesInLocalstorage from './migrate_nonsense_values_in_localstorage'; | ||
|
||
export default () => { | ||
migrateAccessTokenToDropboxAccessToken(); | ||
migrateStoreInDropboxToStoreInSyncBackend(); | ||
migrateNonsenseValuesInLocalstorage(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isLocalStorageAvailable } from '../util/settings_persister'; | ||
|
||
export default () => { | ||
if (!isLocalStorageAvailable) { | ||
return; | ||
} | ||
|
||
Object.entries(localStorage).forEach(([k, v], _) => { | ||
if (['null', 'undefined'].includes(v)) { | ||
console.warn(`localStorage contains a bogus entry: '${k}': '${v}'`); | ||
console.warn('Deleting the bogus entry.'); | ||
localStorage.removeItem(k); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Store from '../store'; | ||
import { readInitialState, subscribeToChanges } from './settings_persister'; | ||
|
||
describe('Settings persister', () => { | ||
let store; | ||
beforeEach(() => { | ||
const initialState = readInitialState(); | ||
store = Store(initialState); | ||
subscribeToChanges(store)(); | ||
}); | ||
|
||
afterEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
test('Do not persist nonsense like like "false" for settings without default', () => { | ||
expect(localStorage.getItem('showClockDisplay')).not.toBe('false'); | ||
expect(localStorage.getItem('showClockDisplay')).toBe(null); | ||
}); | ||
|
||
test('Does persist given default values, for example colorScheme', () => { | ||
expect(localStorage.getItem('colorScheme')).toBe('Light'); | ||
}); | ||
}); |