Files
AEmotionStudio-ComfyUI-Magn…/tests/unit/PopOutTheme.test.ts
T
Æmotion StudioandClaude Opus 5.5 76bb34da1d Make the pop-out pair with its own tab and keep its connection
Each ComfyUI tab talks to its viewer on a session channel. Pings run only while
connected, status follows pings, and a hidden glass keeps feeding the viewer.

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

47 lines
1.5 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { PopOutManager } from '../../src/magnify-glass/PopOutManager';
describe('Pop-out theme', () => {
let manager: PopOutManager;
let posted: any[];
beforeEach(() => {
vi.useFakeTimers();
posted = [];
vi.stubGlobal('BroadcastChannel', class {
onmessage: ((e: MessageEvent) => void) | null = null;
postMessage(message: unknown) { posted.push(message); }
close() { }
});
manager = new PopOutManager(() => ({ glass: 'on', inspector: true }), () => { });
});
afterEach(() => {
manager.cleanup();
document.body.classList.remove('dark-theme');
vi.unstubAllGlobals();
vi.useRealTimers();
});
const pong = () => (manager as any).handleMessage({ type: 'pong' });
const themes = () => posted.filter(m => m.type === 'config').map(m => m.data.theme);
it('follows body.dark-theme and resends only when it changes', () => {
document.body.classList.add('dark-theme');
pong();
pong();
expect(themes()).toEqual(['dark']);
document.body.classList.remove('dark-theme');
pong();
expect(themes()).toEqual(['dark', 'light']);
});
it('sends the theme again when the viewer reconnects', () => {
pong();
(manager as any).handleMessage({ type: 'close' });
pong();
expect(themes()).toEqual(['light', 'light']);
});
});