mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-07-27 06:01:49 +00:00
Add support for loading files from Google Drive
#vibecoded
This commit is contained in:
34
src/datasource/test_helpers.ts
Normal file
34
src/datasource/test_helpers.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import {jest} from '@jest/globals';
|
||||
|
||||
/**
|
||||
* Mocks the global sessionStorage object and returns the underlying dictionary object
|
||||
* that stores the items. This dictionary can be inspected or modified by tests.
|
||||
*/
|
||||
export function mockSessionStorage(): {[key: string]: string} {
|
||||
const sessionStorageMock: {[key: string]: string} = {};
|
||||
Object.defineProperty(global, 'sessionStorage', {
|
||||
value: {
|
||||
getItem: jest.fn((key: string) => sessionStorageMock[key] || null),
|
||||
setItem: jest.fn((key: string, value: string) => {
|
||||
sessionStorageMock[key] = value;
|
||||
}),
|
||||
removeItem: jest.fn((key: string) => {
|
||||
delete sessionStorageMock[key];
|
||||
}),
|
||||
clear: jest.fn(() => {
|
||||
for (const key in sessionStorageMock) {
|
||||
delete sessionStorageMock[key];
|
||||
}
|
||||
}),
|
||||
get length() {
|
||||
return Object.keys(sessionStorageMock).length;
|
||||
},
|
||||
key: jest.fn((index: number) => {
|
||||
return Object.keys(sessionStorageMock)[index] || null;
|
||||
}),
|
||||
},
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
return sessionStorageMock;
|
||||
}
|
||||
Reference in New Issue
Block a user