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:
48
packages/editor-ui/src/composables/useStorage.test.ts
Normal file
48
packages/editor-ui/src/composables/useStorage.test.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user