- 切换到 expo-router 文件路由,删除 App.tsx - 新增 5 个 Expo 原生插件:ppocr (OCR), accessibility (账单抓取), notification-listener, screenshot-monitor, sms-receiver - 实现核心领域逻辑:billPipeline (账单流水), dedup (去重), transferRecognizer (转账识别), ruleEngine + categories (双轨制分类), budgets, creditCards, recurring, sync, ocrProcessor - 增强 ledger.ts:支持 balance assertion, option, pad/note 指令, posting 级 metadata, cost/price 解析 - 新增完整 UI:tabs (首页/报表/设置), 交易详情, 预算, 日历热力图, 分类管理, 信用卡, 定期交易, 规则管理 - 实现 Zustand 状态管理:ledgerStore, importStore, settingsStore, metadataStore, automationStore + 持久化 - 新增 AI 功能:chatAssistant, monthlySummary, voiceInput - 实现多端同步:gitSync, webdavSync, icloudSync - 新增主题系统 (tokens/presets) 和 i18n (zh/en) - 添加 30+ 单元测试覆盖核心逻辑
80 lines
3.6 KiB
TypeScript
80 lines
3.6 KiB
TypeScript
import { describe, expect, it, beforeEach } from 'vitest';
|
|
import { useAutomationStore } from '../src/store/automationStore';
|
|
import { parseLedger } from '../src/domain/ledger';
|
|
import type { ImportedEvent } from '../src/domain/types';
|
|
|
|
const ledger = parseLedger([{ path: 'main.bean', content: '2026-01-01 open Assets:Alipay CNY\n2026-01-01 open Expenses:Food CNY\n2026-01-01 open Expenses:Uncategorized CNY\n2026-01-01 open Income:Uncategorized CNY\n' }]);
|
|
|
|
const sampleEvent: ImportedEvent = {
|
|
id: 'ocr-test-1', occurredAt: '2026-07-13T14:30:00', amount: '24.5', currency: 'CNY', direction: 'expense',
|
|
channel: 'WeChat', counterparty: '星巴克', memo: 'OCR识别', raw: {},
|
|
};
|
|
|
|
beforeEach(() => {
|
|
useAutomationStore.getState().clear();
|
|
});
|
|
|
|
describe('automationStore', () => {
|
|
it('addDetected 添加检测事件 + 统计', () => {
|
|
useAutomationStore.getState().addDetected('ocr', sampleEvent);
|
|
useAutomationStore.getState().addDetected('screenshot', { ...sampleEvent, id: 'ss-1' });
|
|
const state = useAutomationStore.getState();
|
|
expect(state.detected).toHaveLength(2);
|
|
expect(state.stats.ocr).toBe(1);
|
|
expect(state.stats.screenshot).toBe(1);
|
|
});
|
|
|
|
it('processAll 走 BillPipeline 生成草稿', async () => {
|
|
useAutomationStore.getState().addDetected('ocr', sampleEvent);
|
|
await useAutomationStore.getState().processAll(
|
|
ledger, [], [], [], { WeChat: 'Assets:Alipay' },
|
|
);
|
|
const state = useAutomationStore.getState();
|
|
expect(state.drafts.length).toBeGreaterThan(0);
|
|
expect(state.detected).toHaveLength(0); // 处理后清空
|
|
expect(state.isProcessing).toBe(false);
|
|
});
|
|
|
|
it('空 detected 时 processAll 无操作', async () => {
|
|
await useAutomationStore.getState().processAll(ledger, [], [], [], {});
|
|
expect(useAutomationStore.getState().drafts).toHaveLength(0);
|
|
});
|
|
|
|
it('confirmDraft 移除草稿并返回', async () => {
|
|
useAutomationStore.getState().addDetected('ocr', sampleEvent);
|
|
await useAutomationStore.getState().processAll(ledger, [], [], [], { WeChat: 'Assets:Alipay' });
|
|
const before = useAutomationStore.getState().drafts.length;
|
|
const draft = useAutomationStore.getState().confirmDraft(0);
|
|
expect(draft).not.toBeNull();
|
|
expect(useAutomationStore.getState().drafts.length).toBe(before - 1);
|
|
});
|
|
|
|
it('rejectDraft 移除草稿', async () => {
|
|
useAutomationStore.getState().addDetected('ocr', sampleEvent);
|
|
await useAutomationStore.getState().processAll(ledger, [], [], [], { WeChat: 'Assets:Alipay' });
|
|
const before = useAutomationStore.getState().drafts.length;
|
|
useAutomationStore.getState().rejectDraft(0);
|
|
expect(useAutomationStore.getState().drafts.length).toBe(before - 1);
|
|
});
|
|
|
|
it('clear 重置全部状态', () => {
|
|
useAutomationStore.getState().addDetected('notification', sampleEvent);
|
|
useAutomationStore.getState().clear();
|
|
const state = useAutomationStore.getState();
|
|
expect(state.detected).toHaveLength(0);
|
|
expect(state.drafts).toHaveLength(0);
|
|
expect(state.stats.notification).toBe(0);
|
|
});
|
|
|
|
it('多来源事件混合处理', async () => {
|
|
useAutomationStore.getState().addDetected('ocr', sampleEvent);
|
|
useAutomationStore.getState().addDetected('sms', { ...sampleEvent, id: 'sms-1', channel: 'Bank:1234' });
|
|
useAutomationStore.getState().addDetected('notification', { ...sampleEvent, id: 'notif-1' });
|
|
await useAutomationStore.getState().processAll(ledger, [], [], [], { WeChat: 'Assets:Alipay', 'Bank:1234': 'Assets:Alipay' });
|
|
const state = useAutomationStore.getState();
|
|
expect(state.stats.ocr).toBe(1);
|
|
expect(state.stats.sms).toBe(1);
|
|
expect(state.stats.notification).toBe(1);
|
|
});
|
|
});
|