🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
import { createModal } from '@lobehub/ui';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { openEditorModal } from '.';
vi.mock('@lobehub/ui', async (importOriginal) => ({
...(await importOriginal<object>()),
...(await import('~base-ui-stubs')).baseUiStubs,
}));
vi.mock('./EditorModalContent', () => ({ default: () => null }));
const lastModalProps = () => vi.mocked(createModal).mock.calls.at(-1)![0] as Record<string, any>;
describe('openEditorModal', () => {
beforeEach(() => {
vi.mocked(createModal).mockClear();
});
it('runs the caller cleanup on any close, not only user dismissal', () => {
// Regression: `onOpenChange` fires only for Escape / backdrop / the header
// close button. The footer's Cancel goes through the instance's `close()`,
// which just flips the stack entry — so wiring cleanup to `onOpenChange`
// left the caller's editing flag set and the editor could never reopen.
const onClose = vi.fn();
openEditorModal({ onClose, value: 'original' });
const props = lastModalProps();
expect(props.onOpenChange).toBeUndefined();
expect(typeof props.onOpenChangeComplete).toBe('function');
props.onOpenChangeComplete(true);
expect(onClose).not.toHaveBeenCalled();
props.onOpenChangeComplete(false);
expect(onClose).toHaveBeenCalledTimes(1);
});
it('tolerates a caller that passes no cleanup', () => {
openEditorModal({ value: 'original' });
expect(() => lastModalProps().onOpenChangeComplete(false)).not.toThrow();
});
});