fix: refine coding project landing actions
This commit is contained in:
33
tests/unit/coding-project-entry.test.ts
Normal file
33
tests/unit/coding-project-entry.test.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user