DriftLedger/tests/iosShortcuts.test.ts
fengmengqi f6437b83fe feat: 初始化完整应用框架
- 切换到 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+ 单元测试覆盖核心逻辑
2026-07-15 10:01:31 +08:00

52 lines
1.9 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { IosShortcutsChannel, SimulatedIosAppIntentBridge, handleSharedImage } from '../src/services/iosShortcuts';
describe('iOS Shortcuts', () => {
it('IosShortcutsChannel 接收原生事件', async () => {
const received: string[] = [];
const bridge = new SimulatedIosAppIntentBridge();
const channel = new IosShortcutsChannel(bridge, e => received.push(e.type));
channel.start();
bridge.simulate({ type: 'screenshot', base64: 'img' });
bridge.simulate({ type: 'share-image', base64: 'img2' });
expect(received).toEqual(['screenshot', 'share-image']);
channel.stop();
});
it('handleEvent 可手动调用', async () => {
const channel = new IosShortcutsChannel(null, () => {});
await channel.handleEvent({ type: 'voice', text: '花了30元' });
});
it('notifyComplete 调用桥接', async () => {
const bridge = new SimulatedIosAppIntentBridge();
const channel = new IosShortcutsChannel(bridge, () => {});
await channel.notifyComplete();
expect(bridge.completedCount).toBe(1);
});
it('无桥接时 start/notifyComplete 不报错', async () => {
const channel = new IosShortcutsChannel(null, () => {});
channel.start();
await channel.notifyComplete();
channel.stop();
});
it('handleSharedImage 生成 ScreenshotEvent', () => {
const event = handleSharedImage('base64-data');
expect(event.base64).toBe('base64-data');
expect(event.uri).toContain('share-extension');
expect(event.timestamp).toBeGreaterThan(0);
});
it('stop 后不再接收事件', () => {
const received: string[] = [];
const bridge = new SimulatedIosAppIntentBridge();
const channel = new IosShortcutsChannel(bridge, e => received.push(e.type));
channel.start();
channel.stop();
bridge.simulate({ type: 'screenshot' });
expect(received).toHaveLength(0);
});
});