fix: refine coding project landing actions

This commit is contained in:
inman
2026-09-06 15:45:22 +08:00
parent de8ce283dd
commit faf751be5e
10 changed files with 307 additions and 117 deletions

View File

@@ -0,0 +1,33 @@
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();
});
});