feat(FEAT-MO-001): 同步市场概览前端契约
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { useMarketOverview } from './useMarketOverview';
|
||||
|
||||
const response = { source: 'tdx', status: 'fresh', data: null, snapshotId: '20260818-101500', asOf: '2026-08-18T10:15:00+08:00', warnings: [] } as const;
|
||||
|
||||
describe('市场概览状态', () => {
|
||||
it('并行加载五个模块,一个模块失败不影响其他模块', async () => {
|
||||
const api = {
|
||||
getSummary: vi.fn().mockResolvedValue(response),
|
||||
getIndices: vi.fn().mockRejectedValue(new Error('failed')),
|
||||
getBreadth: vi.fn().mockResolvedValue(response),
|
||||
getSectors: vi.fn().mockResolvedValue(response),
|
||||
getFunds: vi.fn().mockResolvedValue(response),
|
||||
};
|
||||
const state = useMarketOverview(api);
|
||||
|
||||
await state.refresh();
|
||||
|
||||
expect(state.summary.value.status).toBe('ready');
|
||||
expect(state.indices.value.status).toBe('error');
|
||||
expect(state.breadth.value.status).toBe('ready');
|
||||
expect(state.isLoading.value).toBe(false);
|
||||
});
|
||||
|
||||
it('分析偏好写入本地存储并可恢复', () => {
|
||||
const first = useMarketOverview({} as never);
|
||||
first.setAnalysisHorizon('短线');
|
||||
first.setAnalysisEngine('混合');
|
||||
|
||||
const second = useMarketOverview({} as never);
|
||||
|
||||
expect(second.analysisHorizon.value).toBe('短线');
|
||||
expect(second.analysisEngine.value).toBe('混合');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user