feat(mobile): UI-03 theme calibration and account pages (01-04)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-22 00:28:39 +08:00
parent 9d521ff9da
commit 95e8417553
14 changed files with 1462 additions and 234 deletions
+66 -33
View File
@@ -1,7 +1,9 @@
/// 设置页 widget 测试(P3 计划 Task 3)。
/// 设置页 widget 测试(P3 Task 3;UI-03 页面 02 重设计后更新)。
///
/// 覆盖:修改密码入口跳 /password-change;退出登录 → 调 api.logout
/// (尽力而为)→ 清空本地会话 → 清栈回 /login。
/// 覆盖:修改密码入口跳 /password-change;退出登录(有进行中任务 →
/// 确认弹窗任务保留说明)→ 调 api.logout(尽力而为)→ 清空本地会话 →
/// 清栈回 /login;账号摘要卡 + 通用分组 + 上传帮助面板 + 版本;
/// 语言行打开共享面板 Done 提交。
library;
import 'package:dio/dio.dart';
@@ -11,6 +13,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:photo_live/app/locale_controller.dart';
import 'package:photo_live/core/api_client.dart';
import 'package:photo_live/core/session_store.dart';
import 'package:photo_live/features/uploads/task_state.dart';
import 'package:photo_live/features/uploads/task_store.dart';
import 'package:photo_live/l10n/app_localizations.dart';
import 'package:photo_live/pages/home_page.dart';
import 'package:photo_live/pages/login_page.dart';
@@ -39,6 +43,7 @@ void main() {
Future<void> pumpHome(
WidgetTester tester,
ApiClient client, {
TaskStore? taskStore,
List<dynamic> extraOverrides = const <dynamic>[],
}) async {
await tester.pumpWidget(
@@ -46,7 +51,11 @@ void main() {
// Task 9 起主壳含队列页(触达 sessionAccountProvider/TaskStore),
// 真实平台通道在测试环境挂起,必须注入替身。
overrides: [
...pageTestOverrides(session: store, client: client),
...pageTestOverrides(
session: store,
taskStore: taskStore,
client: client,
),
...extraOverrides,
],
child: MaterialApp(
@@ -85,9 +94,26 @@ void main() {
if (o.path == '/v1/albums') return (500, errorBody('INTERNAL_ERROR'));
throw StateError('unexpected ${o.path}');
});
await pumpHome(tester, clientOf(adapter));
// 一个排队中任务:退出确认走「任务保留」文案(UI-03 有任务分支)。
final taskStore = TaskStore.memory();
final task = await taskStore.create(UploadTaskDraft(
id: 't-1',
accountId: 'staff01',
albumId: 'alb-1',
clientTaskId: 'ct-t-1',
sourceFilePath: '/tmp/t-1.jpg',
filename: 't-1.jpg',
bytes: 10,
contentType: 'image/jpeg',
));
await taskStore.updateState(task.id, UploadTaskState.queued);
await pumpHome(tester, clientOf(adapter), taskStore: taskStore);
// 等任务计数防抖载入(未结束任务 → 退出确认带保留说明)。
await tester.pump(const Duration(milliseconds: 450));
// 点列表项 → 先弹确认(§4.5:明确本机任务保留,不承诺后台继续)。
// 点列表项 → 先弹确认(明确本机任务保留,不承诺后台继续)。
await tester.ensureVisible(find.text('Sign out'));
await tester.pumpAndSettle();
await tester.tap(find.text('Sign out'));
await tester.pumpAndSettle();
expect(find.text('Sign out?'), findsOneWidget);
@@ -116,46 +142,44 @@ void main() {
expect(find.byType(HomePage), findsNothing, reason: '主壳已出栈');
});
testWidgets('设置分组:账号/语言/安全/上传帮助/关于(UI-01 §4.5)',
testWidgets('账号摘要卡 + 通用分组 + 上传帮助面板 + 版本(UI-03 页面 02)',
(tester) async {
final adapter = FakeAdapter((_) => throw StateError('不应发起请求'));
// 分组列表长于默认 800×600 视口(「关于」在折叠线下不可建树)。
tester.view.physicalSize = const Size(800, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await pumpHome(tester, clientOf(adapter));
// 五个分组标题(SectionHeader 文案)。
for (final section in [
'Account',
'Language',
'Security',
'Upload help',
'About',
]) {
// 两个分组标题(SectionHeader 文案)。
for (final section in ['Account', 'General']) {
expect(find.text(section), findsOneWidget, reason: '分组「$section」');
}
// 账号分组:当前账号 + 说明副标题。
// 账号摘要卡:当前账号 + 说明副标题(非编辑入口)。
expect(find.text('staff01'), findsOneWidget);
expect(find.text('Currently signed-in account'), findsOneWidget);
expect(find.descendant(
of: find.byType(CircleAvatar),
matching: find.text('S'),
), findsOneWidget, reason: '首字母头像占位');
// 上传帮助:展开后说明系统限制 / 强退 / 网络等待三分态(不承诺
// 通用分组四行。
expect(find.text('Language'), findsOneWidget);
expect(find.text('Change password'), findsOneWidget);
expect(find.text('Upload help'), findsOneWidget);
expect(find.text('Version'), findsOneWidget);
expect(find.text(kAppVersion), findsOneWidget);
// 上传帮助:底部面板说明系统限制 / 强退 / 网络等待(不承诺
// 「后台上传已开启」)。
await tester.tap(find.text('How background uploads work'));
await tester.tap(find.text('Upload help'));
await tester.pumpAndSettle();
expect(find.text('How background uploads work'), findsOneWidget);
expect(find.textContaining('battery limits'), findsOneWidget);
expect(
find.textContaining('start automatically once a connection is available'),
findsOneWidget,
);
// 关于分组:版本 tile。
expect(find.text('Version'), findsOneWidget);
expect(find.text(kAppVersion), findsOneWidget);
});
testWidgets('语言切换:底部弹层三选一 → 更新档位 + 持久化(P3 Task 10)',
testWidgets('语言切换:共享面板临时选中 + Done 提交 → 更新档位 + 持久化',
(tester) async {
final adapter = FakeAdapter((_) => throw StateError('不应发起请求'));
final localeStore = FakeLocaleStore();
@@ -171,23 +195,32 @@ void main() {
// 本 harness 的 MaterialApp 固定 en(live 全 App 重建在
// app/locale_test.dart 的 PhotoLiveApp 用例覆盖)。
expect(find.text('Language'), findsOneWidget, reason: '语言分组标题');
expect(find.text('Follow system'), findsOneWidget, reason: '默认档位行标题');
expect(find.text('Language'), findsOneWidget, reason: '语言行标题');
expect(
find.text('Follow system'),
findsOneWidget,
reason: '默认档位(行尾当前值)',
);
// 行标题即当前档位,点它打开弹层。
await tester.tap(find.text('Follow system'));
// 点语言行打开共享弹层。
await tester.tap(find.text('Language'));
await tester.pumpAndSettle();
// 弹层三选项(语言名以自身语言书写,跨 locale 不变)。
// 「Follow system」出现两次:主档行标题 + 弹层选项。
// 「Follow system」出现两次:语言行尾当前值 + 弹层选项。
expect(find.text('Follow system'), findsNWidgets(2));
expect(find.text('中文'), findsOneWidget);
expect(find.text('English'), findsOneWidget);
expect(find.text('Done'), findsOneWidget);
// 临时选中 + Done 提交(未 Done 前不落档位)。
await tester.tap(find.text('中文'));
await tester.pump();
expect(localeStore.writes, isEmpty, reason: 'Done 前不写持久层');
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
expect(find.text('中文'), findsOneWidget, reason: '行标题更新为当前档位');
expect(find.text('中文'), findsOneWidget, reason: '行尾更新为当前档位');
expect(localeStore.writes, ['zh'], reason: '选择写入 app.locale');
});
}