Files
AEmotionStudio-ComfyUI-Magn…/tests/unit/StateManager.test.ts
T
Æmotion StudioandClaude Opus 5.5 4b06ee92bb Update the Inspector panel look, navigation and editing
Restyle the panel on ComfyUI palette tokens and drop the built-in themes.
Add a header with Back/Forward, Prev/Next, Focus, Lock and a searchable
Go to node picker, a subgraph/group breadcrumb, and simplified modes:
Follow glass or Float, plus Sticky, Follow selection and Lock to node
(replaces Hold).

Fix widget edits (step2 steps, INT/FLOAT, commit on Enter/blur, undo),
subgraph lookups, orphaned dropdown menus, global arrow-key capture,
the pop-out editor, and remove Google Fonts loading and dead code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 06:47:21 -08:00

93 lines
3.1 KiB
TypeScript

/**
* StateManager Unit Tests
*
* Tests for the StateManager class which manages info panel state.
*/
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
// Mock app object for settings
vi.mock('/scripts/app.js', () => ({
app: {
ui: {
settings: {
getSettingValue: (key: string) => undefined
}
}
}
}));
import { StateManager } from '../../src/info-panel/StateManager';
describe('StateManager', () => {
let stateManager: StateManager;
beforeEach(() => {
vi.useFakeTimers();
// Node's own localStorage global hides happy-dom's
vi.stubGlobal('localStorage', new Storage());
stateManager = new StateManager();
});
afterEach(() => {
vi.useRealTimers();
vi.unstubAllGlobals();
});
describe('constructor', () => {
it('should initialize with default state values', () => {
expect(stateManager.state.isPanelVisible).toBe(false);
expect(stateManager.state.isPanelMinimized).toBe(false);
expect(stateManager.state.isFloating).toBe(false);
expect(stateManager.state.floatPosition).toBeNull();
});
it('should initialize glass preview as visible', () => {
expect(stateManager.state.isGlassPreviewVisible).toBe(true);
});
});
describe('layout', () => {
it('keeps float mode, position and minimized state across reloads', () => {
stateManager.state.isFloating = true;
stateManager.state.floatPosition = { x: 120, y: 80 };
stateManager.state.isPanelMinimized = true;
stateManager.saveLayout();
const reloaded = new StateManager();
expect(reloaded.state.isFloating).toBe(true);
expect(reloaded.state.floatPosition).toEqual({ x: 120, y: 80 });
expect(reloaded.state.isPanelMinimized).toBe(true);
});
it('starts from the defaults when storage is blocked or holds junk', () => {
localStorage.setItem('comfyui_magnify_inspector_layout', '{not json');
expect(new StateManager().state.isFloating).toBe(false);
const blocked = () => { throw new Error('blocked'); };
vi.stubGlobal('localStorage', { getItem: blocked, setItem: blocked });
const manager = new StateManager();
expect(manager.state.floatPosition).toBeNull();
expect(() => manager.saveLayout()).not.toThrow();
});
});
describe('toggleMinimized', () => {
it('should toggle minimized state', () => {
expect(stateManager.state.isPanelMinimized).toBe(false);
stateManager.toggleMinimized();
expect(stateManager.state.isPanelMinimized).toBe(true);
stateManager.toggleMinimized();
expect(stateManager.state.isPanelMinimized).toBe(false);
});
});
it('starts showing and locked to no node', () => {
expect(stateManager.state.currentNodeId).toBeNull();
expect(stateManager.state.lockedNodeId).toBeNull();
});
});