forked from opensearch-project/dashboards-observability
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding test for clear cache on logout (opensearch-project#1794)
* adding test for clear cache on logout Signed-off-by: Shenoy Pratik <[email protected]> * update name to logout Signed-off-by: Shenoy Pratik <[email protected]> --------- Signed-off-by: Shenoy Pratik <[email protected]>
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SECURITY_DASHBOARDS_LOGOUT_URL } from '../../../common/constants/data_sources'; | ||
import { | ||
ASYNC_QUERY_ACCELERATIONS_CACHE, | ||
ASYNC_QUERY_DATASOURCE_CACHE, | ||
} from '../../../common/constants/shared'; | ||
import { catalogRequestIntercept } from './cache_intercept'; | ||
|
||
interface LooseObject { | ||
[key: string]: any; | ||
} | ||
|
||
// Mock sessionStorage | ||
const sessionStorageMock = (() => { | ||
let store = {} as LooseObject; | ||
return { | ||
getItem(key: string) { | ||
return store[key] || null; | ||
}, | ||
setItem(key: string, value: string) { | ||
store[key] = value.toString(); | ||
}, | ||
removeItem(key: string) { | ||
delete store[key]; | ||
}, | ||
clear() { | ||
store = {}; | ||
}, | ||
}; | ||
})(); | ||
|
||
Object.defineProperty(window, 'sessionStorage', { value: sessionStorageMock }); | ||
|
||
describe('Intercept logout handler', () => { | ||
beforeEach(() => { | ||
jest.spyOn(window.sessionStorage, 'removeItem'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
const logoutPath = { | ||
path: SECURITY_DASHBOARDS_LOGOUT_URL, | ||
}; | ||
|
||
it('Intercept logout handler should clear the cache session', () => { | ||
const logoutInterceptFn = catalogRequestIntercept(); | ||
logoutInterceptFn(logoutPath, null); | ||
expect(sessionStorage.removeItem).toBeCalledWith(ASYNC_QUERY_DATASOURCE_CACHE); | ||
expect(sessionStorage.removeItem).toBeCalledWith(ASYNC_QUERY_ACCELERATIONS_CACHE); | ||
}); | ||
}); |
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