Skip to content

Commit

Permalink
chore: Test case for session-storage.js (deriv-com#11201)
Browse files Browse the repository at this point in the history
  • Loading branch information
shafin-deriv authored Nov 6, 2023
1 parent b801f90 commit 307f1b0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/bot-web-ui/src/utils/__tests__/session-storage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getStoredItemsByKey, getStoredItemsByUser, setStoredItemsByKey } from 'Utils/session-storage';

describe('Session Storage Util', () => {
const storageKey = 'example_key';
const defaultValue = 'default_value';
const storedItems = { example: 'data' };

it('should return default value when storage is empty', () => {
const result = getStoredItemsByKey(storageKey, defaultValue);
expect(result).toBe(defaultValue);
});

it('should return default value when loginid is falsy', () => {
const loginid = '123';
const result = getStoredItemsByUser(storageKey, loginid, defaultValue);
expect(result).toBe(defaultValue);
});

it('should set stored items', () => {
setStoredItemsByKey(storageKey, storedItems);
const result = getStoredItemsByKey(storageKey, defaultValue);
expect(result).toStrictEqual(storedItems);
});

it('should throw error if invalid object is passed to store', () => {
const consoleWarnMock = jest.fn();
global.console.warn = consoleWarnMock;
const circularObject = {
circularReference: {},
};
circularObject.circularReference = circularObject;
setStoredItemsByKey('example_key', circularObject);
expect(consoleWarnMock).toHaveBeenCalled();
});
});

0 comments on commit 307f1b0

Please sign in to comment.