fix: support offline manual bookkeeping

This commit is contained in:
2026-08-21 15:43:01 +08:00
parent 9bb45aac83
commit 979684a06e
5 changed files with 167 additions and 30 deletions
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:miaoji_zhang/shared/api/api_client.dart';
import 'package:miaoji_zhang/shared/api/auth_api.dart';
import 'package:miaoji_zhang/shared/services/local_database.dart';
import 'package:miaoji_zhang/shared/widgets/backend_status_icon.dart';
void main() {
@@ -79,6 +80,31 @@ void main() {
expect(companion.toJson(), source);
});
test('账号分类缓存为空时会补齐支出和收入兜底并允许本地记账', () {
final database = LocalDatabase.inMemoryForTesting(seedDefaults: false);
addTearDown(database.close);
database.ensureDefaultCategories();
final expense = database.categories('expense');
final income = database.categories('income');
expect(expense, hasLength(12));
expect(income, hasLength(7));
expect(expense.first['name'], '餐饮');
expect(income.first['name'], '工资');
expect(income.first['id'], 13);
final transaction = database.createTransaction({
'ledgerId': 1,
'categoryId': expense.first['id'],
'type': 'expense',
'amount': 18.5,
'occurredAt': DateTime.utc(2026, 8, 21).toIso8601String(),
});
expect(transaction['amount'], 18.5);
expect(transaction['categoryName'], '餐饮');
});
test('七个页面保持本地首屏、后台刷新、竞态保护和统一离线入口', () {
final contracts = <String, List<String>>{
'lib/features/home/pages/home_page.dart': [
@@ -92,6 +118,7 @@ void main() {
"categoriesLocal('expense')",
"categoriesRemote('expense')",
"categoriesRemote('income')",
'localFirst: true',
],
'lib/features/stats/stats_page.dart': [
'periodStatsLocal',
@@ -104,6 +131,7 @@ void main() {
'lib/features/settings/category_manage_page.dart': [
'categoriesLocal',
'categoriesRemote',
'localFirst: true',
],
'lib/features/settings/recycle_bin_page.dart': [
'recycleBinLocal',