fix(editor): Fix local storage flags defaulting to undefined string (#7603)

useStorage takes the default value `undefined` and sets it in local
storage.. also returns "undefined" as string which breaks onboarding
flows

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Mutasem Aldmour
2023-11-07 10:06:08 +01:00
committed by GitHub
parent 78b84af8d1
commit 151e60f829
12 changed files with 97 additions and 42 deletions

View File

@@ -0,0 +1,48 @@
import { nextTick } from 'vue';
import { useStorage } from './useStorage';
describe('useStorage', () => {
beforeEach(() => {
localStorage.clear();
});
it('should initialize with null if no value is stored in localStorage', () => {
const key = 'test-key';
const data = useStorage(key);
expect(data.value).toBeNull();
});
it('should initialize with the stored value if it exists in localStorage', () => {
const key = 'test-key';
const value = 'test-value';
localStorage.setItem(key, value);
const data = useStorage(key);
expect(data.value).toBe(value);
});
it('should update localStorage when the data ref is updated', async () => {
const key = 'test-key';
const value = 'test-value';
const data = useStorage(key);
data.value = value;
await nextTick();
expect(localStorage.getItem(key)).toBe(value);
});
it('should remove the key from localStorage when the data ref is set to null', async () => {
const key = 'test-key';
const value = 'test-value';
localStorage.setItem(key, value);
const data = useStorage(key);
data.value = null;
await nextTick();
expect(localStorage.getItem(key)).toBeNull();
});
});