DriftLedger/tests/floating-ui-config.test.ts
fengmengqi bf04400852 feat: OCR 模型按需下载 + 三层独立开关 + 日志持久化 + 原生浮层主题同步 + 文档重构
OCR 模型按需下载(P8 瘦身):
- 移除 plugins/ppocr/assets/ 内置模型(det 9.8MB + rec 21MB + dict),APK 减包 ~31MB
- 新增 modelDownloader.ts:优先从 HuggingFace/CDN 下载,兜底从 APK assets 拷贝
- OcrModule.kt 新增 setModelDir,支持从 filesystem 加载模型,回退 assets 兼容旧用户
- settingsStore 持久化 ocrModelVersion / ocrModelDir
- 自动化页集成模型状态检查与一键下载 UI

OCR 三层独立控制:
- OcrProcessorConfig 从单一 aiVisionEnabled 拆分为 layer1/2/3 三个独立开关
- 设置页可按层启停(L1 正则规则 / L2 本地 OCR / L3 AI Vision)
- OCR 处理增加耗时与字符数日志

日志系统升级:
- logger.ts 新增 LogFileBackend 抽象,支持磁盘持久化(按日期 app-YYYY-MM-DD.log)
- 新增 logBackend.ts(ExpoLogFileBackend)+ 日志中心页 settings/logs.tsx
- 日志中心:实时缓冲 + 历史文件、4 级过滤、Tag/关键词搜索、JSON 展开、分享导出、7 天过期清理
- _layout.tsx 启动时初始化文件后端 + 日志脱敏(验证码/卡号)

原生浮层 UI 主题同步(P6):
- 新增 floatingUiConfig.ts:JS 侧从 theme tokens + i18n 构建 FloatingUiConfig 推送原生
- 新增 FloatingUiConfigStore.kt:SharedPreferences 存储,三浮层组件读取
- FloatingBillView 重设计:颜色/文案走配置、新增币种 chip、金额校验改 BigDecimal
- FloatingHelper / FloatingTip 同步适配
- _layout.tsx 新增 FloatingUiConfigSyncer,主题/语言切换自动推送

UI 与组件增强:
- FormModal 新增 select/dropdown 控件、行内布局(row/flex)、联动回调 onValuesChange
- 新增 Touchable 通用触摸组件、AccountCreateModal 快速建账弹窗
- 信用卡页展示账单周期/到期还款日/本期应还/剩余可用额度,关联账户改下拉选择
- AI 设置页重做:OpenAI/Gemini/DeepSeek 预设 + 默认 URL/模型
- 引导页新增 Android 权限检查步骤(无障碍/通知/短信/存储/悬浮窗)

去重优化:
- 对手方匹配改为模糊包含(includes),双方均无对手方时判定低置信度重复
- DedupResult 新增 matchedItem 返回匹配对比项

文档重构:
- README.md 重写为入口索引(品牌更新 + 模块概览 + 文档导航表)
- 新增 AGENTS.md(AI 助手贡献指南)、docs/architecture.md(Mermaid 数据流/分层/OCR 级联图)
- 新增 docs/development.md(环境/命令/编码规范/测试/提交规范)、plugins/README.md
- UI 重设计文档(design spec + p1-p8)移入 docs/design/

其他:
- i18n 新增权限/信用卡详情/日志中心/AI 设置等翻译键
- ppocr Config Plugin 修复 import 注入去重;size-optimization 增强
- 新增测试:logger.test.ts、floating-ui-config.test.ts
2026-07-23 19:03:38 +08:00

72 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { afterEach, describe, expect, it } from 'vitest';
import { colorToHex, buildFloatingUiConfig } from '../src/services/floatingUiConfig';
import { lightTheme, darkTheme } from '../src/theme/presets';
import { setLocale, t } from '../src/i18n';
// 共享 i18n 单例:无论断言是否失败都还原 locale避免泄漏给后续测试文件
afterEach(() => setLocale('zh'));
describe('colorToHex', () => {
it("'#RRGGBB' 原样返回", () => {
expect(colorToHex('#111318')).toBe('#111318');
expect(colorToHex('#E5E7EB')).toBe('#E5E7EB');
});
it("'rgba(r,g,b,a)' → '#AARRGGBB'alpha 四舍五入)", () => {
expect(colorToHex('rgba(255,255,255,0.08)')).toBe('#14FFFFFF');
expect(colorToHex('rgba(17,19,24,0.4)')).toBe('#66111318');
expect(colorToHex('rgba(0,0,0,0.7)')).toBe('#B3000000');
});
it('其它格式原样返回', () => {
expect(colorToHex('red')).toBe('red');
expect(colorToHex('rgb(1,2,3)')).toBe('rgb(1,2,3)');
});
});
describe('buildFloatingUiConfig', () => {
it('lightTheme colors 映射正确', () => {
setLocale('zh');
const config = buildFloatingUiConfig(lightTheme, t);
expect(config.colors.accent).toBe('#111318');
expect(config.colors.accentFg).toBe('#FFFFFF');
expect(config.colors.cardBg).toBe('#FFFFFF');
expect(config.colors.inputBg).toBe('#EFF1F4');
expect(config.colors.fgPrimary).toBe('#111318');
expect(config.colors.fgSecondary).toBe('#6B7280');
expect(config.colors.border).toBe('#E5E7EB');
expect(config.colors.income).toBe('#10B981');
expect(config.colors.expense).toBe('#EF4444');
expect(config.colors.transfer).toBe('#3B82F6');
});
it('darkTheme 的 rgba border 转换为 #AARRGGBB', () => {
const config = buildFloatingUiConfig(darkTheme, t);
expect(config.colors.border).toBe('#14FFFFFF');
expect(config.colors.accent).toBe('#F3F4F6');
});
it('labels 使用 floating.* 文案且所有契约字段非空', () => {
setLocale('zh');
const config = buildFloatingUiConfig(lightTheme, t);
expect(config.labels.billTitle).toBe('调整交易草稿');
expect(config.labels.confirm).toBe('确认入账');
expect(config.labels.ballOcr).toBe('识别账单');
for (const [key, value] of Object.entries(config.labels)) {
expect(typeof value, `labels.${key} 应为字符串`).toBe('string');
expect(value.length, `labels.${key} 不应为空`).toBeGreaterThan(0);
expect(value, `labels.${key} 不应是 missing 标记`).not.toContain('[missing');
}
for (const [key, value] of Object.entries(config.colors)) {
expect(value, `colors.${key} 应为 hex`).toMatch(/^#[0-9A-F]{6,8}$/);
}
});
it('英文 locale 下 labels 为英文', () => {
setLocale('en');
const config = buildFloatingUiConfig(lightTheme, t);
expect(config.labels.billTitle).toBe('Adjust Draft');
expect(config.labels.ballOcr).toBe('Scan Bill');
});
});