39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { getPrefs, setPrefs } from '../prefs';
|
|
|
|
describe('prefs', () => {
|
|
beforeEach(() => {
|
|
const store: Record<string, string> = {};
|
|
vi.stubGlobal('localStorage', {
|
|
getItem(key: string) {
|
|
return store[key] ?? null;
|
|
},
|
|
setItem(key: string, value: string) {
|
|
store[key] = value;
|
|
},
|
|
});
|
|
});
|
|
|
|
it('returns defaults when localStorage empty', () => {
|
|
expect(getPrefs()).toEqual({
|
|
storyOpenMode: 'auto',
|
|
actionDetailMode: 'inline',
|
|
collapsedActionGroups: {},
|
|
showEventLog: true,
|
|
});
|
|
});
|
|
|
|
it('round-trips updated prefs', () => {
|
|
setPrefs({ storyOpenMode: 'manual', actionDetailMode: 'hover' });
|
|
expect(getPrefs().storyOpenMode).toBe('manual');
|
|
});
|
|
});
|
|
|
|
describe('expanded prefs', () => {
|
|
it('defaults collapsedActionGroups and showEventLog', () => {
|
|
const prefs = getPrefs();
|
|
expect(prefs.collapsedActionGroups).toEqual({});
|
|
expect(prefs.showEventLog).toBe(true);
|
|
});
|
|
});
|