forked from openmrs/openmrs-esm-patient-management
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix) O3-3524: Add wrapping functions to write value in session stora…
…ge (openmrs#1223) * Add wrapping functions to write and read value from session storage * Add check for undefined as well * Add test for update value in session storage * Review changes
- Loading branch information
1 parent
3fd771f
commit 80d388a
Showing
2 changed files
with
66 additions
and
14 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/esm-service-queues-app/src/helpers/helpers.test.ts
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,25 @@ | ||
import { cleanup } from '@testing-library/react'; | ||
import { updateValueInSessionStorage } from './helpers'; | ||
|
||
describe('Testing updateValueInSessionStorage', () => { | ||
beforeEach(() => { | ||
cleanup(); | ||
sessionStorage.clear(); | ||
}); | ||
it('should save value in the session storage if valid value is passed', () => { | ||
updateValueInSessionStorage('key', 'value'); | ||
expect(sessionStorage.getItem('key')).toBe('value'); | ||
}); | ||
|
||
it('should delete the key of the value passed is null or undefined', () => { | ||
updateValueInSessionStorage('key1', 'v1'); | ||
expect(sessionStorage.getItem('key1')).toBe('v1'); | ||
updateValueInSessionStorage('key1', null); | ||
expect(sessionStorage.getItem('key1')).toBe(null); | ||
|
||
updateValueInSessionStorage('key2', 'v2'); | ||
expect(sessionStorage.getItem('key2')).toBe('v2'); | ||
updateValueInSessionStorage('key2', undefined); | ||
expect(sessionStorage.getItem('key2')).toBe(null); | ||
}); | ||
}); |
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