-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filters): save worklist query filters to session storage so that…
… they persist between navigation to the viewer and back (#3749) Co-authored-by: ladeirarodolfo <39910206+ladeirarodolfo@users.noreply.github.com>
- Loading branch information
1 parent
db39585
commit 2a15ef0
Showing
13 changed files
with
322 additions
and
9 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
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,13 @@ | ||
const base = require('../../jest.config.base.js'); | ||
const pkg = require('./package'); | ||
|
||
module.exports = { | ||
...base, | ||
name: pkg.name, | ||
displayName: pkg.name, | ||
// rootDir: "../.." | ||
// testMatch: [ | ||
// //`<rootDir>/platform/${pack.name}/**/*.spec.js` | ||
// "<rootDir>/platform/app/**/*.test.js" | ||
// ] | ||
}; |
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
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
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,3 +1,4 @@ | ||
import useResizeObserver from './useResizeObserver'; | ||
import useSessionStorage from './useSessionStorage'; | ||
|
||
export { useResizeObserver }; | ||
export { useResizeObserver, useSessionStorage }; |
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,102 @@ | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
import useSessionStorage from './useSessionStorage'; | ||
|
||
const SESSION_STORAGE_KEY = 'test'; | ||
|
||
describe('Hook Session Storage', () => { | ||
beforeEach(() => { | ||
window.sessionStorage.removeItem(SESSION_STORAGE_KEY); | ||
}); | ||
|
||
it('hook should return state and setState', () => { | ||
const data = { test: 1 }; | ||
const { result } = renderHook(() => | ||
useSessionStorage({ key: SESSION_STORAGE_KEY, defaultValue: data }) | ||
); | ||
const [hookState, setHookState] = result.current; | ||
expect(hookState).toStrictEqual(data); | ||
expect(typeof setHookState).toBe('function'); | ||
}); | ||
|
||
it('hook should store data on sessionStorage', () => { | ||
const data = { test: 2 }; | ||
renderHook(() => useSessionStorage({ key: SESSION_STORAGE_KEY, defaultValue: data })); | ||
|
||
const dataStr = JSON.stringify(data); | ||
const dataSessionStorage = window.sessionStorage.getItem(SESSION_STORAGE_KEY); | ||
expect(dataSessionStorage).toEqual(dataStr); | ||
}); | ||
|
||
it('hook should return stored data from sessionStorage', () => { | ||
const data = { test: 3 }; | ||
const dataToCompare = { test: 4 }; | ||
|
||
window.sessionStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(dataToCompare)); | ||
|
||
const { result } = renderHook(() => | ||
useSessionStorage({ key: SESSION_STORAGE_KEY, defaultValue: data }) | ||
); | ||
const [hookState, setHookState] = result.current; | ||
|
||
expect(hookState).toStrictEqual(dataToCompare); | ||
}); | ||
|
||
it('hook should provide a setState method which updates its state', () => { | ||
const data = { test: 5 }; | ||
const dataToCompare = { test: 6 }; | ||
const { result } = renderHook(() => | ||
useSessionStorage({ key: SESSION_STORAGE_KEY, defaultValue: data }) | ||
); | ||
const [hookState, setHookState] = result.current; | ||
|
||
act(() => { | ||
setHookState(dataToCompare); | ||
}); | ||
|
||
const dataToCompareStr = JSON.stringify(dataToCompare); | ||
const dataSessionStorage = window.sessionStorage.getItem(SESSION_STORAGE_KEY); | ||
|
||
const [hookStateToCompare] = result.current; | ||
expect(dataSessionStorage).toEqual(dataToCompareStr); | ||
expect(hookStateToCompare).toStrictEqual(dataToCompare); | ||
}); | ||
|
||
it('hook state must be preserved in case rerender', () => { | ||
const data = { test: 7 }; | ||
const { result, rerender } = renderHook(() => | ||
useSessionStorage({ key: SESSION_STORAGE_KEY, defaultValue: data }) | ||
); | ||
|
||
rerender(); | ||
|
||
const [hookState, setHookState] = result.current; | ||
|
||
const dataToCompareStr = JSON.stringify(data); | ||
const dataSessionStorage = window.sessionStorage.getItem(SESSION_STORAGE_KEY); | ||
|
||
expect(dataSessionStorage).toEqual(dataToCompareStr); | ||
expect(hookState).toStrictEqual(data); | ||
}); | ||
|
||
it('hook state must be preserved in case multiple operations and rerender', () => { | ||
const data = { test: 8 }; | ||
const dataToCompare = { test: 9 }; | ||
const { result, rerender } = renderHook(() => | ||
useSessionStorage({ key: SESSION_STORAGE_KEY, defaultValue: data }) | ||
); | ||
const [hookState, setHookState] = result.current; | ||
|
||
act(() => { | ||
setHookState(dataToCompare); | ||
}); | ||
|
||
rerender(); | ||
|
||
const dataToCompareStr = JSON.stringify(dataToCompare); | ||
const dataSessionStorage = window.sessionStorage.getItem(SESSION_STORAGE_KEY); | ||
|
||
const [hookStateToCompare] = result.current; | ||
expect(dataSessionStorage).toEqual(dataToCompareStr); | ||
expect(hookStateToCompare).toStrictEqual(dataToCompare); | ||
}); | ||
}); |
Oops, something went wrong.