Files
makelore/tests/unit/coding-project-entry.test.ts
2026-09-06 15:45:22 +08:00

34 lines
1.0 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import {
requestCodingProjectCreation,
requestCodingProjectOpen,
subscribeCodingProjectCreationRequest,
subscribeCodingProjectOpenRequest,
} from '@/lib/coding-project-entry';
describe('coding project entry events', () => {
it('delivers project creation requests and removes the listener on unsubscribe', () => {
const listener = vi.fn();
const unsubscribe = subscribeCodingProjectCreationRequest(listener);
requestCodingProjectCreation();
expect(listener).toHaveBeenCalledOnce();
unsubscribe();
requestCodingProjectCreation();
expect(listener).toHaveBeenCalledOnce();
});
it('delivers the selected project id and ignores requests after unsubscribe', () => {
const listener = vi.fn();
const unsubscribe = subscribeCodingProjectOpenRequest(listener);
requestCodingProjectOpen('project-2');
expect(listener).toHaveBeenCalledWith('project-2');
unsubscribe();
requestCodingProjectOpen('project-3');
expect(listener).toHaveBeenCalledOnce();
});
});